0.2.4 • Published 4 years ago
rehype-remove-empty-paragraph v0.2.4
rehype-remove-empty-paragraph
rehype plugin that remove <p></p> / <p><br></p>.
Install
npm:
npm install rehype-remove-empty-paragraphUsage
code: example/example.ts
import unified from 'unified';
import rehypeParse from 'rehype-parse';
import stringify from 'rehype-stringify';
import rehypeRemoveEmptyParagraph from '../src';
const html = '<p>foo</p><p><br></p><p><br>bar<br></p>';
unified()
.use(rehypeParse, { fragment: true })
.use(rehypeRemoveEmptyParagraph, { trimBr: true })
.use(stringify)
.freeze()
.process(html, (err, file) => {
if (err) {
console.error(err);
}
console.log(String(file));
});yield:
<p>foo</p><p>bar</p>API
rehypeRemoveEmptyParagraph([options])
Remove <p></p> / <p><br></p>.
Paragraph is only supported root / paragraph hierarchy.
options.trimBr
Trim leading/trailing <br> in Paragraph.
License
MIT License
Copyright (c) 2021 hankei6km