diff --git a/convert_ipynb_to_md.sh b/convert_ipynb_to_md.sh new file mode 100644 index 0000000..a0b6ba5 --- /dev/null +++ b/convert_ipynb_to_md.sh @@ -0,0 +1,7 @@ +set -ex + +FILEIPYNB=$1 +jupyter nbconvert --to script $1 +FILEPY=$(echo $FILEIPYNB | sed 's/.ipynb$/.py/') +FILEMD=$(echo $FILEIPYNB | sed 's/.ipynb$/.md/') +python convert_python_to_markdown.py "$FILEPY" "$FILEMD" diff --git a/convert_python_to_markdown.py b/convert_python_to_markdown.py new file mode 100644 index 0000000..32cbcc9 --- /dev/null +++ b/convert_python_to_markdown.py @@ -0,0 +1,13 @@ +import sys + +from bs4 import BeautifulSoup +from markdown import markdown + +with open(sys.argv[1]) as f_in, open(sys.argv[2],'w') as f_out: + for i, line in enumerate(f_in): + if i in (1,2): + continue + if line[:2] == "# " and line[:5] != "# In[": + text = line[:2] + f_out.write(line[2:]) + diff --git a/run_conversion.sh b/run_conversion.sh new file mode 100644 index 0000000..4516525 --- /dev/null +++ b/run_conversion.sh @@ -0,0 +1,5 @@ +for i in {cw,wyk}/*.ipynb; +do + bash convert_ipynb_to_md.sh $i + echo $i done +done