highlight.js: (jsx) multiple self-closing tags with attributes highlighting broken
Given jsx code:
class App extends Component {
render() {
return (
<BrowserRouter>
<div>
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
</div>
</BrowserRouter>
);
}
}

It seems that the XML code is not highlighted because of the second Route tag with attributes.
When I tried to modify src/language/javascript.js
{ // E4X / JSX
begin: /</, end: /(\/\w+|\w+\/)>/,
subLanguage: 'xml',
contains: [
{begin: /<\w+\s*\/>/, skip: true},
{
- begin: /<\w+/, end: /(\/\w+|\w+\/)>/, skip: true,
+ begin: /<\w+/, end: /(\/\w+[^>]*|\w+\S*\s*\/)>/, skip: true,
contains: [
{begin: /<\w+\s*\/>/, skip: true},
'self'
]
}
]
}
The highlighting works as expected.

About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (10 by maintainers)
https://github.com/highlightjs/highlight.js/issues/1625 reminded me that it’s not JUST HTML inside these blocks, but you can have JS style comments, template variables, etc…
The more I read the more it seems a separate JSX grammar might be the right choice for dealing with all of this.