Add parent container for HTML elements #213

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

Originally created by @konrad147 on GitHub (Jun 26, 2018).

Hello,

I have a following problem: I need to wrap every <table> element into a <div> during rendering. What would be the best approach to solve it? I thought about a custom extension but not sure whether I can change order of elements there. Another option would be to directly modify MarkdownDocument isn't it?

I know I could use CustomContainers but then client would have to remember to wrap each table into them and I want to avoid.

I'll be thankful for suggestions.

Originally created by @konrad147 on GitHub (Jun 26, 2018). Hello, I have a following problem: I need to wrap every `<table>` element into a `<div>` during rendering. What would be the best approach to solve it? I thought about a custom extension but not sure whether I can change order of elements there. Another option would be to directly modify `MarkdownDocument` isn't it? I know I could use `CustomContainers` but then client would have to remember to wrap each table into them and I want to avoid. I'll be thankful for suggestions.
claunia added the question label 2026-01-29 14:30:35 +00:00
Author
Owner

@xoofx commented on GitHub (Jun 26, 2018):

You probably have two options:

  1. You could extend HtmlTableRenderer, replace the previous HtmlTableRenderer setup in the HtmlRenderer, override the method HtmlTableRenderer.Write (calling the base and wrapping it with a div)
  2. You can also manipulate the MarkdownDocument to add a custom container around.

If it is just a rendering issue, maybe option 1. is the easiest (Haven't checked the details, so it might not work in the end)

@xoofx commented on GitHub (Jun 26, 2018): You probably have two options: 1. You could extend [`HtmlTableRenderer`](https://github.com/lunet-io/markdig/blob/master/src/Markdig/Extensions/Tables/HtmlTableRenderer.cs#L18), replace the previous `HtmlTableRenderer` setup in the `HtmlRenderer`, override the method `HtmlTableRenderer.Write` (calling the base and wrapping it with a div) 2. You can also manipulate the MarkdownDocument to add a custom container around. If it is just a rendering issue, maybe option 1. is the easiest (Haven't checked the details, so it might not work in the end)
Author
Owner

@konrad147 commented on GitHub (Jun 26, 2018):

Thanks!

@konrad147 commented on GitHub (Jun 26, 2018): Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#213