question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`<` sign rendered as beginning of new HTML element

See original GitHub issue

I’ve been looking online and checked the documentation, but I found nothing on this issue.

It might be no issue though. I’m placing the C++ code inside the

<pre>
    <code>
        #include <stdio.h>
    </code>
</pre>

And in the HTML it’s rendered as

#include

and when inspect the code it looks like the new HTML element is created

<span class="hljs-meta">
    #
    <span class="hljs-meta-keyword">include</span>
</span>
<stdio.h></stdio.h>

Am I doing something wrong? Any help would be appreciated. Thanks

Browser: Chrome Version 47.0.2526.73 (64-bit)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
isagalaevcommented, Apr 27, 2019

<pre> in HTML doesn’t mean that text inside it will be auto escaped. This is in fact a common misconception. If highlight.js were to suddenly interpret tags inside <pre> literally, it would be a) quite surprising to people who do know how it works and b) would prevent people from having custom markup inside it. For example, right now you can do something like:

<pre>
...
<span style="background: red"></span>
</pre>

That wouldn’t be possible if we would autoescape it.

Also, you’re supposed to pre-escape any text you want to put inside HTML anyway for security purposes. It would be really cumbersome to force people who do it do something like if (it's a "pre" tag && highlight.js is active) { unescape text back }.

0reactions
josxcommented, Apr 26, 2019

Clearly I understand how to escape chars to html entities, but from my perspective if highlight.js forces to use <pre> tags in browser, it need to support out of the box this feature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<pre>: The Preformatted Text element - HTML - MDN Web Docs
The <pre> HTML element represents preformatted text which is to be presented exactly as written in the HTML file. The text is typically ......
Read more >
React Render HTML - W3Schools
The purpose of the function is to display the specified HTML code inside the specified HTML element. But render where? There is another...
Read more >
WebD2: Common HTML Tags - University of Washington
An opening tag begins a section of page content, and a closing tag ends it. For example, to markup a section of text...
Read more >
Structural markup and right-to-left text in HTML - W3C
Use the dir attribute on a block element only when you need to change the base direction of content in that block. Having...
Read more >
Render HTML element in browser - javascript - Stack Overflow
using jQuery is a bit much here, but usually simple for a start. //learn ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found