How can this be used?
datapimp opened this issue · 5 comments
would this plugin be useful for the following?
so given a markdown document with the following structure
# epic title
content describing the epic
## feature title 1
content describing the feature
### task title 1
content describing the task
### task title 2
content describing the task again
I want to produce a nesting effect, roughly:
section data-heading='epic title'
h1
' epic title
p
' content describing the epic
article data-heading='feature title 1'
h2
' feature title 1
p
' content describing the feature
article data-heading='task title 1'
h3 task title 1
p
' content describing the task
so basically the h1 content is wrapped in a section, and the h2 under neath it get wrapped in an article and so on, for all depths.
I've figured out the way the plugins work in terms of transforming the ast. i've created custom renderers for the section and article tags, and can move children into nodes.
i'm just trying to think about how to perform this task more elegantly using the tools available
This utility works based on the content of a heading. So no, however, you can check out how it works to do similar things :)
Also of interest: this plugin only checks children of root, so it doesn’t walk into block-quotes.
I’ll respond more later. I’m really busy, can’t guarantee I’ll respond today.
only checking the children of root is ok, as the use-case is just building a hierarchy based on the h1, h2, h3 headings.
i'll be able to use some of this code as inspiration in my own plugin. thank you for responding quickly.
i will close this issue as i was mostly being lazy.
@datapimp I was thinking about doing this kind of nesting. Have you been able to come up with something by chance?
I hacked a quick plugin here which somehow adresses the initial question: https://github.com/tcmlabs/mdast-util-nested-sections
This tool nests heading ranges into sections, using div or anything else (any React component). Not much documentation for the moment, I'll try to improve this. It's a bit clunky but does the job.
I did something like this a bit ago as well, but on HAST, here: https://github.com/unifiedjs/unifiedjs.github.io/blob/src/script/html/plugin/section.js. The plugin works, but should be externalised with tests and the like!