(jsx) multiple self-closing tags with attributes highlighting broken
See original GitHub issueGiven 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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (10 by maintainers)
Top Results From Across the Web
React component closing tag - Stack Overflow
I've created a basic tab scroller as a JSFiddle using the self-closing <MyComponent /> and subsequent props, and I'm wondering if there's a ......
Read more >JSX fragment closing tag with a space breaks syntax ...
JSX multielement tag's ( <> ) closing counterpart ( </> ) is wrongly identified as a syntax error if there is a space...
Read more >Introducing JSX - React
This funny tag syntax is neither a string nor HTML. ... We split JSX over multiple lines for readability. ... Specifying Attributes with...
Read more >How do I get matchit to work with '/>' (self-closed tags)?
I really like to jump from one <el> to the end of </el> with matchit. I am using it for jsx, but it...
Read more >Troubleshooting MDX
The reason for this error is that only open tags can be closed. You probably forgot an opening tag somewhere. Unexpected attribute in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Thanks for tracking these jsx issues. @yyyc514
You are right about the
{}
. I know a little abouthighlight.js
and I usedxml
as sublanguage beacusesrc/language/javascript.js
usessublanguage: xml
for jsx and it seems to work.