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

Syntax highlighting overrides HTML formatting inside code blocks #3524

Closed
gparyani opened this issue Apr 21, 2022 · 1 comment
Closed

Syntax highlighting overrides HTML formatting inside code blocks #3524

gparyani opened this issue Apr 21, 2022 · 1 comment
Labels
bug help welcome Could use help from community parser

Comments

@gparyani
Copy link

gparyani commented Apr 21, 2022

Describe the issue/behavior that seems buggy

When a code block that uses the HTML <pre><code> tags contains HTML formatting such as <b> or <s>, and the block is highlighted using highlight.js, any such formatting is overridden. Such formatting should be retained whenever possible, and in cases where it clashes with formatting applied by highlight.js (happens most commonly when highlighting Markdown), the type specified in the HTML tags should take precedence.

Sample Code or Instructions to Reproduce

The following code contains <i> and <strike><b> tags to make part of it italicized and another part struck out and bolded. This works when the HTML elements <pre><code> are used:

<pre><code>...
GROUP BY model.name, <i>attempt.type</i>, <strike><b>attempt.result</b></strike>
...</code></pre>

When the highlighting is performed, it incorrectly looks like:

...
GROUP BY model.name, attempt.type, attempt.result
...

(when seen through a black-and-white camera)

Expected behavior

The parts surrounded by the <i> tag and the<strike><b> tags should be italicized, and bold and struck out respectively. This is how the code block looks like when not highlighted:

...
GROUP BY model.name, attempt.type, attempt.result
...

Additional context

This issue was discovered on Stack Exchange. This is the Meta Stack Exchange bug report; the above code samples came from there. I should also note that this behavior works properly in the previous highlighter Stack Exchange formerly used, Prettify.

@gparyani gparyani added bug help welcome Could use help from community parser labels Apr 21, 2022
@joshgoebel
Copy link
Member

joshgoebel commented Apr 21, 2022

We call this kind of thing "HTML merging". This is intentionally no longer supported (in core) as in our opinion 98% of the time this is done inadvertently and only leaves users open to HTML injection attacks. This type of functionality can easily be added via plug-in for users who understand what they are doing:

#2889

I'd raise the issue with StackOverflow technical team if you think they should support this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community parser
Projects
None yet
Development

No branches or pull requests

2 participants