Adapt micromark-extension-directive for fenced divs #1433
Replies: 2 comments 1 reply
-
I've just found I can fix the closing const newToken = this.sliceSerialize(token).trim() || 'div'
stack[stack.length - 1].name = newToken Updates the MDAST: {
type: 'containerDirective',
name: 'div',
attributes: { id: 'hello' },
_fenceCount: 2,
content: '<p>test</p>\n'
} and the HTML: <div id="hello">
<p>test</p>
</div> |
Beta Was this translation helpful? Give feedback.
-
I would recommend spending some more time with the existing directives and the existing code.
This is not what you want, here. In a different place, you can handle that omission, and default to
I do not understand, where is a closing div? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello again 👋
Further to my question adding attributes to images, I'm now trying to replicate markdown syntax from Pandoc for a lot of stuff, and so I'm attempting to write my own, or hack existing, parsing plugins. I have tried this a few times before actually, but been scared off due to not getting anywhere!
I looked all over for existing plugins compatible with Pandoc fenced-divs, and there have been a few attempts, but none are recommended for production use.
While hacking around with micromark-extension-directive I did figure out that if I comment this line, all of a sudden I am tanalisingly close to all I need, which is defaulting to a div when no name is given, with attributes:
Markdown:
MDAST:
HTML:
So as you can see in the HTML here, the opening tag for the container directive seems to fall back to
div
, but the closing doesn't.I have also tried feeding 'div' as the container name in factoryName, in the event of a space character, but so far computer says no:
Can you please give me some pointers as to where I should be looking in the code to accomplish this? Or how I should be thinking when working with this code, because so far I'm a little stumped!
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions