Convert markdown to notebook to html files, remove them when done.
(filepath_notebook)
| 40 | |
| 41 | |
| 42 | def get_notebook_html(filepath_notebook): |
| 43 | """Convert markdown to notebook to html files, remove them when done.""" |
| 44 | subprocess.run( |
| 45 | [ |
| 46 | "jupytext", |
| 47 | "--to", |
| 48 | "notebook", |
| 49 | "--execute", |
| 50 | filepath_notebook, |
| 51 | ] |
| 52 | ) |
| 53 | filepath_notebook = filepath_notebook.replace(".md", ".ipynb") |
| 54 | |
| 55 | html_exporter = nbconvert.HTMLExporter() |
| 56 | body, _ = html_exporter.from_filename(filepath_notebook) |
| 57 | |
| 58 | parser = IframeParser() |
| 59 | parser.feed(body) |
| 60 | iframes = parser.iframes |
| 61 | |
| 62 | for iframe in iframes: |
| 63 | with temp_html_filepath(iframe) as filepath_html: |
| 64 | yield filepath_html |
| 65 | |
| 66 | |
| 67 | class IframeParser(HTMLParser): |
no test coverage detected