You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When formatting newline whitespace in HTML inside a <pre>, newlines are sometimes rendered twice.
First the original newline token is rendered, and then
the token has another newline to close the span.
This only seems to happen after comments in Elixir code, so this issue might be a tokenizer issue and not an HTML formatter issue.
For example, using makeup 1.0.5 and makeup_elixir 0.15.1, given this string:
defmodule BestStructEver do\r\n defstruct [:a]\r\nend\r\n\r\n# Struct to simple map:\r\niex> Map.from_struct(%BestStructEver{a: \"foobar\"})\r\n# => %{a: \"foobar\"}\r\n\r\n# Map to a struct:\r\niex> struct(BestStructEver, %{a: \"foobar\"})\r\n# => %BestStructEver{a: \"foobar\"}\r\n\r\n# Note: The struct function is from Kernel, so `Kernel.` can be omitted.
It is rendered this way using a Phoenix template <%= raw(Makeup.highlight(my_code_here)) %>:
<preclass="highlight"><code><spanclass="kd">defmodule</span><spanclass="w"></span><spanclass="nc">BestStructEver</span><spanclass="w"></span><spanclass="k" data-group-id="8518303302-1">do</span><spanclass="w"></span><spanclass="kd">defstruct</span><spanclass="w"></span><spanclass="p" data-group-id="8518303302-2">[</span><spanclass="ss">:a</span><spanclass="p" data-group-id="8518303302-2">]</span><spanclass="w"></span><spanclass="k" data-group-id="8518303302-1">end</span><spanclass="w"></span><spanclass="c1"># Struct to simple map:
</span><spanclass="w"></span><spanclass="gp unselectable">iex> </span><spanclass="nc">Map</span><spanclass="o">.</span><spanclass="n">from_struct</span><spanclass="p" data-group-id="8518303302-3">(</span><spanclass="p" data-group-id="8518303302-4">%</span><spanclass="nc" data-group-id="8518303302-4">BestStructEver</span><spanclass="p" data-group-id="8518303302-4">{</span><spanclass="ss">a</span><spanclass="p">:</span><spanclass="w"></span><spanclass="s">"foobar"</span><spanclass="p" data-group-id="8518303302-4">}</span><spanclass="p" data-group-id="8518303302-3">)</span><spanclass="w"></span><spanclass="c1"># => %{a: "foobar"}
</span><spanclass="w"></span><spanclass="c1"># Map to a struct:
</span><spanclass="w"></span><spanclass="gp unselectable">iex> </span><spanclass="n">struct</span><spanclass="p" data-group-id="8518303302-5">(</span><spanclass="nc">BestStructEver</span><spanclass="p">,</span><spanclass="w"></span><spanclass="p" data-group-id="8518303302-6">%{</span><spanclass="ss">a</span><spanclass="p">:</span><spanclass="w"></span><spanclass="s">"foobar"</span><spanclass="p" data-group-id="8518303302-6">}</span><spanclass="p" data-group-id="8518303302-5">)</span><spanclass="w"></span><spanclass="c1"># => %BestStructEver{a: "foobar"}
</span><spanclass="w"></span><spanclass="c1"># Note: The struct function is from Kernel, so `Kernel.` can be omitted.</span></code></pre>
appearing like this image:
When it should appear more like this (ignoring the theme -- this is not Makeup):
When I fork makeup, I think I fix it if I treat the newline as if it needed escaping, rendering an empty string instead, but I feel like this fixes it the wrong way. Instead I feel the span closing tag should not have a newline before it.
<preclass="highlight"><code><spanclass="kd">defmodule</span><spanclass="w"></span><spanclass="nc">BestStructEver</span><spanclass="w"></span><spanclass="k" data-group-id="7157529561-1">do</span><spanclass="w"></span><spanclass="kd">defstruct</span><spanclass="w"></span><spanclass="p" data-group-id="7157529561-2">[</span><spanclass="ss">:a</span><spanclass="p" data-group-id="7157529561-2">]</span><spanclass="w"></span><spanclass="k" data-group-id="7157529561-1">end</span><spanclass="w"></span><spanclass="c1"># Struct to simple map:
</span><spanclass="w"></span><spanclass="gp unselectable">iex> </span><spanclass="nc">Map</span><spanclass="o">.</span><spanclass="n">from_struct</span><spanclass="p" data-group-id="7157529561-3">(</span><spanclass="p" data-group-id="7157529561-4">%</span><spanclass="nc" data-group-id="7157529561-4">BestStructEver</span><spanclass="p" data-group-id="7157529561-4">{</span><spanclass="ss">a</span><spanclass="p">:</span><spanclass="w"></span><spanclass="s">"foobar"</span><spanclass="p" data-group-id="7157529561-4">}</span><spanclass="p" data-group-id="7157529561-3">)</span><spanclass="w"></span><spanclass="c1"># => %{a: "foobar"}
</span><spanclass="w"></span><spanclass="c1"># Map to a struct:
</span><spanclass="w"></span><spanclass="gp unselectable">iex> </span><spanclass="n">struct</span><spanclass="p" data-group-id="7157529561-5">(</span><spanclass="nc">BestStructEver</span><spanclass="p">,</span><spanclass="w"></span><spanclass="p" data-group-id="7157529561-6">%{</span><spanclass="ss">a</span><spanclass="p">:</span><spanclass="w"></span><spanclass="err">\</span><spanclass="err">"</span><spanclass="n">foobar</span><spanclass="err">\</span><spanclass="err">"</span><spanclass="p" data-group-id="7157529561-6">}</span><spanclass="p" data-group-id="7157529561-5">)</span><spanclass="w"></span><spanclass="c1"># => %BestStructEver{a: "foobar"}
</span><spanclass="w"></span><spanclass="c1"># Note: The struct function is from Kernel, so `Kernel.` can be omitted.</span></code></pre>
When formatting newline whitespace in HTML inside a
<pre>
, newlines are sometimes rendered twice.This only seems to happen after comments in Elixir code, so this issue might be a tokenizer issue and not an HTML formatter issue.
For example, using makeup 1.0.5 and makeup_elixir 0.15.1, given this string:
It is rendered this way using a Phoenix template
<%= raw(Makeup.highlight(my_code_here)) %>
:appearing like this image:
When it should appear more like this (ignoring the theme -- this is not Makeup):
When I fork makeup, I think I fix it if I treat the newline as if it needed escaping, rendering an empty string instead, but I feel like this fixes it the wrong way. Instead I feel the span closing tag should not have a newline before it.
It produces this HTML:
The same result happens when I
String.replace(code, "\r\n", "\n")
before passing it to makeup, so I don't believe that's causing it yet.The text was updated successfully, but these errors were encountered: