I know about the existance of the %load markdown_file.md
magic command but this will load the content of the file on the first run of the cell.
If the file changes, the cell won't be updated.
Does anyone know if it is possible to avoid this problem and load the content of the file each time the cell runs?
Asked
Active
Viewed 4,421 times
12

Paolo Squadrito
- 235
- 2
- 9
-
May I ask about the purpose behind loading the markdown file? Is it just to display the contents to allow users of the notebook to read the content in a non-programmatic way? – runDOSrun Sep 25 '20 at 10:37
-
@runDOSrun Yes it's just to display the content. I have some md notes mixed with python code, i find useful to put those notes in a separate md files for several reasons and sometimes i modify them using different software. So i would like the flexibility to show the updated content when i run a markdown cell – Paolo Squadrito Sep 25 '20 at 10:39
1 Answers
16
If you want to load a markdown every time a cell is run, you can do:
from IPython.display import Markdown, display
display(Markdown("markdown_file.md"))

runDOSrun
- 10,359
- 7
- 47
- 57
-
1The given format of Markdown method loads a file content in the system encoding. On Windows the default encoding is not UTF-8. It can be worked around with `Markdown(open('insert.md', encoding='utf-8').read())` (Python 3) or setting relevant environment variables like `set PYTHONIOENCODING=utf-8` but it should be checked. – sherdim May 17 '21 at 05:34