Replacing Contents of HtmlBlock / HtmlInline #505

Closed
opened 2026-01-29 14:38:21 +00:00 by claunia · 1 comment
Owner

Originally created by @damageboy on GitHub (Feb 27, 2022).

Hi,
I'm looking for a cookbook like recipe for how is the "right" way, as far as markdig is concerned for doing markdown transformations.

Namely, I'm trying to concert a .md file to a .mdx file using markdig.

One of the relatively minor challenges in this process is converting style="a: b;c: d" html attributes to style={{a: b, c: d}}.

Generally speaking, making such changes in a "living" MarkdownDoc class is not very well documented, or I'm just reading the wrong documents.

Could anyone chart the path of least resistance when it comes to such challenges?

Originally created by @damageboy on GitHub (Feb 27, 2022). Hi, I'm looking for a cookbook like recipe for how is the "right" way, as far as markdig is concerned for doing markdown transformations. Namely, I'm trying to concert a `.md` file to a `.mdx` file using markdig. One of the relatively minor challenges in this process is converting `style="a: b;c: d"` html attributes to `style={{a: b, c: d}}`. Generally speaking, making such changes in a "living" MarkdownDoc class is not very well documented, or I'm just reading the wrong documents. Could anyone chart the path of least resistance when it comes to such challenges?
claunia added the question label 2026-01-29 14:38:21 +00:00
Author
Owner

@xoofx commented on GitHub (Mar 1, 2022):

I'm looking for a cookbook like recipe for how is the "right" way, as far as markdig is concerned for doing markdown transformations.

It depends on what you want to do. If it is to re-emit markdown documents or to still transform it to a pseudo-HTML content? The later is usually the easiest.

But the former, depending on your processing need, can be done by processing Markdown syntax tree via e.g MarkdownObject.Descendants

If you need to write a different output, you might have to write a custom renderer or you can overwrite an existing one (e.g HtmlRenderer). You can see the code here and despite the lack of doc, it should not be too difficult to figure out how to write a new one or overwrite a new one.

@xoofx commented on GitHub (Mar 1, 2022): > I'm looking for a cookbook like recipe for how is the "right" way, as far as markdig is concerned for doing markdown transformations. It depends on what you want to do. If it is to re-emit markdown documents or to still transform it to a pseudo-HTML content? The later is usually the easiest. But the former, depending on your processing need, can be done by processing Markdown syntax tree via e.g [MarkdownObject.Descendants](https://github.com/xoofx/markdig/blob/9bbf6855e1df877e7fd472a810633b44e40a9be9/src/Markdig/Syntax/MarkdownObjectExtensions.cs#L240) If you need to write a different output, you might have to write a custom renderer or you can overwrite an existing one (e.g HtmlRenderer). You can see the code [here](https://github.com/xoofx/markdig/tree/master/src/Markdig/Renderers) and despite the lack of doc, it should not be too difficult to figure out how to write a new one or overwrite a new one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#505