remarkHTML タグを含む Markdown ドキュメントの AST を取得するために使用しています。これを実行すると:
const remark = require('remark')
const result = remark.parse('<h1>First</h1>')
console.log(JSON.stringify(result, null, 2))
レベル 1 の見出しを含む AST を取得します。
{
"type": "root",
"children": [
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "Title",
"position": {
"start": {
"line": 1,
"column": 3,
"offset": 2
},
"end": {
"line": 1,
"column": 8,
"offset": 7
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 8,
"offset": 7
}
}
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "body",
"position": {
"start": {
"line": 2,
"column": 1,
"offset": 8
},
"end": {
"line": 2,
"column": 5,
"offset": 12
}
}
}
],
"position": {
"start": {
"line": 2,
"column": 1,
"offset": 8
},
"end": {
"line": 2,
"column": 5,
"offset": 12
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 5,
"offset": 12
}
}
}
しかし、h1代わりに明示的なタグを使用すると:
const remark = require('remark')
const result = remark.parse('<h1>Title</h1>\nbody') # <- note change
console.log(JSON.stringify(result, null, 2))
htmlタグのテキストとその内容を含むタイプのノードを取得します。
{
"type": "root",
"children": [
{
"type": "html",
"value": "<h1>Title</h1>\nbody",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 5,
"offset": 19
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 5,
"offset": 19
}
}
}
2 番目のケースでも、最初のケースと同じ AST を取得したいと考えています。つまり、remarkHTML を解析したいと考えています。Markdown には HTML を含めることが許可されているため、デフォルトでこれが行われることを期待していました。これがパーサー構成オプションによって有効になっている場合、私はそれを見つけることができませんでした. ポインタは大歓迎です。