Pipe-based markdown tables are not converting correctly to HTML #462

Closed
opened 2026-01-29 14:37:24 +00:00 by claunia · 2 comments
Owner

Originally created by @nhamawi on GitHub (May 7, 2021).

EDITED TO REPRODUCE OIRIGINAL ISSUE FOR OTHERS THAT MIGHT RUN INTO THE SAME ISSUE

[... or the documentation is missing some relevant setup information]

When trying to convert a pipe-based markdown table to HTML, the result does not include any form of HTML table even with advanced extensions enabled. Instead, the result includes the input text in paragraph blocks < p > and < /p >.

This can be reproduced with .netfiddle as follows and the latest version of Markdig (0.24.0):

using System;
using System.IO;
using Markdig;
using Markdig.Renderers;
using Markdig.Parsers;

public class Program
{
	private static string Render(string markdown)
	{
		var writer = new StringWriter();
		var renderer = new HtmlRenderer(writer);
		var pipeline = new MarkdownPipelineBuilder()
			.UseAdvancedExtensions()
			.UsePipeTables()
			.Build();
		var document = MarkdownParser.Parse(markdown, pipeline);
		// pipeline.Setup(renderer); <-- Was missing this. Uncomment to fix this issue
		renderer.Render(document);
		writer.Flush();
		return writer.ToString();
	}

	public static void Main()
	{
		var markdown = "a | b \r\n" + "-- | - \r\n" + "0 | 1 ";
		var html = Render(markdown);
		Console.WriteLine(html);
	}
}

And the output:

<p>a</p>
<p>b</p>
<p>0</p>
<p>1</p>
Originally created by @nhamawi on GitHub (May 7, 2021). **EDITED TO REPRODUCE OIRIGINAL ISSUE FOR OTHERS THAT MIGHT RUN INTO THE SAME ISSUE** [... or the documentation is missing some relevant setup information] When trying to convert a pipe-based markdown table to HTML, the result does not include any form of HTML table even with advanced extensions enabled. Instead, the result includes the input text in paragraph blocks < p > and < /p >. This can be reproduced with .netfiddle as follows and the latest version of Markdig (0.24.0): using System; using System.IO; using Markdig; using Markdig.Renderers; using Markdig.Parsers; public class Program { private static string Render(string markdown) { var writer = new StringWriter(); var renderer = new HtmlRenderer(writer); var pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .UsePipeTables() .Build(); var document = MarkdownParser.Parse(markdown, pipeline); // pipeline.Setup(renderer); <-- Was missing this. Uncomment to fix this issue renderer.Render(document); writer.Flush(); return writer.ToString(); } public static void Main() { var markdown = "a | b \r\n" + "-- | - \r\n" + "0 | 1 "; var html = Render(markdown); Console.WriteLine(html); } } And the output: <p>a</p> <p>b</p> <p>0</p> <p>1</p>
Author
Owner

@MihaZupan commented on GitHub (May 7, 2021):

A few issues here:

  • You're not actually using your Render method, you are calling into the default Markdown.ToHtml
  • You are not using the pipeline for rendering (calling pipeline.Setup(renderer))

This can be done like

private static string Render(string markdown)
{
	var pipeline = new MarkdownPipelineBuilder()
		.UseAdvancedExtensions()
		.Build();
	var document = MarkdownParser.Parse(markdown, pipeline);

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

	return writer.ToString();
}

Or simplify it by using the helpers already provided:

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

var document = MarkdownParser.Parse(markdown, pipeline);

return document.ToHtml(pipeline);
var pipeline = new MarkdownPipelineBuilder()
	.UseAdvancedExtensions()
	.Build();

return Markdown.ToHtml(markdown, pipeline);
@MihaZupan commented on GitHub (May 7, 2021): A few issues here: - You're not actually using your `Render` method, you are calling into the default `Markdown.ToHtml` - You are not using the pipeline for rendering (calling `pipeline.Setup(renderer)`) This can be done like ```c# private static string Render(string markdown) { var pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .Build(); var document = MarkdownParser.Parse(markdown, pipeline); var writer = new StringWriter(); var renderer = new HtmlRenderer(writer); pipeline.Setup(renderer); renderer.Render(document); writer.Flush(); return writer.ToString(); } ``` Or simplify it by using the helpers already provided: ```c# var pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .Build(); var document = MarkdownParser.Parse(markdown, pipeline); return document.ToHtml(pipeline); ``` ```c# var pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .Build(); return Markdown.ToHtml(markdown, pipeline); ```
Author
Owner

@nhamawi commented on GitHub (May 7, 2021):

Sorry for the obvious and silly oversite as I was reworking code, but was going back and forth with using the render method and just .ToHtml(). Thank you for the quick response!!!

@nhamawi commented on GitHub (May 7, 2021): Sorry for the obvious and silly oversite as I was reworking code, but was going back and forth with using the render method and just .ToHtml(). Thank you for the quick response!!!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#462