我正在尝试这段Markdown文本:
Hello, this should just be a paragraph, and there should be a test of Markdown fenced code block with backticks below:
```
Hello there
This should be in
a code block
```
在Jupyter Notebook的markdown单元格中,实现以下效果:
![jupyter notebook markdown cell code](https://istack.dev59.com/xvfzz.webp)
![jupyter notebook markdown cell rendered](https://istack.dev59.com/C1n2M.webp)
现在我想做同样的事情,但是我希望将源代码存储在Python字符串变量中,然后使用
IPython.display.Markdown()
进行转换。因此,我有以下代码:from IPython.display import display
from IPython.display import Markdown as md, Javascript, HTML
mdstr="""
Hello, this should just be a paragraph, and there should be a test of Markdown fenced code block with backticks:
```
Hello there
This should be in
a code block
```
"""
display(md(mdstr))
然而,这将呈现如下:
从屏幕截图中可以看出,在开头段落和代码块之间现在缺少一个垂直空间。
那么,我该如何使用 IPython.display.Markdown
获得与在 Jupyter 笔记本的 Markdown 单元格中只有 Markdown 文本时相同的输出(即段落和代码块之间有垂直空格)?
或者 - 如果不能使用 IPython.display.Markdown
,我还有哪些其他选项,可以定义 Python 字符串中的 Markdown 文本,并生成与具有相同输入的 Jupyter Markdown 单元格完全相同的输出字符串?