human-text
v0.0.1
Published
`human-text` is a JavaScript library that transforms plain text into HTML. It is a port of the Ruby gem [auto_html](https://github.com/dejan/auto_html).
Downloads
162
Readme
human-text
human-text is a JavaScript library that transforms plain text into HTML. It is a port of the Ruby gem auto_html.
Installation
npm install human-textUsage
import { autoHtml, SimpleFormat, Image, Link } from 'human-text';
const text = 'Check the logo: https://example.org/images/rails.png. Visit: http://rubyonrails.org';
const filters = [new SimpleFormat(), new Image(), new Link()];
const result = autoHtml(text, filters);
console.log(result);This will output:
<p>Check the logo: <img src="https://example.org/images/rails.png" alt="">. Visit: <a href="http://rubyonrails.org">http://rubyonrails.org</a></p>Filters
The following filters are available:
SimpleFormat: Wraps the text in<p>tags and replaces newlines with<br>tags.Image: Replaces image URLs with<img>tags.Link: Replaces URLs with<a>tags.HtmlEscape: Escapes HTML characters.Markdown: Converts Markdown to HTML.Emoji: Converts emoji codes to emojis.
Running tests
npm test