Skip to content

Latest commit

 

History

History
78 lines (54 loc) · 1.51 KB

README.md

File metadata and controls

78 lines (54 loc) · 1.51 KB

@allenlee/remark-drop-paragraph

A remark plugin for dropping unnecessary paragraph nodes

The idea behind this plugin: mdx-js/mdx#1170 (comment)

Installation

npm install @allenlee/remark-drop-paragraph

Export

see the comments or source code for more information

  • inlineElement
  • blockElement
  • isJsxElement
  • DefaultOption
  • type RemarkDropParagraphOption

Options

  • 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)

Usage

Source

const remarkDropParagraph = require('@allenlee/remark-drop-paragraph');

remark().use(remarkDropParagraph).process(`
<JsxOut>

paragraph1 in

</JsxOut>

paragraph2 out <JsxComponent />
`);

Yields

Without this

<JsxOut>
<p>
  paragraph1 in
</p>
</JsxOut>

<p>paragraph2 out <JsxComponent /></p>

With this

<JsxOut>
  paragraph1 in
</JsxOut>

<p>paragraph2 out</p> <JsxComponent />

License

MIT @ Allen Lee