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.

JavaScript highlighting breaks on left angle bracket (less-than, <)

See original GitHub issue

This may be reproduced with the jQuery code ( http://code.jquery.com/jquery-1.10.1.js )

The less-than < operator, bit-shift operator << and some occurrences of < in comments produce a tag highlighting.

Examples from the jQuery code where tag is produced:

        // BMP codepoint
        high < 0 ?

// Support: Android<4.0
// Detect silently failing push.apply

// Support: Chrome<<14
// Always assume duplicates if they aren't passed to the comparison function

// General-purpose constants
strundefined = typeof undefined,
MAX_NEGATIVE = 1 << 31,

It looks like a major bug to me.

Also looks like the following lines of the language definition somehow connected to the issue, but I don’t exactly sure how to fix it (and if they are the only cause):

      { // E4X
        begin: '<', end: '>;',
        subLanguage: 'xml'
      }

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
isagalaevcommented, Feb 22, 2017

@unilobo the behavior you’re seeing is not caused by this bug which deals with a raw staring to highlight. Yours is just plain lack of escaping in HTML: you need to escape < in HTML if you want it literally. <code> has no special escaping rules and <h2> inside <code> is just a tag, same as everywhere else. This has nothing to do with highlight.js, really 😃

0reactions
unilobocommented, Feb 22, 2017

Hey, just using version 8/9 and this seems to suffer the same problem?

Namely, html does not display correctly unless replacing left angle bracket with &lt<;.

I wish you would mention this in docs/readme. d:)

Is this expected behavior or a bug?

Example here;

http://codepen.io/2dareis2do/pen/ygdWXV

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to disable angle bracket highlighting in Visual Studio ...
Show activity on this post. You can use the following: // Highlight matching brackets when one of them is selected. "editor. matchBrackets": ...
Read more >
Markdown: Syntax
Left angle brackets are used to start tags; ampersands are used to denote HTML entities. If you want to use them as literal...
Read more >
Grouping operator ( ) - JavaScript - MDN Web Docs
The grouping operator consists of a pair of parentheses around an expression that groups the contents. The operator overrides the normal ...
Read more >
HTML Entities - W3Schools
If you use the less than (<) or greater than (>) signs in your text, the browser might ... A commonly used entity...
Read more >
Query Parser Syntax - Apache Lucene
Terms. A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases. A Single Term...
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