From 411bd6d2d98e355bd7aa487809165ad4b00b113a Mon Sep 17 00:00:00 2001 From: Yufei Huang Date: Thu, 18 May 2023 08:02:35 +0800 Subject: [PATCH] fix: allow dash as tag name in markdig code snippet syntax (#8783) --- .../CodeSnippet/CodeSnippetExtractor.cs | 2 +- .../CodeSnippetTest.cs | 47 ++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DocAsCode.MarkdigEngine.Extensions/CodeSnippet/CodeSnippetExtractor.cs b/src/Microsoft.DocAsCode.MarkdigEngine.Extensions/CodeSnippet/CodeSnippetExtractor.cs index 4aba3c6aef7..db3f90cf821 100644 --- a/src/Microsoft.DocAsCode.MarkdigEngine.Extensions/CodeSnippet/CodeSnippetExtractor.cs +++ b/src/Microsoft.DocAsCode.MarkdigEngine.Extensions/CodeSnippet/CodeSnippetExtractor.cs @@ -9,7 +9,7 @@ namespace Microsoft.DocAsCode.MarkdigEngine.Extensions; public class CodeSnippetExtractor { - private static readonly Regex TagnameFormat = new(@"^[\w\.]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase); + private static readonly Regex TagnameFormat = new(@"^[\w\.-]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly string StartLineTemplate; private readonly string EndLineTemplate; private readonly bool IsEndLineContainsTagName; diff --git a/test/Microsoft.DocAsCode.MarkdigEngine.Extensions.Tests/CodeSnippetTest.cs b/test/Microsoft.DocAsCode.MarkdigEngine.Extensions.Tests/CodeSnippetTest.cs index 126eb2e098f..c0dbbceeb39 100644 --- a/test/Microsoft.DocAsCode.MarkdigEngine.Extensions.Tests/CodeSnippetTest.cs +++ b/test/Microsoft.DocAsCode.MarkdigEngine.Extensions.Tests/CodeSnippetTest.cs @@ -292,7 +292,7 @@ public void TestDfmFencesBlockLevel() } [Theory] - [Trait("Related", "DfmMarkdown")] + [Trait("Related", "DfmMarkdown")] #region Inline Data [InlineData(@"[!code-csharp[Main](Program.cs)]", @"
namespace ConsoleApplication1
 {
@@ -609,6 +609,51 @@ public void TestDfmFencesBlockLevelWithWhitespaceLeading()
         });
     }
 
+    [Fact]
+    public void Issue8777()
+    {
+        TestUtility.VerifyMarkup(
+            """
+            [!code-csharp[Main](Greet.cs?name=hello-world-message)]
+            """,
+            """
+            

+            namespace HelloWorld
+            {
+                public class Greet
+                {
+                    public string Who { get; private set; }
+            
+                    public Greet(string who)
+                    {
+                        Who = who;
+                    }
+                }
+            }
+ """, + files: new Dictionary + { + { + "Greet.cs", """ + #region hello-world-message + namespace HelloWorld + { + public class Greet + { + public string Who { get; private set; } + + public Greet(string who) + { + Who = who; + } + } + } + #endregion + """ + }, + }); + } + [Fact] [Trait("Related", "DfmMarkdown")] public void TestDfmFencesBlockLevelWithWorkingFolder()