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: whitespace between pre tags not preserved when it contains tags #82

Closed
saimiri opened this Issue May 27, 2016 · 11 comments

Comments

Projects
None yet
4 participants
@saimiri

saimiri commented May 27, 2016

Whitespace between pre tags is meaningful. pre tags are usually used specifically to keep the formatting including whitespace, so that for example code snippets are indented correctly.

@tdewolff

This comment has been minimized.

Show comment
Hide comment
@tdewolff

tdewolff May 27, 2016

Owner

You are right, this must be a regression. I'm away now and I can only fix this in August..

Owner

tdewolff commented May 27, 2016

You are right, this must be a regression. I'm away now and I can only fix this in August..

@saimiri

This comment has been minimized.

Show comment
Hide comment
@saimiri

saimiri May 28, 2016

Upon further examination, it seems that tags inside the pre element are the ones causing the problem.

I'm using Hugo, which in turn uses Pygments to add syntax highlighting to code snippets. It creates structures like this:

<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span style="color: #f92672">&lt;field</span>
  <span style="color: #a6e22e">name=</span><span style="color: #e6db74">&quot;fieldset_title&quot;</span>
  <span style="color: #a6e22e">type=</span><span style="color: #e6db74">&quot;text&quot;</span> <span style="color: #a6e22e">default=</span><span style="color: #e6db74">&quot;SMR_CCO_FIELDSET_DEFAULT_TITLE&quot;</span>
  <span style="color: #a6e22e">label=</span><span style="color: #e6db74">&quot;SMR_CCO_FIELDSET_TITLE&quot;</span>
  <span style="color: #a6e22e">filter=</span><span style="color: #e6db74">&quot;string&quot;</span>
  <span style="color: #a6e22e">translate_default=</span><span style="color: #e6db74">&quot;true&quot;</span> <span style="color: #f92672">/&gt;</span>
</pre></div>

Minify correctly preserves the linebreaks but it strips the whitespace from inside between the span tags.

<div class="highlight" style="background: #272822"><pre style=line-height:125%><span style=color:#f92672>&lt;field</span>
<span style=color:#a6e22e>name=</span><span style=color:#e6db74>&quot;fieldset_title&quot;</span>
<span style=color:#a6e22e>type=</span><span style=color:#e6db74>&quot;text&quot;</span> <span style=color:#a6e22e>default=</span><span style=color:#e6db74>&quot;SMR_CCO_FIELDSET_DEFAULT_TITLE&quot;</span>
<span style=color:#a6e22e>label=</span><span style=color:#e6db74>&quot;SMR_CCO_FIELDSET_TITLE&quot;</span>
<span style=color:#a6e22e>filter=</span><span style=color:#e6db74>&quot;string&quot;</span>
<span style=color:#a6e22e>translate_default=</span><span style=color:#e6db74>&quot;true&quot;</span> <span style=color:#f92672>/&gt;</span></pre></div>

If there are no other tags inside the pre, whitespace is preserved like it should.

As a side note, I tried something like this:

<pre>
    <div>
        [code here]
    </div>
</pre>

The result was the same as with span tags, except the closing div tag was stripped away too.

I'd be happy to help you with this but I'm afraid I'm not familiar enough with Go to do so.

saimiri commented May 28, 2016

Upon further examination, it seems that tags inside the pre element are the ones causing the problem.

I'm using Hugo, which in turn uses Pygments to add syntax highlighting to code snippets. It creates structures like this:

<div class="highlight" style="background: #272822"><pre style="line-height: 125%"><span style="color: #f92672">&lt;field</span>
  <span style="color: #a6e22e">name=</span><span style="color: #e6db74">&quot;fieldset_title&quot;</span>
  <span style="color: #a6e22e">type=</span><span style="color: #e6db74">&quot;text&quot;</span> <span style="color: #a6e22e">default=</span><span style="color: #e6db74">&quot;SMR_CCO_FIELDSET_DEFAULT_TITLE&quot;</span>
  <span style="color: #a6e22e">label=</span><span style="color: #e6db74">&quot;SMR_CCO_FIELDSET_TITLE&quot;</span>
  <span style="color: #a6e22e">filter=</span><span style="color: #e6db74">&quot;string&quot;</span>
  <span style="color: #a6e22e">translate_default=</span><span style="color: #e6db74">&quot;true&quot;</span> <span style="color: #f92672">/&gt;</span>
