Skip to content

Commit 4adc549

Browse files
authored
[Markdown] Fix more block quote boundary issues (#3101)
1 parent 4f34fdc commit 4adc549

2 files changed

Lines changed: 205 additions & 102 deletions

File tree

Markdown/Markdown.sublime-syntax

Lines changed: 91 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ variables:
2727
)
2828
[ \t]*$ # followed by any number of tabs or spaces, followed by the end of the line
2929
)
30-
block_quote: (?:[ ]{,3}>(?:.|$)) # between 0 and 3 spaces, followed by a greater than sign, followed by any character or the end of the line
30+
block_quote: (?:[ ]{,3}(>)[ ]?) # between 0 and 3 spaces, followed by a greater than sign, (followed by any character or the end of the line = "only care about optional space!")
3131
atx_heading: (?:[ ]{,3}[#]{1,6}(?:[ \t]|$)) # between 0 and 3 spaces, followed 1 to 6 hashes, followed by at least one space or tab or by end of the line
3232
atx_heading_space: (?:(?=[ \t]+#+[ \t]*$)|[ \t]+|$) # consume spaces only if heading is not empty to ensure `atx_heading_end` can fully match closing hashes
3333
atx_heading_end: (?:[ \t]+(#+))?[ \t]*($\n?) # \n is optional so ## is matched as end punctuation in new document (at eof)
@@ -235,7 +235,7 @@ contexts:
235235
pattern will only match stuff matched by the sub-patterns.
236236
push:
237237
- meta_scope: meta.block-level.markdown
238-
- include: block-quote
238+
- include: block-quotes
239239
- include: ligatures
240240
- include: indented-code-block
241241
- include: atx-heading
@@ -388,9 +388,10 @@ contexts:
388388
# >= >== >=== >=> >==> >===> >=< >==< >===<
389389
- match: '<<+|<>|>>+' # << <<< <<<< <> >>>> >>> >>
390390

391-
block-quote:
392-
- match: '[ ]{,3}(>)[ ]?'
393-
comment: |
391+
block-quotes:
392+
# https://spec.commonmark.org/0.30/#block-quotes
393+
- match: ^{{block_quote}}
394+
comment: |-
394395
We terminate the block quote when seeing an empty line, a
395396
separator or a line with leading > characters. The latter is
396397
to “reset” the quote level for quoted lines.
@@ -401,62 +402,33 @@ contexts:
401402
captures:
402403
1: punctuation.definition.blockquote.markdown
403404
push:
404-
- meta_scope: markup.quote.markdown
405-
- match: |-
406-
(?x)^
407-
(?= \s*$
408-
| {{thematic_break}}
409-
| {{block_quote}}
410-
)
411-
pop: true
412-
- match: |-
413-
(?x)
414-
(?= {{block_quote}}
415-
)
416-
push:
417-
- match: ^
418-
pop: true
419-
- include: block-quote
420-
- match: |-
421-
(?x)
422-
(?= {{indented_code_block}}
423-
| {{atx_heading}}
424-
| {{thematic_break}}
425-
| {{list_item}}
426-
)
427-
push:
428-
- include: indented-code-block
429-
- include: atx-heading
430-
- include: thematic-break
431-
- match: ([ ]{,3})(\d+([.)]))(\s)
432-
captures:
433-
1: markup.list.numbered.markdown
434-
2: markup.list.numbered.bullet.markdown
435-
3: punctuation.definition.list_item.markdown
436-
4: markup.list.numbered.markdown
437-
push:
438-
- meta_content_scope: markup.list.numbered.markdown meta.paragraph.list.markdown
439-
- include: list-content
440-
- match: ([ ]{,3})([*+-])((?:[ ](\[[ xX]\]))?\s)
441-
captures:
442-
1: markup.list.unnumbered.markdown
443-
2: markup.list.unnumbered.bullet.markdown punctuation.definition.list_item.markdown
444-
3: markup.list.unnumbered.markdown
445-
4: constant.language.checkbox.markdown-gfm
446-
push:
447-
- meta_content_scope: markup.list.unnumbered.markdown meta.paragraph.list.markdown
448-
- include: list-content
449-
- match: ^
450-
pop: true
451-
- include: list-paragraph
452-
- include: block-quote-code-blocks
453-
- match: ''
454-
push:
455-
- match: ^
456-
pop: true
457-
- include: inline-bold-italic-linebreak
405+
- block-quote-meta
406+
- block-quote-content
458407

459-
block-quote-code-blocks:
408+
block-quote-nested:
409+
- match: '{{block_quote}}'
410+
captures:
411+
1: punctuation.definition.blockquote.markdown
412+
set:
413+
- block-quote-meta
414+
- block-quote-content
415+
416+
block-quote-meta:
417+
- meta_include_prototype: false
418+
- meta_scope: markup.quote.markdown
419+
- include: immediately-pop
420+
421+
block-quote-content:
422+
- include: block-quote-nested
423+
- include: block-quote-code-block
424+
- include: block-quote-list-item
425+
- include: atx-heading
426+
- include: indented-code-block
427+
- include: thematic-break
428+
- match: ''
429+
set: block-quote-text
430+
431+
block-quote-code-block:
460432
- match: |-
461433
(?x)
462434
{{fenced_code_block_start}}
@@ -466,22 +438,70 @@ contexts:
466438
0: meta.code-fence.definition.begin.text.markdown-gfm
467439
2: punctuation.definition.raw.code-fence.begin.markdown
468440
5: constant.other.language-name.markdown
469-
push: block-quote-code-block-content
441+
set: block-quote-code-block-content
470442
471443
block-quote-code-block-content:
444+
- match: ^(?!\s*{{block_quote}})
445+
pop: true
472446
- match: '{{code_fence_end}}'
473447
captures:
474448
0: meta.code-fence.definition.end.text.markdown-gfm
475449
1: punctuation.definition.raw.code-fence.end.markdown
476450
pop: true
477-
- match: '[ ]{,3}(>)[ ]?'
451+
- match: '{{block_quote}}'
478452
captures:
479453
1: punctuation.definition.blockquote.markdown
480454
- match: ''
481-
push:
482-
- meta_content_scope: markup.raw.code-fence.markdown-gfm
483-
- match: ^
484-
pop: true
455+
push: block-quote-code-block-text
456+
457+
block-quote-code-block-text:
458+
- meta_include_prototype: false
459+
- meta_content_scope: markup.raw.code-fence.markdown-gfm
460+
- match: ^
461+
pop: true
462+
463+
block-quote-list-item:
464+
- match: ([ ]{,3})(\d+)(\.)(\s)
465+
captures:
466+
1: markup.list.numbered.markdown
467+
2: markup.list.numbered.bullet.markdown
468+
3: markup.list.numbered.bullet.markdown punctuation.definition.list_item.markdown
469+
4: markup.list.numbered.markdown
470+
set:
471+
- block-quote-ordered-list-content
472+
- list-content
473+
- match: ([ ]{,3})([*+-])((?:[ ](\[[ xX]\]))?\s)
474+
captures:
475+
1: markup.list.unnumbered.markdown
476+
2: markup.list.unnumbered.bullet.markdown punctuation.definition.list_item.markdown
477+
3: markup.list.unnumbered.markdown
478+
4: constant.language.checkbox.markdown-gfm
479+
set:
480+
- block-quote-unordered-list-content
481+
- list-content
482+
483+
block-quote-ordered-list-content:
484+
- meta_content_scope: markup.list.numbered.markdown meta.paragraph.list.markdown
485+
- include: block-quote-text
486+
487+
block-quote-unordered-list-content:
488+
- meta_content_scope: markup.list.unnumbered.markdown meta.paragraph.list.markdown
489+
- include: block-quote-text
490+
491+
block-quote-text:
492+
- match: |-
493+
(?x)
494+
^
495+
(?= \s*$
496+
| {{atx_heading}}
497+
| {{block_quote}}
498+
| {{fenced_code_block_start}}
499+
| {{list_item}}
500+
| {{thematic_break}}
501+
)
502+
pop: true
503+
- include: inline-bold-italic-linebreak
504+
- include: scope:text.html.basic
485505

486506
indented-code-block:
487507
- match: '{{indented_code_block}}.*$\n?'
@@ -1118,11 +1138,12 @@ contexts:
11181138
- include: indented-code-block
11191139
- match: $
11201140
pop: true
1121-
- match: '^(?=\s+{{block_quote}})'
1141+
- match: ^[ ]*{{block_quote}}
1142+
captures:
1143+
1: punctuation.definition.blockquote.markdown
11221144
push:
1123-
- include: block-quote
1124-
- match: $
1125-
pop: true
1145+
- block-quote-meta
1146+
- block-quote-content
11261147
- include: fenced-code-blocks
11271148
- include: reference-link-definition
11281149
- match: \s+(?=\S)

0 commit comments

Comments
 (0)