-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[YAML Highlight] # inside strings is treated as comment #1075
Comments
Ah looks like the key is to have |
Actually its pretty tricky to support all these edge cases so not going to submit a PR yet. The current behavior supports multi line strings, but Im having trouble keeping that functionality while enabling comments inside of strings. Hoping someone more experienced with Prism might have some insights |
@mjrussell: thanks for reporting. (Poke @hason: you might want to check this issue) |
Mutli line's with comments i.e.: mutli: "mutli line
with # inside" # and out will fail because the regex (probably not new behavior actually with greedy): Expects the last capture group |
As you can see in my commit above, the issue with # inside strings should be solved. That is, But we are still facing two issues here. The first one, related to YAML, is the abusive use of that group The second one is a flaw in the current greedy behaviour, which can be reproduced with nearly every other component: ... and probably nearly all other components... The greedy string, when processed, invalidates the previously matched comment (the large one, beginning at the middle of the string) but does not force it to be reconsidered. So even the smaller comment, the one that actually is to be highligted, is ignored... Obviously, the Poke @LeaVerou, @zeitgeist87: Should I open an issue for this? Will we go on that road again? Are we willing to improve the greedy behaviour? |
Hi @Golmote, Thanks for your great work. I've quickly thrown together a fix for this bug #1095. It seems to work for your examples, and it passes all tests in our test suite. I haven't tested it further though. The PR refactors the tokenize() method, so that a subset of it can be called recursively. That way the greedy flag can cleanup after itself. The diff looks worse than it is, because I had to move a few things around. |
Awesome to see some progress on this! Agree I had many issues with greedy behavior before so excited to see how @zeitgeist87's tweaks work |
This should be fixed by #1095 |
In YAML, the
#
for comments can appear inside strings which are enclosed with"
or'
Github formatting:
Prism:
I understand it is because https://github.com/PrismJS/prism/blob/gh-pages/components/prism-yaml.js#L7 is too greedy. But Im not sure how to change it. Would look behind for
"
or'
be sufficient?The text was updated successfully, but these errors were encountered: