Socket
Socket
Sign inDemoInstall

highlight-codemirror

Package Overview
Dependencies
12
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    highlight-codemirror

A syntax highlighter built to run in node and consume CodeMirror modes.


Version published
Weekly downloads
2.2K
increased by8.71%
Maintainers
1
Install size
2.99 MB
Created
Weekly downloads
 

Readme

Source

highlight-codemirror

A syntax highlighter built to run in node and consume CodeMirror modes.

Build Status Dependency Status NPM version

API

highlight(source, mode)

The source should be a string of code to highlight. The mode should be either the name of a mode (as a string) or an object (allowing you to specify other options).

var highlight = require('highlight-codemirror');

var html = highlight('assert(typeof "foo" === "string")', 'javascript');
// => '<span class="cm-variable">assert</span>(<span class="cm-keyword">typeof</span> <span class="cm-string">&quot;foo&quot;</span> <span class="cm-operator">===</span> <span class="cm-string">&quot;string&quot;</span>)'

highlight.loadMode(name);

Loading modes is synchronous, so you may wish to pre-populate the cache bu loading the mode up front. You can also load custom modes by passing an absolute path to a JavaScript file. e.g. the null mode might look like:

/custom-null-mode.js

var CodeMirror = require('codemirror');

// Minimal default mode.
CodeMirror.defineMode("custom-null", function() {
  return {token: function(stream) {stream.skipToEnd();}};
});

You could then do:

highlight.loadMode('/custom-null-mode.js');
assert(highlight('This is not really a programming language', 'custom-null') === 'This is not really a programming language');

License

MIT

FAQs

Last updated on 12 Oct 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc