Skip to content
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

Fix #1601 Allow strings to have trailing comments #1602

Merged
merged 5 commits into from
Oct 29, 2018

Conversation

Chris-Johnston
Copy link
Contributor

Fixes #1601

Updates the string regex to allow for strings that may have a trailing '#'. This uses a different pattern from other regex patterns, because only the string regex pattern is greedy, while the others are not.

Example

Using the example code from #1601 , I get this result:

Updates the string regex to allow for strings that may have a trailing '#'.
This uses a different pattern from other regex patterns, because only
the string regex pattern is greedy, while the others are not.
Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR!

I left a comment with one minor thing to do and it'd be great if you were to add this case to the YAML string test.

@@ -31,7 +31,7 @@ Prism.languages.yaml = {
alias: 'important'
},
'string': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}))/m,
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}|(\s*#)))/m,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the capturing group around \s*#.

@@ -31,7 +31,7 @@ Prism.languages.yaml = {
alias: 'important'
},
'string': {
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}))/m,
pattern: /([:\-,[{]\s*(?:![^\s]+)?[ \t]*)("|')(?:(?!\2)[^\\\r\n]|\\.)*\2(?=[ \t]*(?:$|,|]|}|(?:\s*#)))/m,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that you don't need the group at all...
Sorry for not making myself clear enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, I had assumed that a grouping would be necessary. I just tried it and you are right.

This grouping was actually not required
@RunDevelopment
Copy link
Member

Perfect!

@mAAdhaTTah I think we are ready to merge.

@mAAdhaTTah mAAdhaTTah merged commit 1c5f28a into PrismJS:master Oct 29, 2018
@mAAdhaTTah
Copy link
Member

Thank you for the contribution!

@Chris-Johnston Chris-Johnston deleted the fix/1601 branch October 29, 2018 19:18
@plaindocs
Copy link

Thanks @Chris-Johnston @RunDevelopment @mAAdhaTTah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants