在 Gatsby 中,我file.md
有file.md
.
盖茨比变压器备注
使用时gatsby-transformer-remark
,我可以使用allMarkdownRemark.nodes.html
. 如何获取文件每个部分的 HTML?例如:
file.md
:
# section 1
**bold**
# section 2
foo
我想获得一组 HTML 部分,例如:
[
'<div><h1>section 1</h1><b>bold</b></div>',
'<div><h1>section 2</h1>foo</div>'
]
盖茨比插件 mdx
gatsby-plugin-mdx
,我什么时候
query MyQuery {
mdx {
headings {
value
depth
}
}
}
我明白了
{
"data": {
"mdx": {
"headings": [
{
"value": "Section1",
"depth": 1
},
{
"value": "Section2",
"depth": 1
},
]
}
},
"extensions": {}
}
但是当我这样做时:
query MyQuery {
mdx(headings: {elemMatch: {value: {eq: "Section1"}}}) {
body
}
}
这body
是整个文件,而不仅仅是第 1 节。