简体   繁体   English

nbconvert to markdown:避免代码单元格中的缩进

[英]nbconvert to markdown: avoid indents in code cells

I have a working notebook notebook.ipynb which I want to convert to a Markdown file ( output.md ) using nbconvert .我有一个工作笔记本notebook.ipynb ,我想使用nbconvert将其转换为 Markdown 文件( output.md )。 I'm looking for a way to avoid code outputs in the original notebook to be indented in the output.md output.我正在寻找一种方法来避免原始笔记本中的代码输出在output.md output 中缩进。

Input notebook.ipynb输入notebook.ipynb

在此处输入图像描述

Executed command:执行的命令:

jupyter nbconvert --execute --to markdown --output output.md notebook.ipynb

Output: Output:

# This is a simple test


'''python
print("<mark>Test</mark>")
'''

    <mark>Test</mark>

Expected output (no indentation):预期 output(无缩进):

# This is a simple test


'''python
print("<mark>Test</mark>")
'''

<mark>Test</mark>

Here's a workaround (not really a solution): using display(HTML()) instead of print() .这是一个解决方法(不是真正的解决方案):使用display(HTML())而不是print()

Use:利用:

from IPython.display import display, HTML
display(HTML("<mark>Test</mark>"))

instead of:代替:

print("<mark>Test</mark>")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM