From 4437a7f71b4a8e27b6943102470f8e4429d01204 Mon Sep 17 00:00:00 2001 From: Jakub Pokrywka Date: Mon, 27 Sep 2021 13:29:40 +0200 Subject: [PATCH] add ipynb to md conversion --- convert_ipynb_to_md.sh | 7 +++++++ convert_python_to_markdown.py | 13 +++++++++++++ run_conversion.sh | 5 +++++ 3 files changed, 25 insertions(+) create mode 100644 convert_ipynb_to_md.sh create mode 100644 convert_python_to_markdown.py create mode 100644 run_conversion.sh 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