Add 'search' HTML tag support

This commit is contained in:
Miha Zupan
2025-04-15 04:31:13 +02:00
parent 61e9be290b
commit b15cf582a5
2 changed files with 38 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
using Markdig.Syntax;
namespace Markdig.Tests;
public class TestHtmlCodeBlocks
{
// Start condition: line begins with the string < or </ followed by one of the strings (case-insensitive)
// {list of all tags}, followed by a space, a tab, the end of the line, the string >, or the string />.
public static string[] KnownSimpleHtmlTags =>
[
"address", "article", "aside", "base", "basefont", "blockquote", "body", "caption", "center", "col", "colgroup", "dd", "details",
"dialog", "dir", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "frame", "frameset",
"h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hr", "html", "iframe", "legend", "li", "link",
"main", "menu", "menuitem", "nav", "noframes", "ol", "optgroup", "option", "p", "param",
"search", "section", "summary", "table", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "track", "ul",
];
[Theory]
[TestCaseSource(nameof(KnownSimpleHtmlTags))]
public void TestKnownTags(string tag)
{
MarkdownDocument document = Markdown.Parse(
$"""
Hello
<{tag} />
World
""".ReplaceLineEndings("\n"));
HtmlBlock[] htmlBlocks = document.Descendants<HtmlBlock>().ToArray();
Assert.AreEqual(1, htmlBlocks.Length);
Assert.AreEqual(7, htmlBlocks[0].Span.Start);
Assert.AreEqual(10 + tag.Length, htmlBlocks[0].Span.Length);
}
}

View File

@@ -295,7 +295,7 @@ public class HtmlBlockParser : BlockParser
return BlockState.Continue;
}
private static readonly CompactPrefixTree<int> HtmlTags = new(66, 94, 83)
private static readonly CompactPrefixTree<int> HtmlTags = new(67, 96, 86)
{
{ "address", 0 },
{ "article", 1 },
@@ -362,6 +362,7 @@ public class HtmlBlockParser : BlockParser
{ "title", 62 },
{ "tr", 63 },
{ "track", 64 },
{ "ul", 65 }
{ "ul", 65 },
{ "search", 66 },
};
}