fabulous
v1.0.1
Published
A tiny, bare bones and kind of dumb highlighter.
Downloads
6
Maintainers
Readme
Fabulous
Fabulous is a tiny, bare bones and kind of dumb highlighter for Node.js and the browser.
It supports Internet Explorer 9+ and works with Browserify.
Installation
npm install fabulous
Usage
CLI
With the default JavaScript rules:
fabulous <input> <output>
API
With the default JavaScript rules:
var fabulous = require('fabulous')
var str = 'function foo() {}'
var code = fabulous(str)
// => "<span class="keyword">function</span> foo() {}"
You can also use your own custom (regexp) rules:
var fabulous = require('fabulous')
var str = 'An apple, a banana and an orange.'
var words = fabulous(str, {
fruit: /apple|banana|orange/g
})
// => "An <span class="fruit">apple</span>, a <span class="fruit">banana</span> and an <span class="fruit">orange</span>."
Caveats
If an identical match with the exact same rule is present on the same line more than once it'll only highlight the first occurrence:
var fabulous = require('fabulous')
var str = 'var foo; var bar'
var code = fabulous(str)
// => "<span class="keyword">var</span> foo; var bar"
If something that matches a rule exists in another rule that rule will also be wrapped:
var fabulous = require('fabulous')
var str = "var str = 'function() {}'"
var code = fabulous(str)
// => "<span class="keyword">var</span> str = <span class="string">'<span class="keyword">function</span>() {}'</span>"