From 43c07c71539fa911d06f44f62b7dcdc06d7bc816 Mon Sep 17 00:00:00 2001 From: JJ Style Date: Fri, 12 May 2023 13:49:56 +0100 Subject: [PATCH 1/3] feat(theme-common): code block MagicComments support for matlab --- .../src/utils/codeBlockUtils.ts | 8 ++++++-- .../_dogfooding/_pages tests/code-block-tests.mdx | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts index 1b3badeb04aa..6518b208a7d4 100644 --- a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts @@ -21,6 +21,7 @@ const commentPatterns = { html: {start: ''}, lua: {start: '--', end: ''}, wasm: {start: '\\;\\;', end: ''}, + matlab: {start: '%', end: ''}, }; type CommentType = keyof typeof commentPatterns; @@ -85,6 +86,9 @@ function getAllMagicCommentDirectiveStyles( // Text uses HTML, front matter uses bash return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives); + case 'matlab': + return getCommentPattern(['matlab'], magicCommentDirectives); + case 'lua': case 'haskell': case 'sql': @@ -94,10 +98,10 @@ function getAllMagicCommentDirectiveStyles( return getCommentPattern(['wasm'], magicCommentDirectives); default: - // All comment types except lua and wasm + // All comment types except lua, wasm and matlab return getCommentPattern( Object.keys(commentPatterns).filter( - (pattern) => !['lua', 'wasm'].includes(pattern), + (pattern) => !['lua', 'wasm', 'matlab'].includes(pattern), ) as CommentType[], magicCommentDirectives, ); diff --git a/website/_dogfooding/_pages tests/code-block-tests.mdx b/website/_dogfooding/_pages tests/code-block-tests.mdx index 8248d0dace65..cc8e9897a0bc 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -322,3 +322,15 @@ WHERE customer_id IN ( WHERE country = 'USA' ) ``` + +```matlab title="matlab.m" +% highlight-start +function result = times2(n) + result = n * 2; +end +% highlight-end + +x = 10; +% highlight-next-line +y = times2(x); +``` From f7954a0bf483b60c9dbf30e7a05937325e544a8f Mon Sep 17 00:00:00 2001 From: JJ Style Date: Tue, 16 May 2023 21:51:30 +0100 Subject: [PATCH 2/3] feat(theme-common): change matlab magic comment block to tex --- .../src/utils/codeBlockUtils.ts | 9 ++++++--- .../_dogfooding/_pages tests/code-block-tests.mdx | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts index 6518b208a7d4..0ff41b64ba78 100644 --- a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts @@ -21,7 +21,7 @@ const commentPatterns = { html: {start: ''}, lua: {start: '--', end: ''}, wasm: {start: '\\;\\;', end: ''}, - matlab: {start: '%', end: ''}, + tex: {start: '%', end: ''}, }; type CommentType = keyof typeof commentPatterns; @@ -86,8 +86,10 @@ function getAllMagicCommentDirectiveStyles( // Text uses HTML, front matter uses bash return getCommentPattern(['html', 'jsx', 'bash'], magicCommentDirectives); + case 'tex': + case 'latex': case 'matlab': - return getCommentPattern(['matlab'], magicCommentDirectives); + return getCommentPattern(['tex'], magicCommentDirectives); case 'lua': case 'haskell': @@ -101,7 +103,8 @@ function getAllMagicCommentDirectiveStyles( // All comment types except lua, wasm and matlab return getCommentPattern( Object.keys(commentPatterns).filter( - (pattern) => !['lua', 'wasm', 'matlab'].includes(pattern), + (pattern) => + !['lua', 'wasm', 'tex', 'latex', 'matlab'].includes(pattern), ) as CommentType[], magicCommentDirectives, ); diff --git a/website/_dogfooding/_pages tests/code-block-tests.mdx b/website/_dogfooding/_pages tests/code-block-tests.mdx index cc8e9897a0bc..25c08d521fec 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -334,3 +334,17 @@ x = 10; % highlight-next-line y = times2(x); ``` + +```latex title="latex.tex +\begin{document} + \section{Triangles} + % highlight-next-line + \subsection{Pythagoras' Theorem} + Pythagoras's theorem is: + % highlight-start + \begin{equation} + c^2 = a^2 + b^2 + \end{equation} + % highlight-end +\end{document} +``` From 5f0d777b12fa57fa54bfdf9792f14baca1e51054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Tue, 30 May 2023 15:04:12 +0200 Subject: [PATCH 3/3] Update website/_dogfooding/_pages tests/code-block-tests.mdx --- website/_dogfooding/_pages tests/code-block-tests.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/_dogfooding/_pages tests/code-block-tests.mdx b/website/_dogfooding/_pages tests/code-block-tests.mdx index 25c08d521fec..22c9697465fa 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -335,7 +335,7 @@ x = 10; y = times2(x); ``` -```latex title="latex.tex +```latex title="latex.tex" \begin{document} \section{Triangles} % highlight-next-line