Skip to content

Commit

Permalink
fix: allow dash as tag name in markdig code snippet syntax (#8783)
Browse files Browse the repository at this point in the history
  • Loading branch information
yufeih authored May 18, 2023
1 parent 185afe1 commit 411bd6d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void TestDfmFencesBlockLevel()
}

[Theory]
[Trait("Related", "DfmMarkdown")]
[Trait("Related", "DfmMarkdown")]
#region Inline Data
[InlineData(@"[!code-csharp[Main](Program.cs)]", @"<pre><code class=""lang-csharp"" name=""Main"">namespace ConsoleApplication1
{
Expand Down Expand Up @@ -609,6 +609,51 @@ public void TestDfmFencesBlockLevelWithWhitespaceLeading()
});
}

[Fact]
public void Issue8777()
{
TestUtility.VerifyMarkup(
"""
[!code-csharp[Main](Greet.cs?name=hello-world-message)]
""",
"""
<pre><code class="lang-csharp" name="Main">
namespace HelloWorld
{
public class Greet
{
public string Who { get; private set; }
public Greet(string who)
{
Who = who;
}
}
}</code></pre>
""",
files: new Dictionary<string, string>
{
{
"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()
Expand Down

0 comments on commit 411bd6d

Please sign in to comment.