0.1.4 • Published 6 years ago
contents-helpers v0.1.4
Installation
Install contents-helpers
using Yarn or NPM:
yarn add contents-helpers
npm install --save contents-helpers
If you'd like to use a standlone pre-built version of the library for prototyping, you can include it via a <script>
tag like so:
<script src="https://unpkg.com/contents-helpers@latest/dist/contents-helpers.min.js"></script>
Be sure to change the version from @latest
to whatever the current latest version is when you include it, otherwise the dependency is unpinned!
Helpers
The library contains a handful of different helpers which can all be imported individually, or as a single object:
import Helpers from 'contents-helpers'
import { toHtml, toString } from 'contents-helpers'
Each helper has it's own API...
toHtml
toHtml((Object | Array: value))
import { toHtml } from 'contents-helpers'
const html = toHtml(item.properties.body)
// <p>A paragraph of text...</p>
// <p>Some things to do:</p>
// <ul>
// <li>One</li>
// <li>Two</li>
// <li>Three</li>
// </ul>
Convert a value
into HTML. The value can be one of:
- A Contents block.
- An array of Contents blocks.
- A non-HTML string, which will be escaped.
- A HTML string, which will do nothing.