zachhannum / mkdocs-toc-sidebar-plugin

An MkDocs plugin that allows users to add additional content to the ToC sidebar using the Material theme
MIT License
5 stars 3 forks source link

HTML beautification breaks pymdown_extensions (Tilde & Caret) #4

Open dmitry-radzevich opened 3 years ago

dmitry-radzevich commented 3 years ago

Please see facelessuser/pymdown-extensions#1312 for a full context and examples. In short: pretty-printing of HTML caused by this extension inserts extra spaces that negatively affect how the output looks in <sub/> and <sup/> cases:

Original HTML / rendering:

<p>Simple<sub>subscript</sub></p>
<p>Complex<sub>subscript with escaped spaces</sub></p>
<p>H<sub>3</sub>PO<sub>4</sub>
H<sub>2</sub>O</p>

image

"Beautified" HTML / rendering (notice extra spaces before subscripts and superscripts):

<p>
        H
        <sub>
         3
        </sub>
        PO
        <sub>
         4
        </sub>
        H
        <sub>
         2
        </sub>
        O
       </p>

image

Perhaps it's the prettification step that mangles the output HTML:

        souped_html = soup.prettify(soup.original_encoding)
        return souped_html 
dmitry-radzevich commented 3 years ago

From https://www.crummy.com/software/BeautifulSoup/bs4/doc/:

The prettify() method will turn a Beautiful Soup parse tree into a nicely formatted Unicode string, with a separate line for each tag and each string: ... Since it adds whitespace (in the form of newlines), prettify() changes the meaning of an HTML document and should not be used to reformat one. The goal of prettify() is to help you visually understand the structure of the documents you work with.