Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML beautification breaks pymdown_extensions (Tilde & Caret) #4

Open
dmitry-radzevich opened this issue Apr 24, 2021 · 1 comment · May be fixed by #5
Open

HTML beautification breaks pymdown_extensions (Tilde & Caret) #4

dmitry-radzevich opened this issue Apr 24, 2021 · 1 comment · May be fixed by #5

Comments

@dmitry-radzevich
Copy link

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 dmitry-radzevich changed the title HTML beautification breaks pymdown_extensions (Tilde & Subscript) HTML beautification breaks pymdown_extensions (Tilde & Caret) Apr 24, 2021
@dmitry-radzevich
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant