MarkdigToc is a extension for Markdig to generate table of content by parse [toc] in markdown document.
Currently just for render to html.
Use with default options:
var pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions() // Add most of all advanced extensions
.UseTableOfContent() //Add MarkdigToc extension
.Build();
var result=Markdown.ToHtml(@"
[TOC]
# t1
## t1.1
### t1.1.1
### t1.1.2
## t1.2
");
Console.WriteLine(result);Use with custom options:
var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions()
.UseTableOfContent(
tocAction: opt=>{ // toc options },
idAction: opt=>{ // auto id options }
).Build();
// ...Code copied from AutoIdentifierExtension, then added some code and options.
NOTICE: When use
UseTableOfContent, it will auto replace (AutoIdentifierExtension) or add (CustomAutoIdExtension).
-
AutoIdentifierOptionsOptions:Enum: default AutoIdentifierOptions.DefaultOption from
AutoIdentifierExtension:- None
- AutoLink
- AllowOnlyAscii
- Default
- Github
-
GenerateHeadingId?HeadingIdGenerator:Delegate: defalut nullDelegate for handle custom heading id creation.
Arguments:
-
level:
intThe level of current heading, usually be count of char #.
-
content:
stringThe content of current heading.
-
id:
string?Not null if already defined id in markdown strings.
e.g. title-id for
# title {#title-id}NOTICE: In order to parse attributes, need
UseGenericAttributesextension after all of other extensions which you want parse.
-
-
IsUlOnlyContainLi:bool: default trueAccording to webhint ,
ulandolmust only directly containli,scriptortemplateelements.Set false to mix
ulandlilike others do (generate less code). -
TitleAsConainerHeader:bool: default falsePut the tile in
ContainerTagnot inside theTocTagNOTICE: working only
ContainerTagis not null.
-
ContainerTag:string? : default nullIf this is not null, the toc will put in a element use
ContainerTag. -
ContainerId:string? : default nullId attribute for
ContainerTag. -
ContainerClass:string? : default nullClass attribute for
ContainerTag. e.g."class1 class2"
-
TocTag:string : default navTag name for toc element.
-
TocId:string? : default nullId attribute for
TocTag. -
TocClass:string? : default nullClass attribute for
TocTag. e.g."class1 class2"
NOTICE: I also parse toc title and use it's attributes from markdown document , but that is not a regular syntax, you should know that.
-
OverrideTitle:string? : default nullOverride toc title , ignore defined in markdown document.
-
TitleTag:string : default pTag name for toc title element.
-
TitleId:string? : default nullId attribute for
TitleTag. -
TitleClass:string? : default nullClass attribute for
TitleTag. e.g."class1 class2"
-
ulClass:string? : default pClass attribute for
ulelement. -
liClass:string? : default nullClass attribute for
lielement. -
aClass:string? : default nullClass attribute for
aelement.
Markdown document:
[TOC]
##### t5
#### t4
### t3
## t2
# t1
## t2
### t3
#### t4
##### t5IsUlOnlyContainLi=true :
●
○
■
■
■ t5
■ t4
■ t3
○ t2
● t1
○ t2
■ t3
■ t4
■ t5
IsUlOnlyContainLi=false :
■ t5
■ t4
■ t3
○ t2
● t1
○ t2
■ t3
■ t4
■ t5
Thanks Atrejoe for signed version