highlight-syntax
highlight source code syntax with html
Works in node and the browser. Supported languages:
- javascript
- bash
- c
Very small:
$ browserify . | uglifyjs -cm 2>/dev/null | gzip | wc -c1776$ browserify all.js | uglifyjs -cm 2>/dev/null | gzip | wc -c3391
example
all languages
You can load all the languages:
var highlight =var fs =var src = fsconsole
subset of languages
Or you can load a subset of languages. This will make the bundle you deliver to the browser smaller.
var highlight =var fs =var src = fsconsole
example with marked
You can pass this module to marked to highlight code in a markdown file:
var highlight =var marked =var fs =var src = fsconsole
api
var highlighter =var highlight =
The css files in this distribution are:
- highlight-syntax/dark.css - combined dark themes for all languages
- highlight-syntax/light.css - combined linght themes for all languages
var highlight = highlighter(rules)
Create a highlighter function from an array of rules
. You can load the rules
explicitly from:
require('highlight-syntax/c')
- crequire('highlight-syntax/sh')
- bashrequire('highlight-syntax/js')
- javascript
var html = highlight(src, opts)
Turn a string of code src
written in opts.lang
to a syntax-highlighted
string of html. If opts
is a string, it is interpreted as the opts.lang
.
opts.lang
- string language name or file extension
usage
highlight-syntax FILES... {OPTIONS}
-o --outfile Write output to a file. Default: - (stdout)
-l --lang Set a language explicitly for stdin input.
-t --theme Include an inline css theme. Example: dark
install
To get the library:
npm install highlight-syntax
To get the command:
npm install -g highlight-syntax
license
BSD