Skip to content

egoist/cm-highlight

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

use codemirror as a syntax highlighter

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published