From 0f0b14e397c882a40ac3299e30ffce2ffb70037e Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 27 Apr 2024 10:32:47 +0200 Subject: [PATCH 1/2] Syntax: Improve codespans in tables --- messages/next.md | 14 ++++++++ syntaxes/Markdown.sublime-syntax | 38 +++++++++++++++++++-- tests/syntax_test_markdown.md | 57 +++++++++++++++++++++++++++----- 3 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 messages/next.md diff --git a/messages/next.md b/messages/next.md new file mode 100644 index 00000000..eb2fb34e --- /dev/null +++ b/messages/next.md @@ -0,0 +1,14 @@ +# MarkdownEditing {version} Changelog + +Your _MarkdownEditing_ plugin is updated. Enjoy new version. For any type of +feedback you can use [GitHub issues][issues]. + +## Bug Fixes + +- improve code span patterns in table cells + +## New Features + +## Changes + +[issues]: https://github.com/SublimeText-Markdown/MarkdownEditing/issues diff --git a/syntaxes/Markdown.sublime-syntax b/syntaxes/Markdown.sublime-syntax index f043fcfd..852588a2 100644 --- a/syntaxes/Markdown.sublime-syntax +++ b/syntaxes/Markdown.sublime-syntax @@ -9,7 +9,7 @@ # # The scope suffix should indicate which flavor of Markdown the feature came from, # to help make this syntax definition easier to maintain. -name: Markdown (MDE) +name: Markdown scope: text.html.markdown hidden: true @@ -108,6 +108,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]*) @@ -2920,11 +2926,39 @@ contexts: - include: markups table-cell-code-spans: - - match: (`+)[^`|]+(\1) + # 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 diff --git a/tests/syntax_test_markdown.md b/tests/syntax_test_markdown.md index d9165a20..991fca42 100644 --- a/tests/syntax_test_markdown.md +++ b/tests/syntax_test_markdown.md @@ -2938,6 +2938,54 @@ 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 +| table with | `multiple` code `spans`) | +| <- punctuation.separator.table-cell +| ^ punctuation.separator.table-cell +| ^^^^^^^^^^ markup.raw.inline +| ^^^^^^ - markup.raw.inline +| ^^^^^^^ markup.raw.inline + + + `|` 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 | @@ -2994,15 +3042,6 @@ not a table | |`test | me | |^^^^^^^^^^^^^ meta.table.markdown-gfm - markup.raw | ^ punctuation.separator.table-cell -| ` ` | ` me ` | -| <- 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 | table | followed by paragraph From 5ca3c4bfcf247aa127946954996d8433364a7999 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 27 Apr 2024 10:45:51 +0200 Subject: [PATCH 2/2] Syntax: accept new LaTeX scopes required for https://github.com/sublimehq/Packages/pull/3575 --- tests/syntax_test_markdown.md | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/syntax_test_markdown.md b/tests/syntax_test_markdown.md index 991fca42..0690b940 100644 --- a/tests/syntax_test_markdown.md +++ b/tests/syntax_test_markdown.md @@ -8215,24 +8215,24 @@ $$ |^ punctuation.definition.math.begin.markdown | ^ - punctuation foo = 1 + 2 * \sqrt{a^2+b^2} -| <- markup.math.block.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex variable.other.math.tex -|^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.math.block.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex -| ^ keyword.operator.math.tex -| ^ constant.numeric.math.tex -| ^ keyword.operator.math.tex -| ^ constant.numeric.math.tex -| ^ keyword.operator.math.tex -| ^^^^^ support.function.math.tex -| ^^^^^^^^^ meta.group.brace.latex -| ^ punctuation.definition.group.brace.begin.latex -| ^ variable.other.math.tex -| ^ keyword.operator.math.tex -| ^ constant.numeric.math.tex -| ^ keyword.operator.math.tex -| ^ variable.other.math.tex -| ^ keyword.operator.math.tex -| ^ constant.numeric.math.tex -| ^ punctuation.definition.group.brace.end.latex +| <- markup.math.block.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar variable.other.math +|^^^^^^^^^^^^^^^^^^^^^^^^^^^^ markup.math.block.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar +| ^ keyword.operator +| ^ constant.numeric +| ^ keyword.operator +| ^ constant.numeric +| ^ keyword.operator +| ^^^^^ support.function.math +| ^^^^^^^^^ meta.group.brace +| ^ punctuation.definition.group.brace.begin +| ^ variable.other.math +| ^ keyword.operator, punctuation.separator.superscript +| ^ constant.numeric +| ^ keyword.operator +| ^ variable.other.math +| ^ keyword.operator, punctuation.separator.superscript +| ^ constant.numeric +| ^ punctuation.definition.group.brace.end $$ | <- markup.math.block.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex punctuation.definition.math.end.markdown |^ markup.math.block.markdown text.tex.latex.embedded.markdown meta.environment.math.block.dollar.latex punctuation.definition.math.end.markdown