From a35380d6f0ff65f7c35345baafcf1c3f8a378d38 Mon Sep 17 00:00:00 2001 From: aaronchucarroll <120818400+aaronchucarroll@users.noreply.github.com> Date: Fri, 12 Jul 2024 00:51:37 -0400 Subject: [PATCH] Adds support for Github-style fenced math blocks in markdown editor and preview (#213750) * added support for markdown fenced math blocks * original markdownEngine.ts * Add fenced math block rendering to markdown-math * Update dependencies * custom parser for fenced math blocks * custom parser for fenced math blocks * reverted changes to extension.ts * reverted all changes from prior implementations * proper fence grammar implementation for math --------- Co-authored-by: Matt Bierner --- .../src/markdownEngine.ts | 2 +- extensions/markdown-math/package.json | 10 +++++++ extensions/markdown-math/src/extension.ts | 2 +- .../syntaxes/md-math-block.tmLanguage.json | 2 +- .../syntaxes/md-math-fence.tmLanguage.json | 28 +++++++++++++++++++ 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 extensions/markdown-math/syntaxes/md-math-fence.tmLanguage.json diff --git a/extensions/markdown-language-features/src/markdownEngine.ts b/extensions/markdown-language-features/src/markdownEngine.ts index 103cbc191e4..fb906f63453 100644 --- a/extensions/markdown-language-features/src/markdownEngine.ts +++ b/extensions/markdown-language-features/src/markdownEngine.ts @@ -441,4 +441,4 @@ function normalizeHighlightLang(lang: string | undefined) { default: return lang; } -} +} \ No newline at end of file diff --git a/extensions/markdown-math/package.json b/extensions/markdown-math/package.json index ef56c5dc474..9669efc2435 100644 --- a/extensions/markdown-math/package.json +++ b/extensions/markdown-math/package.json @@ -56,6 +56,16 @@ "meta.embedded.math.markdown": "latex", "punctuation.definition.math.end.markdown": "latex" } + }, + { + "scopeName": "markdown.math.codeblock", + "path": "./syntaxes/md-math-fence.tmLanguage.json", + "injectTo": [ + "text.html.markdown" + ], + "embeddedLanguages": { + "meta.embedded.math.markdown": "latex" + } } ], "notebookRenderer": [ diff --git a/extensions/markdown-math/src/extension.ts b/extensions/markdown-math/src/extension.ts index 4e462e444be..6491b0c1459 100644 --- a/extensions/markdown-math/src/extension.ts +++ b/extensions/markdown-math/src/extension.ts @@ -43,4 +43,4 @@ export function activate(context: vscode.ExtensionContext) { return md; } }; -} +} \ No newline at end of file diff --git a/extensions/markdown-math/syntaxes/md-math-block.tmLanguage.json b/extensions/markdown-math/syntaxes/md-math-block.tmLanguage.json index 43fd1bda5db..543568bf83e 100644 --- a/extensions/markdown-math/syntaxes/md-math-block.tmLanguage.json +++ b/extensions/markdown-math/syntaxes/md-math-block.tmLanguage.json @@ -82,4 +82,4 @@ } }, "scopeName": "markdown.math.block" -} +} \ No newline at end of file diff --git a/extensions/markdown-math/syntaxes/md-math-fence.tmLanguage.json b/extensions/markdown-math/syntaxes/md-math-fence.tmLanguage.json new file mode 100644 index 00000000000..556c579d3e7 --- /dev/null +++ b/extensions/markdown-math/syntaxes/md-math-fence.tmLanguage.json @@ -0,0 +1,28 @@ +{ + "fileTypes": [], + "injectionSelector": "L:markup.fenced_code.block.markdown", + "patterns": [ + { + "include": "#math-code-block" + } + ], + "repository": { + "math-code-block": { + "begin": "(?<=[`~])math(\\s+[^`~]*)?$", + "end": "(^|\\G)(?=\\s*[`~]{3,}\\s*$)", + "patterns": [ + { + "begin": "(^|\\G)(\\s*)(.*)", + "while": "(^|\\G)(?!\\s*([`~]{3,})\\s*$)", + "contentName": "meta.embedded.math.markdown", + "patterns": [ + { + "include": "text.html.markdown.math#math" + } + ] + } + ] + } + }, + "scopeName": "markdown.math.codeblock" +}