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

Newlines removed from code blocks when syntax highlighting and HTML minification both active #1300

Closed
flother opened this issue Jan 12, 2021 · 4 comments
Labels

Comments

@flother
Copy link
Contributor

flother commented Jan 12, 2021

Using Zola version 0.13.0, when minify_html = true and markdown.highlight_code = true in config.toml, newlines are removed from Markdown code blocks.

Expected behaviour

Newlines should be preserved within Markdown code blocks.

Current behaviour

When minify_html = true and markdown.highlight_code = true, this Markdown code block:

```rust
fn main() {
  println!("Hello, world!");
}
```

Is converted into this HTML:

<pre style=background-color:#2b303b;>
<code class=language-rust data-lang=rust><span style=color:#b48ead;>fn </span><span style=color:#8fa1b3;>main</span><span style=color:#c0c5ce;>() { println!("</span><span style=color:#a3be8c;>Hello, world!</span><span style=color:#c0c5ce;>"); } </span></code></pre>

When either (or both) minify_html or markdown.highlight_code are false, newlines are preserved, e.g.

<pre><code class=language-rust data-lang=rust>fn main() {
  println!("Hello, world!");
}
</code></pre>
@Keats Keats added the bug label Jan 12, 2021
FIGBERT added a commit to FIGBERT/figbert.com that referenced this issue Jan 16, 2021
The current implementation of HTML minification
conflicts with syntax highlighting. See here:

getzola/zola#1300
@Keats
Copy link
Collaborator

Keats commented Feb 2, 2021

It looks like it works as expected on the next branch for me?

@flother
Copy link
Contributor Author

flother commented Feb 4, 2021

I just compiled Zola from the head of the next branch and I still see this bug.

$ git clone git@github.com:getzola/zola.git
$ cd zola
$ git checkout next
$ cargo build
$ ./target/debug/zola init tester
Welcome to Zola!
Please answer a few questions to get started quickly.
Any choices made can be changed by modifying the `config.toml` file later.
> What is the URL of your site? (https://example.com):
> Do you want to enable Sass compilation? [Y/n]:
> Do you want to enable syntax highlighting? [y/N]: y
> Do you want to build a search index of the content? [y/N]:

Done! Your site was created in ./tester

Get started by moving into the directory and using the built-in server: `zola serve`
Visit https://www.getzola.org for the full documentation.

I then modified tester/config.toml to add minify_html = true just above the [markdown] section, and added a simple page template in tester/template/page.html:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
</head>
<body>
  {{ page.content|safe }}
</body>
</html>

And finally added a content page at tester/content/test.md:

+++
title = "A test"
+++

```rust
fn main() {
  println!("Hello, world!");
}
```

Then when I ran ../target/debug/zola serve and visited http://127.0.0.1:1111/test, all whitespace in the code block had been reduced:

$ curl http://127.0.0.1:1111/test
<!doctype html><html><head><meta charset=utf-8><body><pre style=background-color:#2b303b;>
<code class=language-rust data-lang=rust><span style=color:#b48ead;>fn </span><span style=color:#8fa1b3;>main</span><span style=color:#c0c5ce;>() { println!("</span><span style=color:#a3be8c;>Hello, world!</span><span style=color:#c0c5ce;>"); } </span></code></pre><script src=/livereload.js?port=1024&mindelay=10></script>

@Keats
Copy link
Collaborator

Keats commented Feb 5, 2021

You're right, I don't know how I tested it before.
I've filed wilsonzlin/minify-html#21 upstream

@beshrkayali
Copy link

Hi, just wanted to confirm that this is indeed fixed and working in the next branch after updating to 0.4.2 of minify-html.

tnytown pushed a commit to tnytown/website that referenced this issue Jul 17, 2021
Fixes regression introduced in c820dce.

The minify_html option wasn't implemented in the Zola version in Nixpkgs 20.09. When I bumped the
version to 21.05, it took affect and messed with linebreaks in the `<pre>` tag. Overrode Zola to
achieve the correct results. See getzola/zola#1300.
@Keats Keats closed this as completed in a65a2d5 Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants