diff --git a/tools/ipynb2md.py b/tools/ipynb2md.py index eba40432e4b..7f963ad3bda 100644 --- a/tools/ipynb2md.py +++ b/tools/ipynb2md.py @@ -31,6 +31,9 @@ import os import argparse import nbformat +import mslex +import shlex +import subprocess def remove_outputs(nb): @@ -68,7 +71,18 @@ def main(): clear_notebook(old_ipynb, new_ipynb) - os.system('jupyter nbconvert ' + new_ipynb + ' --to markdown --output ' + md_file) + + cmd = 'jupyter nbconvert' + new_ipynb, + '--to markdown' + '--output' + md_file + if os.name == 'posix': + escaped_cmd = shlex.quote(cmd) + subprocess.run(escaped_cmd) + elif os.name == 'nt': + escaped_cmd = mslex.quote(cmd) + subprocess.run(escaped_cmd) + else: + print("Could not determine operating system, exiting.") + return + with open(md_file, 'a') as f: f.write('') os.system('rm ' + new_ipynb)