mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-03 21:36:36 +00:00
Custom Contains - Custom rendering #301
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @LukeTOBrien on GitHub (May 29, 2019).
Hello,
I am moving my project from NodeJS using Markdown-it to .NET Core using Markdig.
I am using the Markdown-it-containers plugin.
As you can see from the Example on that page, the plugin allows custom rendering, so instead of
divthe developer can use any element they choose.It my project I make use of this in quite a few cases, for example I have Markdown like this:
This renders as:
Would there be anyway to do this in Markdig?
I notice in you current spec you do not specify a mechanism for custom rendering.
Thanks
@MihaZupan commented on GitHub (May 29, 2019):
The CustomContainers extension emits
CustomContainerobjects into the document.You can create your own renderer for that specific object - pretty much copying what the current renderer does.
All you have to do then is ensure that your renderer takes priority over the older one - insert it before that one in the list of renderers.
So you end up with something like
used by
@MihaZupan commented on GitHub (May 29, 2019):
I suppose a parameter with a
divdefault could be exposed on the existing extension as well.@LukeTOBrien commented on GitHub (May 29, 2019):
Thank you very much for your quick response.
When I get some time I will test this out.
Would this preserve the class?
There is no test for whether or not to to use the custom renderer, I only want some containers to appear as
asideand some to appear asdivas per normal.Would the above code apply to all container rather than just some of them?
I also know that you are currently working on official documentation for the project, I think custom rendering for containers could be a common thing that a lot of folks would want to do, so perhaps this could make it in to the official documentation?
@MihaZupan commented on GitHub (May 29, 2019):
A renderer is a catch-all for that type. You can of course choose the tag based on the info string that is exposed on the object when rendering said object.
I don't know what you mean by official documentation. It would certainly be useful but I'm not working on any rn.
@LukeTOBrien commented on GitHub (May 29, 2019):
I will try some tests when I get home.
About the 'official' documentation thing, on the main readme:
'Proper' or 'Official', I guess somebody's working on it.
Anyway I have written some Unit Test for the Header Section #342 , so perhaps I could contribute them and also help with documentation?
@xoofx commented on GitHub (May 29, 2019):
Yeah, sorry, the readme hasn't been updated since then, but nobody is working on it and there is no plan to work on that.
It is not a huge amount of work, but it is certainly several days of work to get a descent documentation up and running (with proper docgen via docfx...), and I have personally no spare time left allocated for that.
@MihaZupan commented on GitHub (May 29, 2019):
I can take a look at docfx, haven't actually tried it yet
@LukeTOBrien commented on GitHub (May 29, 2019):
Hmm, I have never come across docfx.
You already have
.mdfiles in the spec folder, if it was me I would use Hugo (Whisper Theme) with a GitHub pages repo and copy the existing.mdfiles.@MihaZupan commented on GitHub (May 29, 2019):
I have used mdbook before on a different project, but it seems fitting to use docfx since it's powered by Markdig. If I gather correctly it's what docs.microsoft.com uses.
The markdown in spec folders essentially doubles as a test suite, but some words about parsing, rendering and the AST would be required.
@LukeTOBrien commented on GitHub (May 31, 2019):
Hello there,
I finally got to sit down and test this thing out, it works!
I have also been wondering about commiting this code and #342 into the main Markdig repo - Under perhaps
ExsensionHelpersorHelpersnamespace. What do you think about that? Would you be interested?Here is the class I came up with:
Then for my purposes:
@MihaZupan commented on GitHub (May 31, 2019):
If anything, an info-tag mapping could be exposed as a parameter for the CustomContainers extension, I do not think a separate extension is needed.
@LukeTOBrien commented on GitHub (May 31, 2019):
Okay. Closing as resolve, thanks!