-
When parsing import unified from 'unified';
import markdown from 'remark-parse';
import type {Block} from '@notionhq/client/build/src/api-types';
import {parseRoot} from './internal';
import gfm from 'remark-gfm';
export function parseBody(body: string): Block[] {
const tokens = unified().use(markdown).use(gfm).parse(body);
return parseRoot(tokens);
} the generated MD AST is [
{
"type": "paragraph",
"children": [
{
"type": "html",
"value": "<sub>",
},
{
"type": "text",
"value": "hi",
},
{
"type": "html",
"value": "</sub>",
}
]
}
] For my purposes, it would be more convenient if instead, the HTML tag and content were processed as a single node with children, like: [
{
"type": "paragraph",
"children": [
{
"type": "html",
"value": "sub",
"children": [
{
"type": "text",
"value": "hi",
},
]
},
]
}
] Is this at all possible to do? Specifically, I just want to remove all HTML tags as well as their content when parsing, which would be very easy to do if it was a single node with children. |
Beta Was this translation helpful? Give feedback.
Answered by
wooorm
Jun 13, 2021
Replies: 1 comment 8 replies
-
What about: <main>
All
the
markdown
content
</main> Short answer: no. But it sounds like an XY problem |
Beta Was this translation helpful? Give feedback.
8 replies
Answer selected by
wooorm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about:
Short answer: no. But it sounds like an XY problem