highlight

CodeMirror syntax highlighting that works in the browser and on Node.js

Source:

Methods

(static) highlightArray(codeopt) → {Array.<(string|Object)>}

Source:

Using the CodeMirror editor highlights a string of text representing JavaScript program code and returns an array of plain objects describing React Elements for easy serialization/unserialization.

Example
import {highlightArray} from 'webcompiler';
// or - import {highlightArray} from 'webcompiler/lib/highlight';
// or - var highlightArray = require('webcompiler').highlightArray;
// or - var highlightArray = require('webcompiler/lib/highlight').highlightArray;

highlightArray('function myScript(){return 100;}');
// [{type: 'pre', props: {className: 'CodeMirror-line'}, children: [...]}]
Parameters:
Name Type Attributes Default Description
code string <optional>
""

any valid ES2015, TypeScript, JSX, Flow code

Returns:

an array of plain objects describing React Elements

Type
Array.<(string|Object)>

(static) highlightHTML(codeopt) → {string}

Source:

Using the CodeMirror editor highlights a string of text representing JavaScript program code and returns an HTML string.

Example
import {highlightHTML} from 'webcompiler';
// or - import {highlightHTML} from 'webcompiler/lib/highlight';
// or - var highlightHTML = require('webcompiler').highlightHTML;
// or - var highlightHTML = require('webcompiler/lib/highlight').highlightHTML;

highlightHTML('function myScript(){return 100;}'); // <pre class="CodeMirror-line">...</pre>
Parameters:
Name Type Attributes Default Description
code string <optional>
""

any valid ES2015, TypeScript, JSX, Flow code

Returns:

an HTML string of the pre.CodeMirror-line elements

Type
string

(static) highlightJSX(codeopt) → {Array.<ReactElement>}

Source:

Using the CodeMirror editor highlights a string of text representing JavaScript program code and returns an array of React elements.

Example
import {highlightJSX} from 'webcompiler';
// or - import {highlightJSX} from 'webcompiler/lib/highlight';
// or - var highlightJSX = require('webcompiler').highlightJSX;
// or - var highlightJSX = require('webcompiler/lib/highlight').highlightJSX;

<div className="CodeMirror cm-s-monokai">{highlightJSX('function myScript(){return 100;}')}</div>
Parameters:
Name Type Attributes Default Description
code string <optional>
""

any valid ES2015, TypeScript, JSX, Flow code

Returns:

React elements of the pre.CodeMirror-line elements

Type
Array.<ReactElement>