Tables are wrongly rendered using HtmlRenderer #378

Open
opened 2026-01-29 14:35:22 +00:00 by claunia · 0 comments
Owner

Originally created by @Thoorium on GitHub (Jul 10, 2020).

Markdig version: 0.20.0

I have an extension method to render markdown to html to handle the url base of the links in the documents. To achieve this, I use the HtmlRenderer.

public static async Task<string> ToHtml(this MarkdownDocument markdownDocument, string urlBase = "")
{
    using StringWriter stringWriter = new StringWriter();
    HtmlRenderer htmlRenderer = new HtmlRenderer(stringWriter);

    if (!string.IsNullOrWhiteSpace(urlBase))
    {
        htmlRenderer.BaseUrl = new Uri(urlBase.Substring(0, urlBase.IndexOf("?") > 0 ? urlBase.IndexOf("?") : urlBase.Length), UriKind.Absolute);
    }
            
    htmlRenderer.Render(markdownDocument);
    await stringWriter.FlushAsync();

    return stringWriter.ToString();
}

This is the markdown it process.

# Hello, world

Some text

Please read [some link](another-markdown-document).

Here's a table.

|This|is|some|table|headers|
|---|---|---|---|---|
|Content|Content|Content|Content|Content|
|Content|Content|Content|Content|Content|
|Content|Content|Content|Content|Content|

When I inspect the markdown document, I can see it detected a table in my markup.
image

But the output html is wrong.

<h1 id="hello-world">Hello, world</h1>
<p>Some text</p>
<p>Please read <a href="https://localhost:5001/another-markdown-document">some link</a>.</p>
<p>Here's a table.</p>
<p>This</p>
<p>is</p>
<p>some</p>
<p>table</p>
<p>headers</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
...

If I use Markdig.Markdown.ToHtml(...) the table outputs correctly. Is there anything I'm missing?

Originally created by @Thoorium on GitHub (Jul 10, 2020). Markdig version: 0.20.0 I have an extension method to render markdown to html to handle the url base of the links in the documents. To achieve this, I use the `HtmlRenderer`. ```c# public static async Task<string> ToHtml(this MarkdownDocument markdownDocument, string urlBase = "") { using StringWriter stringWriter = new StringWriter(); HtmlRenderer htmlRenderer = new HtmlRenderer(stringWriter); if (!string.IsNullOrWhiteSpace(urlBase)) { htmlRenderer.BaseUrl = new Uri(urlBase.Substring(0, urlBase.IndexOf("?") > 0 ? urlBase.IndexOf("?") : urlBase.Length), UriKind.Absolute); } htmlRenderer.Render(markdownDocument); await stringWriter.FlushAsync(); return stringWriter.ToString(); } ``` This is the markdown it process. ```markdown # Hello, world Some text Please read [some link](another-markdown-document). Here's a table. |This|is|some|table|headers| |---|---|---|---|---| |Content|Content|Content|Content|Content| |Content|Content|Content|Content|Content| |Content|Content|Content|Content|Content| ``` When I inspect the markdown document, I can see it detected a table in my markup. ![image](https://user-images.githubusercontent.com/7754953/87105591-6c05f980-c229-11ea-9f14-91e965e55664.png) But the output html is wrong. ``` <h1 id="hello-world">Hello, world</h1> <p>Some text</p> <p>Please read <a href="https://localhost:5001/another-markdown-document">some link</a>.</p> <p>Here's a table.</p> <p>This</p> <p>is</p> <p>some</p> <p>table</p> <p>headers</p> <p>Content</p> <p>Content</p> <p>Content</p> ... ``` If I use `Markdig.Markdown.ToHtml(...)` the table outputs correctly. Is there anything I'm missing?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#378