@beeanco/render-wordpress-post
v1.0.2
Published
Render a wordpress post to clean html
Downloads
40
Maintainers
Readme
@beeanco/render-wordpress-post
Render a wordpress post to clean html
Installation
With node.js installed, use npm to install this package:
npm install @beeanco/render-wordpress-post
Usage
import { render } from '@beeanco/render-wordpress-post';
const result = render('<p class="dunno" style="color: red">Some text[shortcode]</p>');
// `result` is '<p>Some text</p>'
So, what does it do to the passed HTML:
- Removes all CSS classes
- Removes all inline styles
- Renders supported and custom shortcodes (see below)
- Removes unknown shortcodes (e.g.
[caption]
tags)
Supported shortcodes
[caption]
- Renders to<figure>
[audio]
- Renders to<audio>
[youtube]
- Renders to an<iframe>
containing the embedded YouTube video
Custom shortcodes
You can also add support for your own shortcodes by implementing the ShortcodeRenderer
interface and passing it to render
:
import { render, defaultRenderers } from '@beeanco/render-wordpress-post';
import type { ShortcodeRenderer } from '@beeanco/render-wordpress-post';
const worldRenderer: ShortcodeRenderer = (node) => `World`;
const result = render('Hello, [world]', [
// Pass your own renderer
worldRenderer,
// Also add support for caption, audio, ...
...defaultRenderers,
]);
// `result` is 'Hello, World'