Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[SECURITY] update in ipynb2md.py #21159

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tools/ipynb2md.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import os
import argparse
import nbformat
import mslex
import shlex
import subprocess


def remove_outputs(nb):
Expand Down Expand Up @@ -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('<!-- INSERT SOURCE DOWNLOAD BUTTONS -->')
os.system('rm ' + new_ipynb)
Expand Down