[Question] Custom renderer outside MarkDig possible? #736

Open
opened 2026-01-29 14:44:20 +00:00 by claunia · 1 comment
Owner

Originally created by @Seikilos on GitHub (May 10, 2025).

Hi,

due to a lack of documentation I am trying to create a simple PDF exporter and was playing around with deriving from RendererBase because I won't return a text writer, so I cannot use TextRenderBase like the HtmlRenderer does. (This is my assumption)

However, the signature of render base poses some questions for me:

public override object Render(MarkdownObject markdownObject)

I get a MarkdownObject and need to descend down to containers, etc but I am stuck.

Beside the fact that I haven't found a way for a hierarchical traversal yet, I stumbled upon MarkdownObject.IsContainerInline and MarkdownObject.IsContainerBlock, which are internal.

I assume that I misunderstand how to approach the traversal, but does the internal modifier on the method above makes it quite tricky to discern what to do?

I looked at the plain text and html renderers, I also looked at some forked Wpf Renderer but still am unsure on how to handle traversal that way without a text render output (otherwise I could somehow hijack the html renderer I assume.

Or would be actually using the Html renderer to get html be the best way? I could parse the resulting html into a tree and then continue my pdf export from html instead of markdown I assume.

Originally created by @Seikilos on GitHub (May 10, 2025). Hi, due to a lack of documentation I am trying to create a simple PDF exporter and was playing around with deriving from RendererBase because I won't return a text writer, so I cannot use TextRenderBase like the HtmlRenderer does. (This is my assumption) However, the signature of render base poses some questions for me: `public override object Render(MarkdownObject markdownObject)` I get a `MarkdownObject` and need to descend down to containers, etc but I am stuck. Beside the fact that I haven't found a way for a hierarchical traversal yet, I stumbled upon `MarkdownObject.IsContainerInline` and `MarkdownObject.IsContainerBlock`, which are internal. I assume that I misunderstand how to approach the traversal, but does the internal modifier on the method above makes it quite tricky to discern what to do? I looked at the plain text and html renderers, I also looked at some forked Wpf Renderer but still am unsure on how to handle traversal that way without a text render output (otherwise I could somehow hijack the html renderer I assume. Or would be actually using the Html renderer to get html be the best way? I could parse the resulting html into a tree and then continue my pdf export from html instead of markdown I assume.
claunia added the question label 2026-01-29 14:44:20 +00:00
Author
Owner

@xoofx commented on GitHub (May 10, 2025):

RendererBase has several methods WriteChildren and Write(MarkdownObject) that are used to traverse the objects.

Your derived MarkdownObjectRenderer will call back to these methods as it is done for the HtmlRenderers For example for the list renderer here or the quote block renderer here ...etc.

@xoofx commented on GitHub (May 10, 2025): `RendererBase` has several methods [WriteChildren](https://github.com/xoofx/markdig/blob/3535701d70066d055d06adaeaa1531b10601c6ac/src/Markdig/Renderers/RendererBase.cs#L101) and [`Write(MarkdownObject)`](https://github.com/xoofx/markdig/blob/3535701d70066d055d06adaeaa1531b10601c6ac/src/Markdig/Renderers/RendererBase.cs#L165) that are used to traverse the objects. Your derived `MarkdownObjectRenderer` will call back to these methods as it is done for the HtmlRenderers For example for the list renderer [here](https://github.com/xoofx/markdig/blob/3535701d70066d055d06adaeaa1531b10601c6ac/src/Markdig/Renderers/Html/ListRenderer.cs#L61) or the quote block renderer [here](https://github.com/xoofx/markdig/blob/3535701d70066d055d06adaeaa1531b10601c6ac/src/Markdig/Renderers/Html/QuoteBlockRenderer.cs#L26) ...etc.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#736