all repos — htmlformat @ 09c6d471f34326c8631ebcc204beb3e1e702f1d0

Go package and CLI tool used to format HTML

fix some <pre> edge cases unescaping entities inside <pre><code> tags whitespace handling

Alin
commit

09c6d471f34326c8631ebcc204beb3e1e702f1d0

parent

69d6c2d86b95f2897d9751c22d14277419276c6e

1 file changed, 33 insertions(+), 0 deletions(-)

changed files
M format_test.goformat_test.go
@@ -102,6 +102,39 @@ <time>19:00</time>–<time>20:00</time>
</div> `, }, + { + name: "HTML entities in pre/code blocks are preserved", + input: `<pre><code>&lt;tab&gt;</code></pre>`, + expected: `<pre> +<code>&lt;tab&gt;</code></pre> +`, + }, + { + name: "multiple HTML entities in pre blocks are preserved", + input: `<pre>&lt;html&gt; &amp; &quot;quotes&quot;</pre>`, + expected: `<pre>&lt;html&gt; &amp; &#34;quotes&#34;</pre> +`, + }, + { + name: "HTML entities in nested code within pre are preserved", + input: `<pre>Some text <code>&lt;tag&gt;</code> more text</pre>`, + expected: `<pre> +Some text <code>&lt;tag&gt;</code> more text</pre> +`, + }, + { + name: "ampersands in pre blocks are preserved", + input: `<pre>npm install &amp;&amp; npm test</pre>`, + expected: `<pre>npm install &amp;&amp; npm test</pre> +`, + }, + { + name: "complex HTML entities in code blocks are preserved", + input: `<pre><code>const html = "&lt;div class=&quot;test&quot;&gt;Hello &amp; goodbye&lt;/div&gt;";</code></pre>`, + expected: `<pre> +<code>const html = &#34;&lt;div class=&#34;test&#34;&gt;Hello &amp; goodbye&lt;/div&gt;&#34;;</code></pre> +`, + }, } for _, test := range tests {