简体   繁体   中英

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 . I'm looking for a way to avoid code outputs in the original notebook to be indented in the output.md output.

Input notebook.ipynb

在此处输入图像描述

Executed command:

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

Output:

# This is a simple test


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

    <mark>Test</mark>

Expected output (no indentation):

# 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() .

Use:

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

instead of:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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