ReadMe's React-based syntax highlighter
ReadMe's React-based syntax highlighter based on [CodeMirror][codemirror] and [react-codemirror2][react-codemirror]
 

```
npm install --save @readme/syntax-highlighter
`js`
const syntaxHighlighter = require('@readme/syntax-highlighter');
const ele = syntaxHighlighter('console.log("Hello, world!");', 'js');
`js`
const syntaxHighlighter = require('@readme/syntax-highlighter');
const ele = syntaxHighlighter('console.log("Hello, world!");', 'js', { ...opts, highlightMode: true });
`js`
const syntaxHighlighter = require('@readme/syntax-highlighter');
const ele = syntaxHighlighter('console.log("Hello, world!");', 'js', {
...opts,
highlightMode: true,
ranges: [
[
{ ch: 0, line: 0 },
{ ch: 0, line: 1 },
],
],
});
Access to a full code Mirror instance. See configuration settings in the [react-codemirror2 library][react-codemirror#props]
`js`
const syntaxHighlighter = require('@readme/syntax-highlighter');
const ele = syntaxHighlighter('console.log("Hello, world!");', 'js', { ...opts, editable: true }, { ...editorProps });
[rdme-variable]: https://github.com/readmeio/api-explorer/tree/next/packages/variable
| Name | Type | Description |
| :--- | :--- | :--- |
| customTheme | String | Highlighting theme. One of neo, material-palenight, or tomorrow-night. (Setting this will override the dark mode option.)dark
| | Boolean | Enable dark mode. |editable
| | Boolean | Enable the full CodeMirror instance |highlightMode
| | Boolean | Enable line number display. |inline
| | String | Wrap code in a tag, instead of a . |ranges
| | Array | Ranges of line numbers to apply highlighting to. Requires highlightMode enabled |tokenizeVariables
| | Boolean | Match and render ReadMe variables in your markdown. |aspLanguages Supported
| Language | Available language mode(s) |
| :--- | :--- |
| ASP.NET | , aspx |c
| C | |c++
| C++ | , cpp, cplusplus |cs
| C# | , csharp |clj
| Clojure | , cljc, cljx, clojure |css
| CSS | , less, sass, scss, styl, stylus |curl
| cURL | |d
| D | |dart
| Dart | |dockerfile
| Docker | |erl
| Erlang | , erlang |go
| Go | |gql
| GraphQL | , graphql |gradle
| Groovy | , groovy |handlebars
| Handlebars | , hbs |html
| HTML/XML | , xhtml, xml |http
| HTTP | |java
| Java | |coffeescript
| JavaScript | , ecmascript, javascript, js, jsx, node |json
| JSON | |jl
| Julia | , julia |kotlin
| Kotlin | , kt |liquid
| Liquid | |markdown
| Markdown | |objc
| Objective-C | , objectivec, |objc++
| Objective-C++ | , objcpp, objectivecpp, objectivecplusplus, |ocaml
| OCaml | , ml |perl
| Perl | , pl |php
| PHP | |powershell
| PowerShell | , ps1 |py
| Python | , python |r
| R | |jsx
| React | |jruby
| Ruby | , macruby, rake, rb, rbx, ruby |rs
| Rust | , rust |scala
| Scala | |bash
| Shell | , sh, shell, zsh |cql
| SQL | , mssql, mysql, plsql, postgres, postgresql, pgsql, sql, sqlite |swift
| Swift | |toml
| TOML | |ts
| TypeScript | , typescript |yaml
| YAML | , yml` |
[codemirror]: https://github.com/codemirror/CodeMirror
[react-codemirror]: https://github.com/scniro/react-codemirror2
[react-codemirror#props]: https://github.com/scniro/react-codemirror2#props