From 872e4e674ff0ac9b1fb10c11993b7aff7f586bc9 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 11 Jan 2024 18:09:55 +0900 Subject: [PATCH 1/5] feat(theme-common): fix missing code block MagicComments style in Visual Basic (.NET) 16.x --- .../docusaurus-theme-common/src/utils/codeBlockUtils.ts | 4 +++- website/_dogfooding/_pages tests/code-block-tests.mdx | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts index 16a45f856d84..8a6e16f190b8 100644 --- a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts @@ -28,6 +28,7 @@ const commentPatterns = { wasm: {start: '\\;\\;', end: ''}, tex: {start: '%', end: ''}, vb: {start: "['‘’]", end: ''}, + vbnet: {start: "_\s*['‘’]", end: ''}, // Visual Studio 2019 or later rem: {start: '[Rr][Ee][Mm]\\b', end: ''}, f90: {start: '!', end: ''}, // Free format only ml: {start: '\\(\\*', end: '\\*\\)'}, @@ -113,10 +114,11 @@ function getAllMagicCommentDirectiveStyles( return getCommentPattern(['wasm'], magicCommentDirectives); case 'vb': - case 'vbnet': case 'vba': case 'visual-basic': return getCommentPattern(['vb', 'rem'], magicCommentDirectives); + case 'vbnet': + return getCommentPattern(['vbnet', 'rem'], magicCommentDirectives); case 'batch': return getCommentPattern(['rem'], magicCommentDirectives); diff --git a/website/_dogfooding/_pages tests/code-block-tests.mdx b/website/_dogfooding/_pages tests/code-block-tests.mdx index 27e751cfa6cc..00cdd899295f 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -385,15 +385,15 @@ y = times2(x); ``` ```vbnet title="vbnet.vb" +' highlight-next-line Dim languages As New Set(Of String) From { - ' highlight-start "C#", "Visual Basic", + _ ' highlight-start "F#", - ' highlight-end "PowerShell", - ' highlight-next-line "TypeScript" + _' highlight-end } ``` From 111f34ec7a8b25ec872db5b02da04317fe942b27 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 11 Jan 2024 18:53:48 +0900 Subject: [PATCH 2/5] Add VBA code example --- .../_pages tests/code-block-tests.mdx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/website/_dogfooding/_pages tests/code-block-tests.mdx b/website/_dogfooding/_pages tests/code-block-tests.mdx index 00cdd899295f..cc1cdcf021c5 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -384,6 +384,25 @@ y = times2(x); \end{document} ``` +```vba title="vba.vb" +Function Factorial(ByVal n As Long) As Long + If n < 0 Then + Err.Raise 5 ' Invalid argument + End If + 'highlight-next-line + Factorial = 1 ' return value + If n < 2 Then + Exit Function + End If + Dim i As Long + ' highlight-start + For i = 2 To n + Factorial = Factorial * i + Next + ' highlight-end +End Function +``` + ```vbnet title="vbnet.vb" ' highlight-next-line Dim languages As New Set(Of String) From { From afde460fe681ae83286ec604ed6375f39da0cb0a Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 11 Jan 2024 23:26:48 +0900 Subject: [PATCH 3/5] Fix regexp --- packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts index 8a6e16f190b8..3d545655f673 100644 --- a/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/codeBlockUtils.ts @@ -28,7 +28,7 @@ const commentPatterns = { wasm: {start: '\\;\\;', end: ''}, tex: {start: '%', end: ''}, vb: {start: "['‘’]", end: ''}, - vbnet: {start: "_\s*['‘’]", end: ''}, // Visual Studio 2019 or later + vbnet: {start: "(?:_\\s*)?['‘’]", end: ''}, // Visual Studio 2019 or later rem: {start: '[Rr][Ee][Mm]\\b', end: ''}, f90: {start: '!', end: ''}, // Free format only ml: {start: '\\(\\*', end: '\\*\\)'}, From 10232eb1c494e6a2d1c0b6cafbf0055024e67967 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 11 Jan 2024 23:34:23 +0900 Subject: [PATCH 4/5] Shorten test case in code block test --- website/_dogfooding/_pages tests/code-block-tests.mdx | 3 --- 1 file changed, 3 deletions(-) diff --git a/website/_dogfooding/_pages tests/code-block-tests.mdx b/website/_dogfooding/_pages tests/code-block-tests.mdx index cc1cdcf021c5..1d1a6ecd722f 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -391,9 +391,6 @@ Function Factorial(ByVal n As Long) As Long End If 'highlight-next-line Factorial = 1 ' return value - If n < 2 Then - Exit Function - End If Dim i As Long ' highlight-start For i = 2 To n From 4bb3c193e18b1fe7a721027f0c17aa92d2d64a71 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 11 Jan 2024 23:36:43 +0900 Subject: [PATCH 5/5] Fix code in test case --- 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 1d1a6ecd722f..6c294b11c38a 100644 --- a/website/_dogfooding/_pages tests/code-block-tests.mdx +++ b/website/_dogfooding/_pages tests/code-block-tests.mdx @@ -402,7 +402,7 @@ End Function ```vbnet title="vbnet.vb" ' highlight-next-line -Dim languages As New Set(Of String) From { +Dim languages As New HashSet(Of String) From { "C#", "Visual Basic", _ ' highlight-start