In Gatsby, I have file.md
, and I'd like to generate multiple pages—one for each section of file.md
.
gatsby-transformer-remark
When using gatsby-transformer-remark
, I can get the HTML of an entire markdown file with allMarkdownRemark.nodes.html
. How do I get the HTML of each section of the file? For instance:
file.md
:
# section 1
**bold**
# section 2
foo
I'd like to get an array of section HTMLs, like:
[
'<div><h1>section 1</h1><b>bold</b></div>',
'<div><h1>section 2</h1>foo</div>'
]
gatsby-plugin-mdx
With gatsby-plugin-mdx
, when do I
query MyQuery {
mdx {
headings {
value
depth
}
}
}
I get
{
"data": {
"mdx": {
"headings": [
{
"value": "Section1",
"depth": 1
},
{
"value": "Section2",
"depth": 1
},
]
}
},
"extensions": {}
}
But when I do:
query MyQuery {
mdx(headings: {elemMatch: {value: {eq: "Section1"}}}) {
body
}
}
The body
is the entire file, not just Section1.