cm-highlight

0.1.1 • Public • Published

cm-highlight

NPM version NPM downloads Build Status donate

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

Readme

Keywords

none

Package Sidebar

Install

npm i cm-highlight

Weekly Downloads

28

Version

0.1.1

License

MIT

Last publish

Collaborators

  • rem