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

[Markdown] Fix backticks and code-spans in table cells #3969

Merged
merged 2 commits into from
Apr 28, 2024
Merged
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
48 changes: 45 additions & 3 deletions Markdown/Markdown.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ variables:
| (?! \s*\-\s+ | \s+\|){{table_cell}}\|(?!\s+$)
)

table_codespan_content: |-
(?x:
[^`|] # first or only char must not be a backtick or pipe.
(?:[^|]*[^`|])? # none must be a pipe, the last additionally must not be a backtick
)

fenced_code_block_start: |-
(?x:
([ \t]*)
Expand Down Expand Up @@ -2366,14 +2372,50 @@ contexts:
table-cell-content:
- match: (?={{balanced_emphasis}})
push: table-cell-emphasis
- match: (?!{{backticks}})`+
scope: invalid.deprecated.unescaped-backticks.markdown
- include: table-cell-code-spans
- include: table-cell-separators
- include: images
- include: literals
- include: critics
- include: math-inline
- include: escapes
- include: links
- include: markups

table-cell-code-spans:
# code-spans quoted with up to 6 backticks are supported
# to avoid usage of slower Oniguruma features
- match: (`{6}){{table_codespan_content}}(`{6})(?!`)
scope: markup.raw.inline.markdown
captures:
1: punctuation.definition.raw.begin.markdown
2: punctuation.definition.raw.end.markdown
- match: (`{5}){{table_codespan_content}}(`{5})(?!`)
scope: markup.raw.inline.markdown
captures:
1: punctuation.definition.raw.begin.markdown
2: punctuation.definition.raw.end.markdown
- match: (`{4}){{table_codespan_content}}(`{4})(?!`)
scope: markup.raw.inline.markdown
captures:
1: punctuation.definition.raw.begin.markdown
2: punctuation.definition.raw.end.markdown
- match: (`{3}){{table_codespan_content}}(`{3})(?!`)
scope: markup.raw.inline.markdown
captures:
1: punctuation.definition.raw.begin.markdown
2: punctuation.definition.raw.end.markdown
- match: (`{2}){{table_codespan_content}}(`{2})(?!`)
scope: markup.raw.inline.markdown
captures:
1: punctuation.definition.raw.begin.markdown
2: punctuation.definition.raw.end.markdown
- match: (`{1}){{table_codespan_content}}(`{1})(?!`)
scope: markup.raw.inline.markdown
captures:
1: punctuation.definition.raw.begin.markdown
2: punctuation.definition.raw.end.markdown
- match: \`+ # consume remainers

table-cell-emphasis:
- include: emphasis
- include: immediately-pop
Expand Down
47 changes: 44 additions & 3 deletions Markdown/tests/syntax_test_markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -3178,8 +3178,9 @@ bar | baz
| f\|oo |
| ------ |
| b `|` az |
| ^^^ meta.table markup.raw.inline - meta.table.header-separator
| ^ meta.table punctuation.separator.table-cell
|^^^^^^^^^^^ meta.table.markdown-gfm - markup.raw
| ^ punctuation.separator.table-cell.markdown
| ^ punctuation.separator.table-cell.markdown
| b **|** im |
| <- meta.table punctuation.separator.table-cell
| ^^^^^ meta.table markup.bold - punctuation.separator.table-cell
Expand All @@ -3194,6 +3195,46 @@ test
> bar
| <- markup.quote punctuation.definition.blockquote - meta.table

| c1 | c2 | c3 | c4 | c5 | c6 | c7
| --- | --- | --- | --- | --- | --- | ---
| ` ` | ` me ` | `` ` `` | ` `` ` | ``foo`bar`` | ```foo`` | ``foo```
| <- meta.table.markdown-gfm punctuation.separator.table-cell.markdown
| ^^^ meta.table.markdown-gfm markup.raw.inline.markdown
| ^ punctuation.definition.raw.begin.markdown
| ^ punctuation.definition.raw.end.markdown
| ^ punctuation.separator.table-cell
| ^^^^^^ markup.raw.inline.markdown
| ^ punctuation.definition.raw.begin.markdown
| ^ punctuation.definition.raw.end.markdown
| ^^^^^^^ markup.raw.inline.markdown
| ^^ punctuation.definition.raw.begin.markdown
| ^^^ - punctuation
| ^^ punctuation.definition.raw.end.markdown
| ^ punctuation.separator.table-cell
| ^^^^^^ markup.raw.inline.markdown
| ^ punctuation.definition.raw.begin.markdown
| ^^^^ - punctuation
| ^ punctuation.definition.raw.end.markdown
| ^ punctuation.separator.table-cell
| ^^^^^^^^^^^ markup.raw.inline.markdown
| ^^ punctuation.definition.raw.begin.markdown
| ^^^^^^^ - punctuation
| ^^ punctuation.definition.raw.end.markdown
| ^ punctuation.separator.table-cell
| ^^^^^^^^ - markup.raw

| c1 | c2 |
| --- | --- |
| ```` ``` ```` | `````` ````` `````` |
| ^^^^^^^^^^^^^ markup.raw.inline.markdown
| ^^^^ punctuation.definition.raw.begin.markdown
| ^^^^^ - punctuation
| ^^^^ punctuation.definition.raw.end.markdown
| ^^^^^^^^^^^^^^^^^^^ markup.raw.inline.markdown
| ^^^^^^ punctuation.definition.raw.begin.markdown
| ^^^^^^^ - punctuation
| ^^^^^^ punctuation.definition.raw.end.markdown

`|` this `|` example `|` is not a table `|`
| ^ punctuation.definition.raw.end - meta.table
| nor is this | because it is not at block level, it immediately follows a paragraph |
Expand Down Expand Up @@ -3248,7 +3289,7 @@ not a table |
| ^ punctuation.separator.table-cell
| ^ punctuation.separator.table-cell
|`test | me |
|^ invalid.deprecated.unescaped-backticks
|^^^^^^^^^^^^^ meta.table.markdown-gfm - markup.raw
| ^ punctuation.separator.table-cell

| table | followed by
Expand Down
Loading