A remark plugin for dropping unnecessary paragraph nodes
The idea behind this plugin: mdx-js/mdx#1170 (comment)
npm install @allenlee/remark-drop-paragraph
see the comments or source code for more information
- inlineElement
- blockElement
- isJsxElement
- DefaultOption
- type RemarkDropParagraphOption
unwrapTags(paragraph's child per each)
If you need to unwrap outer paragraph, use this method to iterate through the paragraph's children nodes and unwrap when one returns true
default:blockElement.includes(node.type) || isJsxElement(node, true)
noIncludeTags(paragraph's parent)
If you need to drop internal paragraph, use this method to iterate through the nodes that may contain paragraph, and drop the paragraph when it returns true
default:['mdxBlockElement'].includes(node.type) || isJsxElement(node, false)
const remarkDropParagraph = require('@allenlee/remark-drop-paragraph');
remark().use(remarkDropParagraph).process(`
<JsxOut>
paragraph1 in
</JsxOut>
paragraph2 out <JsxComponent />
`);
<JsxOut>
<p>
paragraph1 in
</p>
</JsxOut>
<p>paragraph2 out <JsxComponent /></p>
<JsxOut>
paragraph1 in
</JsxOut>
<p>paragraph2 out</p> <JsxComponent />