greenape / mknotebooks

A plugin for mkdocs to help you include Jupyter notebooks in your projects
MIT License
137 stars 20 forks source link

Rendering fails if the cell-output contains a HTML with a </div> tag #661

Open krlng opened 2 years ago

krlng commented 2 years ago

mknotebooks does not display the output of a cell correctly, if that output contains HTML. It looks like it breaks the output of a cell at the first </div> tag, even if that one is nested within the actual cell-output and therefore should not close the whole cell-output.

In the jupyter notebook it get's rendered correctly:

Screenshot 2021-11-25 at 16 23 38

While within the mknotebooks-docs only the first can be displayed and the second already gets a new output cell:

Screenshot 2021-11-25 at 16 22 33

timvink commented 2 years ago

Are you sure the output HTML is valid? Can you provide a reproducable example?

krlng commented 2 years ago

I thing I found the reason. mknotebooks has a problem with a HTML outputs where a </div> directly followed by a \n. It can be fixed by placing an empty space between those

html_str = """
    <div><span>with_space 1</span></div> 
    <div><span>without_space 2</span></div>
    <div><span>with_space 3</span></div> 
    <div><span>without_space 4</span></div>
    <div><span>with_space 5</span></div> 
"""

from IPython.display import HTML

HTML(html_str.replace("\n"," \n")) # works 

HTML(html_str) # breaks for heading 3 and 5, so always in lines without a space between </div> and \n
greenape commented 2 years ago

Which version of nbconvert is installed?

krlng commented 2 years ago

nbconvert-6.1.0-py3, habe jetzt aber auch noch auf 6.3 geupdated, ändert nichts. MacOS 11.6