</pre></div>

Minify correctly preserves the linebreaks but it strips the whitespace from inside between the span tags.

<div class="highlight" style="background: #272822"><pre style=line-height:125%><span style=color:#f92672>&lt;field</span>
<span style=color:#a6e22e>name=</span><span style=color:#e6db74>&quot;fieldset_title&quot;</span>
<span style=color:#a6e22e>type=</span><span style=color:#e6db74>&quot;text&quot;</span> <span style=color:#a6e22e>default=</span><span style=color:#e6db74>&quot;SMR_CCO_FIELDSET_DEFAULT_TITLE&quot;</span>
<span style=color:#a6e22e>label=</span><span style=color:#e6db74>&quot;SMR_CCO_FIELDSET_TITLE&quot;</span>
<span style=color:#a6e22e>filter=</span><span style=color:#e6db74>&quot;string&quot;</span>
<span style=color:#a6e22e>translate_default=</span><span style=color:#e6db74>&quot;true&quot;</span> <span style=color:#f92672>/&gt;</span></pre></div>

If there are no other tags inside the pre, whitespace is preserved like it should.

As a side note, I tried something like this:

<pre>
    <div>
        [code here]
    </div>
</pre>

The result was the same as with span tags, except the closing div tag was stripped away too.

I'd be happy to help you with this but I'm afraid I'm not familiar enough with Go to do so.

@tdewolff tdewolff changed the title from Needs an option to keep whitespace between pre tags as it is to HTML: whitespace between pre tags not preserved when it contains tags Jul 20, 2016

@tdewolff tdewolff closed this in 7d6ef9e Aug 20, 2016

@nsetyo

This comment has been minimized.

Show comment
Hide comment
@nsetyo

nsetyo Feb 11, 2017

I'm sorry to bump an old thread, i'm still facing this issue in latest version

This is before minify

