From 818751e3371a77fcebd26abfff841634997c47a1 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Thu, 8 Feb 2024 19:28:31 +0100 Subject: [PATCH] [Markdown] Add support for LaTeX in fenced code blocks (#3916) Resolves #3915 --- .../Code Block Syntaxes.sublime-completions | 14 +++++++++++ Markdown/Markdown.sublime-syntax | 23 +++++++++++++++++++ Markdown/tests/syntax_test_markdown.md | 12 ++++++++++ 3 files changed, 49 insertions(+) diff --git a/Markdown/Code Block Syntaxes.sublime-completions b/Markdown/Code Block Syntaxes.sublime-completions index 143ac61b41..084416152e 100644 --- a/Markdown/Code Block Syntaxes.sublime-completions +++ b/Markdown/Code Block Syntaxes.sublime-completions @@ -280,6 +280,20 @@ "details": "Specifies JSON with Comments code highlighting" }, + // LaTeX + { + "trigger": "tex", + "annotation": "TeX", + "kind": ["markup", "s", "Syntax"], + "details": "Specifies TeX code highlighting" + }, + { + "trigger": "latex", + "annotation": "LaTeX", + "kind": ["markup", "s", "Syntax"], + "details": "Specifies LaTeX code highlighting" + }, + // Lisp { "trigger": "lisp", diff --git a/Markdown/Markdown.sublime-syntax b/Markdown/Markdown.sublime-syntax index b3f7395564..fee152ec7c 100644 --- a/Markdown/Markdown.sublime-syntax +++ b/Markdown/Markdown.sublime-syntax @@ -1105,6 +1105,7 @@ contexts: - include: fenced-jsonc - include: fenced-jspx - include: fenced-jsx + - include: fenced-latex - include: fenced-lisp - include: fenced-lua - include: fenced-makefile @@ -1568,6 +1569,28 @@ contexts: 1: punctuation.definition.raw.code-fence.end.markdown 2: meta.fold.code-fence.end.markdown + fenced-latex: + - match: |- + (?x) + {{fenced_code_block_start}} + (?i:\s*(latex|tex)) + {{fenced_code_block_trailing_infostring_characters}} + captures: + 0: meta.code-fence.definition.begin.latex.markdown-gfm + 2: punctuation.definition.raw.code-fence.begin.markdown + 5: constant.other.language-name.markdown + 6: comment.line.infostring.markdown + 7: meta.fold.code-fence.begin.markdown + embed: scope:text.tex.latex + embed_scope: + markup.raw.code-fence.latex.markdown-gfm + text.tex.latex + escape: '{{fenced_code_block_escape}}' + escape_captures: + 0: meta.code-fence.definition.end.latex.markdown-gfm + 1: punctuation.definition.raw.code-fence.end.markdown + 2: meta.fold.code-fence.end.markdown + fenced-lisp: - match: |- (?x) diff --git a/Markdown/tests/syntax_test_markdown.md b/Markdown/tests/syntax_test_markdown.md index 63d2eede3e..09279727cb 100644 --- a/Markdown/tests/syntax_test_markdown.md +++ b/Markdown/tests/syntax_test_markdown.md @@ -1911,6 +1911,18 @@ for (var i = 0; i < 10; i++) { |^^ meta.code-fence.definition.end.jsx.markdown-gfm punctuation.definition.raw.code-fence.end.markdown | ^ meta.code-fence.definition.end.jsx.markdown-gfm meta.fold.code-fence.end - punctuation +```latex +| <- meta.code-fence.definition.begin.latex.markdown-gfm punctuation.definition.raw.code-fence.begin.markdown +|^^ meta.code-fence.definition.begin.latex.markdown-gfm punctuation.definition.raw.code-fence.begin.markdown +| ^^^^^ meta.code-fence.definition.begin.latex.markdown-gfm constant.other.language-name.markdown +| ^ meta.code-fence.definition.begin.latex.markdown-gfm meta.fold.code-fence.begin.markdown - punctuation + +| <- markup.raw.code-fence.latex.markdown-gfm text.tex.latex +``` +| <- meta.code-fence.definition.end.latex.markdown-gfm punctuation.definition.raw.code-fence.end.markdown +|^^ meta.code-fence.definition.end.latex.markdown-gfm punctuation.definition.raw.code-fence.end.markdown +| ^ meta.code-fence.definition.end.latex.markdown-gfm meta.fold.code-fence.end.markdown - punctuation + ```lisp |^^^^^^ meta.code-fence.definition.begin - meta.fold | ^ meta.code-fence.definition.begin meta.fold.code-fence.begin