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

Using the diff function, output is not escaped. #75

Closed
aaronstezycki opened this issue Nov 1, 2022 · 3 comments
Closed

Using the diff function, output is not escaped. #75

aaronstezycki opened this issue Nov 1, 2022 · 3 comments

Comments

@aaronstezycki
Copy link

aaronstezycki commented Nov 1, 2022

Using vite/slinkity to develop eleventy site along with this plugin.

Vite is fine with:

{% highlight "html" %}
  {% include "html.html" %}
{% endhighlight %}

But not with ...

{% highlight "diff-html" %}
  {% include "html.html" %}
{% endhighlight %}

I get a vite error, because vite doesn't like non escaped html code (via vite error)

The vite error:

Unable to parse HTML; Illegal tag name. Use '&lt;' to print '<'.
<div class="ds-example__code"><pre class="language-diff-html"><code class="language-diff-html"><span class="token deleted-arrow deleted language-html"><span class="token prefix deleted"><</span>h6>Heading 6<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>h6</span><span class="token punctuation">></span></span></span></code></pre></div>
                                                                                                                                                                                          ^

I've tried putting a safe filter around the include to ensure nunjucks escapes the included html file, but no dice.
Not using the diff and just using the shortcode normally, outputs escaped code without the vite error.

Does this mean the diff function is processing the 'output' content differently?

@zachleat zachleat added this to the Syntax Highlight v5.0.0 milestone Apr 12, 2023
zachleat added a commit that referenced this issue Apr 12, 2023
@zachleat
Copy link
Member

This is fixed in v5.0.0 and I included an automated test for this, thanks!

@aaronstezycki
Copy link
Author

@zachleat Unfortunately, just having tested this in my local it's still producing an HTML illegal tag error. Again output is fine when using the non diff tag, but when using for example "diff-html" it produces this error for me. It claims I should be using &lt; to print '<'.

Referring to the above code error and cutting it down to the identified character in question ...

<span class="token prefix deleted"><</span>h6>Heading 6<span class="token tag">
                                   ^

I think the syntax highlighter is causing this by adding a '<' somewhere in the output.

This is with v5.0.0

@aaronstezycki
Copy link
Author

aaronstezycki commented Aug 11, 2023

Okay, I think I've identified when/why this is happening. For context: I created a re-useable include file which was using {% highlight 'diff-html' %} by default. But not every instance of content/code being included within the highlight had a + or a -. After adding these indicators, the output seems to be fine and i get no error.

So the issue is when there are no diffing indicators used within {% highlight 'diff-html' %} it should continue to output valid html, but currently does not.

To get around this, using flag on the include i.e {% set diff = true %} to use diffing if it is needed otherwise just use normal highlighting.

Ideally though, the html output should be valid no matter if diffing is set, and or the containing code does/does not have a + or -.

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