<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">[</span>
    <span class="p">{</span>
        <span class="nt">&quot;name&quot;</span>      <span class="p">:</span> <span class="s2">&quot;read_data&quot;</span><span class="p">,</span>
        <span class="nt">&quot;file_name&quot;</span> <span class="p">:</span> <span class="s2">&quot;./maps/IDN_adm1-simplified.shp&quot;</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="nt">&quot;name&quot;</span>      <span class="p">:</span> <span class="s2">&quot;write_data&quot;</span><span class="p">,</span>
        <span class="nt">&quot;format&quot;</span>    <span class="p">:</span> <span class="s2">&quot;jvectormap&quot;</span><span class="p">,</span>
        <span class="nt">&quot;file_name&quot;</span> <span class="p">:</span> <span class="s2">&quot;./output/indonesia-adm1.js&quot;</span><span class="p">,</span>
        <span class="nt">&quot;params&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="nt">&quot;code_field&quot;</span><span class="p">:</span> <span class="s2">&quot;ID_1&quot;</span><span class="p">,</span>
            <span class="nt">&quot;name_field&quot;</span><span class="p">:</span> <span class="s2">&quot;NAME_1&quot;</span><span class="p">,</span>
            <span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;indonesia-adm1&quot;</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">]</span>
</code></pre></div>

and this is after minify

<div class=highlight><pre><code class=language-json data-lang=json><span></span><span class=p>[</span>
<span class=p>{</span>
<span class=nt>&quot;name&quot;</span> <span class=p>:</span> <span class=s2>&quot;read_data&quot;</span><span class=p>,</span>
<span class=nt>&quot;file_name&quot;</span> <span class=p>:</span> <span class=s2>&quot;./maps/IDN_adm1-simplified.shp&quot;</span>
<span class=p>},</span>
<span class=p>{</span>
<span class=nt>&quot;name&quot;</span> <span class=p>:</span> <span class=s2>&quot;write_data&quot;</span><span class=p>,</span>
<span class=nt>&quot;format&quot;</span> <span class=p>:</span> <span class=s2>&quot;jvectormap&quot;</span><span class=p>,</span>
<span class=nt>&quot;file_name&quot;</span> <span class=p>:</span> <span class=s2>&quot;./output/indonesia-adm1.js&quot;</span><span class=p>,</span>
<span class=nt>&quot;params&quot;</span><span class=p>:</span> <span class=p>{</span>
<span class=nt>&quot;code_field&quot;</span><span class=p>:</span> <span class=s2>&quot;ID_1&quot;</span><span class=p>,</span>
<span class=nt>&quot;name_field&quot;</span><span class=p>:</span> <span class=s2>&quot;NAME_1&quot;</span><span class=p>,</span>
<span class=nt>&quot;name&quot;</span><span class=p>:</span> <span class=s2>&quot;indonesia-adm1&quot;</span>
<span class=p>}</span>
<span class=p>}</span>
<span class=p>]</span></code></pre></div>

I'm using hugo with pygment syntax highlight, can you help me?

nsetyo commented Feb 11, 2017

I'm sorry to bump an old thread, i'm still facing this issue in latest version

This is before minify

<div class="highlight"><pre><code class="language-json" data-lang="json"><span></span><span class="p">[</span>
    <span class="p">{</span>
        <span class="nt">&quot;name&quot;</span>      <span class="p">:</span> <span class="s2">&quot;read_data&quot;</span><span class="p">,</span>
        <span class="nt">&quot;file_name&quot;</span> <span class="p">:</span> <span class="s2">&quot;./maps/IDN_adm1-simplified.shp&quot;</span>
    <span class="p">},</span>
    <span class="p">{</span>
        <span class="nt">&quot;name&quot;</span>      <span class="p">:</span> <span class="s2">&quot;write_data&quot;</span><span class="p">,</span>
        <span class="nt">&quot;format&quot;</span>    <span class="p">:</span> <span class="s2">&quot;jvectormap&quot;</span><span class="p">,</span>
        <span class="nt">&quot;file_name&quot;</span> <span class="p">:</span> <span class="s2">&quot;./output/indonesia-adm1.js&quot;</span><span class="p">,</span>
        <span class="nt">&quot;params&quot;</span><span class="p">:</span> <span class="p">{</span>
            <span class="nt">&quot;code_field&quot;</span><span class="p">:</span> <span class="s2">&quot;ID_1&quot;</span><span class="p">,</span>
            <span class="nt">&quot;name_field&quot;</span><span class="p">:</span> <span class="s2">&quot;NAME_1&quot;</span><span class="p">,</span>
            <span class="nt">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;indonesia-adm1&quot;</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">]</span>
</code></pre></div>

and this is after minify

<div class=highlight><pre><code class=language-json data-lang=json><span></span><span class=p>[</span>
<span class=p>{</span>
<span class=nt>&quot;name&quot;</span> <span class=p>:</span> <span class=s2>&quot;read_data&quot;</span><span class=p>,</span>
<span class=nt>&quot;file_name&quot;</span> <span class=p>:</span> <span class=s2>&quot;./maps/IDN_adm1-simplified.shp&quot;</span>
<span class=p>},</span>
<span class=p>{</span>
<span class=nt>&quot;name&quot;</span> <span class=p>:</span> <span class=s2>&quot;write_data&quot;</span><span class=p>,</span>
<span class=nt>&quot;format&quot;</span> <span class=p>:</span> <span class=s2>&quot;jvectormap&quot;</span><span class=p>,</span>
<span class=nt>&quot;file_name&quot;</span> <span class=p>:</span> <span class=s2>&quot;./output/indonesia-adm1.js&quot;</span><span class=p>,</span>
<span class=nt>&quot;params&quot;</span><span class=p>:</span> <span class=p>{</span>
<span class=nt>&quot;code_field&quot;</span><span class=p>:</span> <span class=s2>&quot;ID_1&quot;</span><span class=p>,</span>
<span class=nt>&quot;name_field&quot;</span><span class=p>:</span> <span class=s2>&quot;NAME_1&quot;</span><span class=p>,</span>
<span class=nt>&quot;name&quot;</span><span class=p>:</span> <span class=s2>&quot;indonesia-adm1&quot;</span>
<span class=p>}</span>
<span class=p>}</span>
<span class=p>]</span></code></pre></div>

I'm using hugo with pygment syntax highlight, can you help me?

@tdewolff

This comment has been minimized.

Show comment
Hide comment
@tdewolff

tdewolff Feb 21, 2017

Owner

Hmm that is weird, I will look at it shortly!

Owner

tdewolff commented Feb 21, 2017

Hmm that is weird, I will look at it shortly!

@tdewolff

This comment has been minimized.

Show comment
Hide comment
@tdewolff

tdewolff Feb 24, 2017

Owner

I'm not sure what goes wrong. The CLI tool works correctly, if I add a test case it works correctly but if I run it through the online tool I get all the spaces stripped like you describe.

Can you make sure you have updated github.com/tdewolff/parse and github.com/tdewolff/minify correctly?

Owner

tdewolff commented Feb 24, 2017

I'm not sure what goes wrong. The CLI tool works correctly, if I add a test case it works correctly but if I run it through the online tool I get all the spaces stripped like you describe.

Can you make sure you have updated github.com/tdewolff/parse and github.com/tdewolff/minify correctly?

@carlmjohnson

This comment has been minimized.

Show comment
Hide comment
@carlmjohnson

carlmjohnson Feb 24, 2017

Contributor

I am also having this issue. I ran minify -u then had it process a file on my blog. It looks like something went wrong with pre preservation code.

https://gist.github.com/carlmjohnson/2090b23fc40b99dd5a9f7d2167aac001

Contributor

carlmjohnson commented Feb 24, 2017

I am also having this issue. I ran minify -u then had it process a file on my blog. It looks like something went wrong with pre preservation code.

https://gist.github.com/carlmjohnson/2090b23fc40b99dd5a9f7d2167aac001

@nsetyo

This comment has been minimized.

Show comment
Hide comment
@nsetyo

nsetyo Feb 24, 2017

Can you make sure you have updated github.com/tdewolff/parse and github.com/tdewolff/minify correctly?

I'm using binary version in https://bin.equinox.io/c/dhgbqpS8Bvy/minify-stable-linux-amd64.tgz

nsetyo commented Feb 24, 2017

Can you make sure you have updated github.com/tdewolff/parse and github.com/tdewolff/minify correctly?

I'm using binary version in https://bin.equinox.io/c/dhgbqpS8Bvy/minify-stable-linux-amd64.tgz

@tdewolff

This comment has been minimized.

Show comment
Hide comment
@tdewolff

tdewolff Feb 25, 2017

Owner

It appeared that the issue in go.tacodewolff.nl/minify had to do with CSS and is unrelated.

The repository 2.1.0 branch (and master) work fine and don't contain this regression. However, it seems that the binary build at Equinox is not incorporating 7d6ef9e, which makes me wonder if it contains any of the new commits...

Owner

tdewolff commented Feb 25, 2017

It appeared that the issue in go.tacodewolff.nl/minify had to do with CSS and is unrelated.

The repository 2.1.0 branch (and master) work fine and don't contain this regression. However, it seems that the binary build at Equinox is not incorporating 7d6ef9e, which makes me wonder if it contains any of the new commits...

@tdewolff

This comment has been minimized.

Show comment
Hide comment
@tdewolff

tdewolff Feb 25, 2017

Owner

@nsetyo @carlmjohnson I don't know what went wrong last time, but I've published a new release through Equinox and this seems to be the correct version of the code. Please run minify -u again and let me know if the problem is resolved.

Owner

tdewolff commented Feb 25, 2017

@nsetyo @carlmjohnson I don't know what went wrong last time, but I've published a new release through Equinox and this seems to be the correct version of the code. Please run minify -u again and let me know if the problem is resolved.

@nsetyo

This comment has been minimized.

Show comment
Hide comment
@nsetyo

nsetyo Feb 26, 2017

@tdewolff it's working now
thanks

nsetyo commented Feb 26, 2017

@tdewolff it's working now
thanks

@carlmjohnson

This comment has been minimized.

Show comment
Hide comment
@carlmjohnson

carlmjohnson Feb 28, 2017

Contributor

It looks like it's preserving whitespace now, thanks. But I have a different problem: it's not working as expected with -r. I'll open a separate ticket for it.

Contributor

carlmjohnson commented Feb 28, 2017

It looks like it's preserving whitespace now, thanks. But I have a different problem: it's not working as expected with -r. I'll open a separate ticket for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment