Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Core Grammars:
- fix(c, cpp) stop a raw string's closing delimiter from swallowing quotes, which broke highlighting of everything after the literal, issue #3585 [David Pavlovschii][]
- enh(python) add missing builtins: `aiter` and `anext` (Python 3.10), `frozendict` and `sentinel` (Python 3.15) [Hugo van Kemenade][]
- enh(python) Support t-strings [Nicolas Le Cam][]
- fix(yaml) stop empty lines from ending a block scalar (`|`/`>`), which caused the rest of the string to be re-parsed as YAML, issue #4090 [pikammmmm][]

Documentation:

Expand All @@ -33,6 +34,7 @@ CONTRIBUTORS
[Nicolas Le Cam]: https://github.com/KuSh
[Konstantin Baltsat]: https://github.com/Baltsat
[David Pavlovschii]: https://github.com/davidpavlovschi
[pikammmmm]: https://github.com/pikammmmm


## Version 11.11.3
Expand Down
6 changes: 5 additions & 1 deletion src/languages/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ export default function(hljs) {
//
// Indentation of subsequent lines must be the same to
// be considered part of the block
//
// Empty lines (and lines containing only spaces) do not end the block,
// they are part of its content - but only when another indented line
// follows, so that blank lines trailing the block are left alone.
className: 'string',
begin: '[\\|>]([1-9]?[+-])?[ ]*\\n( +)[^ ][^\\n]*\\n(\\2[^\\n]+\\n?)*'
begin: '[\\|>]([1-9]?[+-])?[ ]*\\n(?:[ ]*\\n)*( +)[^ ][^\\n]*\\n((?:[ ]*\\n)*\\2[^\\n]+\\n?)*'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason you added non-capturing? Generally (other than multi-match) our engine doesn't care about capturing or not... is this intended to be a performance improvement or were you just not aware that "capture doesn't matter"?

I wonder if we could break this into multiple lines/regex (with comments) and use our regex.concact to build the final regex... it's getting a little hard to follow.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Required here, not perf: \2 has to keep pointing at the indent group ( +). If the new groups capture, the indent becomes \3 and \2 refers to a group that can match zero times, so \2[^\n]+ degrades to "any line" and the block swallows what follows it — append baz: quux to the test sample and it gets pulled into the string.

Happy to rebuild it as commented pieces via regex.concat — say the word and I'll push that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh right, duh. :-)

say the word and I'll push that.

word.

},
{ // Ruby/Rails erb
begin: '<%[%=-]?',
Expand Down
26 changes: 26 additions & 0 deletions test/markup/yaml/block_empty_lines.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<span class="hljs-attr">nested:</span>
<span class="hljs-attr">literal:</span> <span class="hljs-string">|
still: a string

not: anymore
</span><span class="hljs-attr">folded:</span> <span class="hljs-string">&gt;
first line

second line
</span><span class="hljs-attr">leading-blank:</span> <span class="hljs-string">|

alpha
beta
</span><span class="hljs-attr">blank-has-spaces:</span> <span class="hljs-string">|
alpha

beta
</span><span class="hljs-attr">multiple-blanks:</span> <span class="hljs-string">|
alpha


beta
</span><span class="hljs-attr">trailing-blank:</span> <span class="hljs-string">|
alpha
</span>
<span class="hljs-attr">next_key:</span> <span class="hljs-string">after</span>
26 changes: 26 additions & 0 deletions test/markup/yaml/block_empty_lines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
nested:
literal: |
still: a string

not: anymore
folded: >
first line

second line
leading-blank: |

alpha
beta
blank-has-spaces: |
alpha

beta
multiple-blanks: |
alpha


beta
trailing-blank: |
alpha

next_key: after