Do we have header level start setting ? #323

Closed
opened 2026-01-29 14:33:48 +00:00 by claunia · 3 comments
Owner

Originally created by @gr8tushar on GitHub (Sep 11, 2019).

Hi,
Do you have something like headerLevelStart as it is in showdownjs ?
Basically it allows you to define from where do you want to start the headers?
e.g. If I set the headerLevelStart as 3,

foo

will be parsed as

foo

Originally created by @gr8tushar on GitHub (Sep 11, 2019). Hi, Do you have something like headerLevelStart as it is in showdownjs ? Basically it allows you to define from where do you want to start the headers? e.g. If I set the headerLevelStart as 3, # foo will be parsed as <h3>foo</h3>
claunia added the question label 2026-01-29 14:33:48 +00:00
Author
Owner

@MihaZupan commented on GitHub (Sep 11, 2019):

You can modify the heading level after the document is parsed like so

foreach (var heading in document.Descendants<HeadingBlock>())
{
    heading.Level += 2;
}
@MihaZupan commented on GitHub (Sep 11, 2019): You can modify the heading level after the document is parsed like so ```c# foreach (var heading in document.Descendants<HeadingBlock>()) { heading.Level += 2; } ```
Author
Owner

@gr8tushar commented on GitHub (Sep 12, 2019):

Hi @MihaZupan,
Thanks for the answer.
I want to read mark down content from DB and render it as HTML. Since my DB already has data with content having h1 tags in it, I would want to reduce them to h2 and so forth, because in my site, I would like to use h1 for Page Title.

So in net shell, after reading the content from DB, i'll have to increase the heading level and then convert it into HTML. Right ?

Won't it be good if we have some sort of configuration in the converter itself ?

@gr8tushar commented on GitHub (Sep 12, 2019): Hi @MihaZupan, Thanks for the answer. I want to read mark down content from DB and render it as HTML. Since my DB already has data with content having h1 tags in it, I would want to reduce them to h2 and so forth, because in my site, I would like to use h1 for Page Title. So in net shell, after reading the content from DB, i'll have to increase the heading level and then convert it into HTML. Right ? Won't it be good if we have some sort of configuration in the converter itself ?
Author
Owner

@MihaZupan commented on GitHub (Sep 14, 2019):

string html = Markdown.ToHtml(markdownString)

is an abstraction over

var builder = new MarkdownPipelineBuilder();
var pipeline = builder.Build();

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

// Do post-processing on the Syntax Tree

StringWriter writer = new StringWriter();
var renderer = new HtmlRenderer(writer);
pipeline.Setup(renderer);

renderer.Render(document);
writer.Flush();

string html = writer.ToString();

You can do any post-processing to the document before rendering it, like increasing heading levels.

This exact heading post-processing could be exposed as a configuration, but I don't think it's common enough of a scenario, especially considering that implementing it yourself takes 2 lines of code.

@MihaZupan commented on GitHub (Sep 14, 2019): ```c# string html = Markdown.ToHtml(markdownString) ``` is an abstraction over ```c# var builder = new MarkdownPipelineBuilder(); var pipeline = builder.Build(); MarkdownDocument document = Markdown.Parse(markdown, pipeline); // Do post-processing on the Syntax Tree StringWriter writer = new StringWriter(); var renderer = new HtmlRenderer(writer); pipeline.Setup(renderer); renderer.Render(document); writer.Flush(); string html = writer.ToString(); ``` You can do any post-processing to the document before rendering it, like increasing heading levels. This exact heading post-processing could be exposed as a configuration, but I don't think it's common enough of a scenario, especially considering that implementing it yourself takes 2 lines of code.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#323