String not processed as markdown if it starts with div #579

Closed
opened 2026-01-29 14:40:15 +00:00 by claunia · 4 comments
Owner

Originally created by @omer-iqbal on GitHub (Dec 4, 2022).

If markdown starts with <div>, e.g.: <div>Hello *world*
Then Markdown.ToHtml() does not process it, i.e. the same string is returned.

However, if the <div> tag is replaced with another one, say <span> or a custom one like <a>, then markdown is processed correctly. The result would be <p><a>Hello <em>world</em>.

        string test = @"<div>Hello *world*";
        string answer = Markdig.Markdown.ToHtml(test);
        // answer in debugger = <div>Hello *world*
Originally created by @omer-iqbal on GitHub (Dec 4, 2022). If markdown starts with `<div>`, e.g.: `<div>Hello *world*` Then `Markdown.ToHtml()` does not process it, i.e. the same string is returned. However, if the `<div>` tag is replaced with another one, say `<span>` or a custom one like `<a>`, then markdown is processed correctly. The result would be `<p><a>Hello <em>world</em>`. string test = @"<div>Hello *world*"; string answer = Markdig.Markdown.ToHtml(test); // answer in debugger = <div>Hello *world*
claunia added the questioninvalid labels 2026-01-29 14:40:15 +00:00
Author
Owner

@xoofx commented on GitHub (Dec 4, 2022):

This is a HTML block as per the CommonMark spec here, <div> is a start condition for a HTML block. See also that all CommonMark implementations are behaving similarly.

@xoofx commented on GitHub (Dec 4, 2022): This is a HTML block as per the CommonMark spec [here](https://spec.commonmark.org/0.30/#html-blocks), `<div>` is a start condition for a HTML block. See also that all CommonMark implementations are [behaving similarly](https://babelmark.github.io/?text=%3Cdiv%3EHello+*world*).
Author
Owner

@omer-iqbal commented on GitHub (Dec 4, 2022):

CommonMark spec section 6.6 confused me actually, e.g. examples 612 onwards. I spent quite some time trying out different md texts and comparing with the spec before opening this issue. Thanks for the clarification. Now it's obvious and I feel bad for opening this issue. :(

@omer-iqbal commented on GitHub (Dec 4, 2022): CommonMark spec section 6.6 confused me actually, e.g. examples 612 onwards. I spent quite some time trying out different md texts and comparing with the spec before opening this issue. Thanks for the clarification. Now it's obvious and I feel bad for opening this issue. :(
Author
Owner

@xoofx commented on GitHub (Dec 4, 2022):

CommonMark spec section 6.6 confused me actually, e.g. examples 612 onwards. I spent quite some time trying out different md texts and comparing with the spec before opening this issue. Thanks for the clarification. Now it's obvious and I feel bad for opening this issue. :(

Don't feel bad. The spec is quite complicated when you go into corner cases like this. But I'm happy that there is a spec because that would be a nightmare without it for a maintainer! 😅

@xoofx commented on GitHub (Dec 4, 2022): > CommonMark spec section 6.6 confused me actually, e.g. examples 612 onwards. I spent quite some time trying out different md texts and comparing with the spec before opening this issue. Thanks for the clarification. Now it's obvious and I feel bad for opening this issue. :( Don't feel bad. The spec is quite complicated when you go into corner cases like this. But I'm happy that there is a spec because that would be a nightmare without it for a maintainer! 😅
Author
Owner

@omer-iqbal commented on GitHub (Dec 4, 2022):

I had looked at md a long time back and didn't find a good parser, so I did some minimal custom (non md) parsing for my project. I am beginning to love md in my project now, thanks to markdig and you're right, the spec has made a huge difference. I do have some custom formatting needs so I will be exploring writing extensions as well.

@omer-iqbal commented on GitHub (Dec 4, 2022): I had looked at md a long time back and didn't find a good parser, so I did some minimal custom (non md) parsing for my project. I am beginning to love md in my project now, thanks to markdig and you're right, the spec has made a huge difference. I do have some custom formatting needs so I will be exploring writing extensions as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#579