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

[BUG] - && not displaying correctly in post #2457

Closed
Kevan-Y opened this issue Nov 9, 2021 · 1 comment · Fixed by #2468
Closed

[BUG] - && not displaying correctly in post #2457

Kevan-Y opened this issue Nov 9, 2021 · 1 comment · Fixed by #2468
Assignees
Labels
type: bug Something isn't working

Comments

@Kevan-Y
Copy link
Contributor

Kevan-Y commented Nov 9, 2021

What happened:
Post with && wrapped in code tag turn to &amp&amp.

image

Post Link: https://telescope.cdot.systems/search/?text=Static%20Analysis%20tooling%20%F0%9F%9B%A0&filter=post

What should have happened:
&& should render correctly

Anything else we need to know?:
Related to this fix #2337.

The file causing this issue

dom.window.document.querySelectorAll('pre code').forEach((code) => {
const { value, language } = hljs.highlightAuto(code.innerHTML);
// If the language wasn't detected, return the HTML untouched
if (!language) {
return;
}
// Otherwise, decorate the <pre> with class names for highlighting this language
const pre = code.parentNode;
if (pre) {
pre.classList.add('hljs', language);
}
// Value from hljs.highlightAuto turn escape character to e.g &lt; to &amp;lt;
// Adding regex to convert &amp; of that escape character back to &
// Replace the contents with newly marked up syntax highlighting
code.innerHTML = value.replace(/\&amp;([^;|^&]+);/gm, '&$1');

Sample of the data from the feed looks like this:

<pre class="highlight shell"><code>npx husky-init <span class="o">&amp;&amp;</span> npm <span class="nb">install\n</span>npm <span class="nb">install</span> <span class="nt">--save-dev</span> prettier pretty-quick\n</code></pre>

When passing to the hljs.highlightAuto
It becomes

npx husky<span class="hljs-operator">-</span>init <span class="hljs-operator">&amp;</span>amp;<span class="hljs-operator">&amp;</span>amp; npm install
    npm install <span class="hljs-comment">--save-dev prettier pretty-quick</span>

I think the regex fails for this case
Passing to the regex returns

npx husky<span class="hljs-operator">-</span>init <span class="hljs-operator">&</span>amp<span class="hljs-operator">&</span>amp npm install
    npm install <span class="hljs-comment">--save-dev prettier pretty-quick</span>

Environment:

  • OS: Windows 11
  • Browser: Chrome Version 94.0.4606.61
@Kevan-Y Kevan-Y added the type: bug Something isn't working label Nov 9, 2021
@Kevan-Y Kevan-Y self-assigned this Nov 9, 2021
@Kevan-Y
Copy link
Contributor Author

Kevan-Y commented Nov 9, 2021

I'm gonna take this issue

@Kevan-Y Kevan-Y mentioned this issue Nov 15, 2021
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant