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

CSS syntax highlighting + line numbers generates in invalid HTML #1994

Closed
jhpratt opened this issue Sep 22, 2022 · 3 comments
Closed

CSS syntax highlighting + line numbers generates in invalid HTML #1994

jhpratt opened this issue Sep 22, 2022 · 3 comments

Comments

@jhpratt
Copy link

jhpratt commented Sep 22, 2022

Bug Report

Environment

Zola version: 0.16.1

Step to reproduce

zola init
echo 'base_url = "https://example.com"\nminify_html = true\n[markdown]\nhighlight_code = true\nhighlight_theme = "css"' > config.toml
echo '+++\n+++\n\n```rust,linenos\nfn\n```\n\nfoo\n' > content/_index.md
echo '{{ section.content | safe }}' > templates/index.html
zola serve --open

Just press enter repeatedly for the prompts. It'll be overridden by this script.

Expected Behavior

HTML code is minified properly.

Current Behavior

Manually formatting the minified code results in this:

<pre class="language-rust z-code" data-lang=rust data-linenos>
    <code class=language-rust data-lang=rust>
        <table>
            <tbody>
                <tr>
                    <td>1<td>
                        <span class="z-source z-rust">
                            <span class="z-storage z-type z-function z-rust">fn</span>
<td><tr><span><tbody><table><code><pre>
<p>foo</p>

Note that the second to last line opens, rather than closes, the tags.

Now comment out minify_html = true in config.toml and run zola serve. The HTML generated follows (manually formatted again):

<pre data-linenos data-lang="rust" class="language-rust z-code">
    <code class="language-rust" data-lang="rust">
        <table>
            <tbody>
                <tr>
                    <td>1</td>
                    <td>
                        <span class="z-source z-rust">
                            <span class="z-storage z-type z-function z-rust">fn</span>
                    </td>
                </tr>
                        </span>
            </tbody>
        </table>
    </code>
</pre>
<p>foo</p>

Better, as the tags are at least closed here. However, they are still not in the correct order. I have shown this with indentation. </span> must be before </td>.

My suspicion is that the minifier is incapable of handling the invalid HTML — tags must be closed in the reverse order they are opened in. Browsers appear capable of handling the unminified code, although the minified code completely breaks the rest of the page.

@Keats
Copy link
Collaborator

Keats commented Sep 22, 2022

Duplicate of #1994
We should fix the random span showing up

@Keats Keats closed this as completed Sep 22, 2022
@jhpratt
Copy link
Author

jhpratt commented Sep 22, 2022

This is #1994 🙂

To be clear it's not a random span, it's just closed in the wrong spot. That's what I tried to show with the indentation in the second example.

I'll probably take a look into this myself tomorrow anyways.

@Keats
Copy link
Collaborator

Keats commented Sep 22, 2022

Argh I meant #1942

Yep for the span I meant we need to fix it

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

No branches or pull requests

2 participants