cm-highlight

use codemirror as a syntax highlighter

MIT License

Downloads
96
Stars
4
Committers
1

cm-highlight

Install

This requires codemirror to be a peer dependency.

yarn add codemirror cm-highlight

Usage

import 'codemirror/mode/javascript/javascript'
import highlight from 'cm-highlight'

const code = `const foo = () => {
  console.log('foo')
}`

const html = highlight(code, { mode: 'javascript' })
//=> <span class="cm-keyword">...</span>

Then just place html into an element like <pre class="cm-s-default"><code>${html}</code></pre>, you can replace default with the codemirror theme name you actually use.

API

highlight(code, [options])

options

mode

Type: string

The mode to use (must be loaded as normal)

tabSize

Type: Number Default: 2

Replace tab with this amount of spaces.

Todos

  • Support line numbers.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

cm-highlight © egoist, Released under the MIT License. Authored and maintained by egoist with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin