rehype-remove-empty-paragraph
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

rehype-remove-empty-paragraph

rehype plugin that remove <p></p> / <p><br></p>.

Install

npm:

npm install rehype-remove-empty-paragraph

Usage

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

Readme

Keywords

Package Sidebar

Install

npm i rehype-remove-empty-paragraph

Weekly Downloads

22

Version

0.2.4

License

MIT

Unpacked Size

5.89 kB

Total Files

7

Last publish

Collaborators

  • hankei6km