xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.41k stars 456 forks source link

Is there any way to get AutoIdentifiers list? #796

Closed Nyazira closed 6 months ago

Nyazira commented 6 months ago

If markdown is as follows:

# 1 你好,世界
## 1.1 你好,世界
# 1 Hello World
## 2 Hello World

then it generates the following code:

<h1 id="section">1 你好,世界</h1>
<h2 id="section-1">1.1 你好,世界</h2>
<h1 id="hello-world">1 Hello World</h1>
<h2 id="hello-world-1">2 Hello World</h2>

Since markdown's title contains both Chinese and English characters, I can't predict what kind of Identifier the title will generate. Is there any way to get a list of identifiers? So I can generate a directory from the list.

MihaZupan commented 6 months ago

Try

MarkdownDocument document = Markdown.Parse(content, pipeline);

foreach (HeadingBlock heading in document.Descendants<HeadingBlock>())
{
    Console.WriteLine(heading.GetAttributes().Id);
}

string html = document.ToHtml(pipeline);
Nyazira commented 6 months ago

Try

MarkdownDocument document = Markdown.Parse(content, pipeline);

foreach (HeadingBlock heading in document.Descendants<HeadingBlock>())
{
    Console.WriteLine(heading.GetAttributes().Id);
}

string html = document.ToHtml(pipeline);

Thank you,it works!