Reuse of mode containing "starts: { endWithParent: true }" not possible.
See original GitHub issueI’m still doing my analysis, but maybe anyone already has an idea, so I write everything down here.
In the new rules for the Handlebars language, I found that reusing some mode-definitions did not work because highlight somehow modifies them in context to its parent mode.
I have created a minimal test-case to reproduce this issue:
let hljs = require('../../build');
describe("bugs", function () {
describe("modes containing 'endsWithParent'", function () {
it("should be allowed to be reused", function () {
hljs.registerLanguage('test-language', function (hljs) {
const TAG_CONTENTS = {className: 'name', begin: /\w+/, starts: {endsWithParent: true}};
const PAREN_TAG = {className: 'tag', begin: /\(/, end: /\)/, contains: [TAG_CONTENTS]};
const SQUARE_BRACKET_TAG = {className: 'tag', begin: /\[/, end: /\]/, contains: [TAG_CONTENTS]};
return {
contains: [PAREN_TAG, SQUARE_BRACKET_TAG]
};
});
hljs.highlight('test-language', '(abc 123) [abc 123] (abc 123)').value
.should.equal(
'<span class="hljs-tag">(<span class="hljs-name">abc</span> 123)</span> ' +
'<span class="hljs-tag">[<span class="hljs-name">abc</span> 123]</span> ' +
'<span class="hljs-tag">(<span class="hljs-name">abc</span> 123)</span>'
)
})
})
})
The expected output (“should.equal” above) is
<span class="hljs-tag">(<span class="hljs-name">abc</span> 123)</span> <span class="hljs-tag">[<span class="hljs-name">abc</span> 123]</span> <span class="hljs-tag">(<span class="hljs-name">abc</span> 123)</span>
but the actual output is
<span class="hljs-tag">(<span class="hljs-name">abc</span> 123)</span> <span class="hljs-tag">[<span class="hljs-name">abc</span> 123] (abc 123)</span>
As you can see, the mode for [abc 123]
is not terminated after the closing square bracket, but remains until the end of the string.
Looking at the “compiled” language, I can see that the property SQUARE_BRACKET_TAG.contains[0].starts.terminator_end
is /\)/
but it should by /\]/
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
20211106 Nov 6 Data Drop
Toss it all, The new curriculum is not working for students or teachers. ... a written summary at year end. With parent/teacher interviews...
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
Fixed in master!
Updated PR with modified handlebars definition reproducing the old bug (now fixed) #2207