From b2e617b6f63d0de2f38eddc775bd755b26ff1425 Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Thu, 29 Oct 2020 11:58:39 -0700 Subject: [PATCH] feat: adding support for TOML highlighting (#26) --- README.md | 1 + __tests__/__fixtures__/toml/index.js | 7 ++++ __tests__/__fixtures__/toml/sample.toml | 33 +++++++++++++++++ .../__snapshots__/codeMirror.test.js.snap | 37 +++++++++++++++++++ src/utils/cm-mode-imports.js | 1 + 5 files changed, 79 insertions(+) create mode 100644 __tests__/__fixtures__/toml/index.js create mode 100644 __tests__/__fixtures__/toml/sample.toml diff --git a/README.md b/README.md index a562bb4..a25aa97 100644 --- a/README.md +++ b/README.md @@ -96,5 +96,6 @@ const ele = syntaxHighlighter('console.log("Hello, world!");', 'js', { ...opts, | Shell | `bash`, `sh`, `shell`, `zsh` | | SQL | `cql`, `mssql`, `mysql`, `plsql`, `postgres`, `postgresql`, `pgsql`, `sql`, `sqlite` | | Swift | `swift` | +| TOML | `toml` | | TypeScript | `ts`, `typescript` | | YAML | `yaml`, `yml` | diff --git a/__tests__/__fixtures__/toml/index.js b/__tests__/__fixtures__/toml/index.js new file mode 100644 index 0000000..7a8a1e1 --- /dev/null +++ b/__tests__/__fixtures__/toml/index.js @@ -0,0 +1,7 @@ +module.exports = { + language: 'TOML', + mode: { + primary: 'toml', + aliases: {}, + }, +}; diff --git a/__tests__/__fixtures__/toml/sample.toml b/__tests__/__fixtures__/toml/sample.toml new file mode 100644 index 0000000..175515a --- /dev/null +++ b/__tests__/__fixtures__/toml/sample.toml @@ -0,0 +1,33 @@ +# This is a TOML document. + +title = "TOML Example" + +[owner] +name = "Tom Preston-Werner" +dob = 1979-05-27T07:32:00-08:00 # First class dates + +[database] +server = "192.168.1.1" +ports = [ 8000, 8001, 8002 ] +connection_max = 5000 +enabled = true + +[servers] + + # Indentation (tabs and/or spaces) is allowed but not required + [servers.alpha] + ip = "10.0.0.1" + dc = "eqdc10" + + [servers.beta] + ip = "10.0.0.2" + dc = "eqdc10" + +[clients] +data = [ ["gamma", "delta"], [1, 2] ] + +# Line breaks are OK when inside arrays +hosts = [ + "alpha", + "omega" +] diff --git a/__tests__/__snapshots__/codeMirror.test.js.snap b/__tests__/__snapshots__/codeMirror.test.js.snap index 3312f68..a53131d 100644 --- a/__tests__/__snapshots__/codeMirror.test.js.snap +++ b/__tests__/__snapshots__/codeMirror.test.js.snap @@ -287,6 +287,43 @@ exports[`Supported languages Swift should syntax highlight an example 1`] = ` " `; +exports[`Supported languages TOML should syntax highlight an example 1`] = ` +"
# This is a TOML document. + +title = "TOML Example" + +[owner] +name = "Tom Preston-Werner" +dob = 1979-05-27T07:32:00-08:00 # First class dates + +[database] +server = "192.168.1.1" +ports = [ 8000, 8001, 8002 ] +connection_max = 5000 +enabled = true + +[servers] + + # Indentation (tabs and/or spaces) is allowed but not required + [servers.alpha] + ip = "10.0.0.1" + dc = "eqdc10" + + [servers.beta] + ip = "10.0.0.2" + dc = "eqdc10" + +[clients] +data = [ ["gamma", "delta"], [1, 2] ] + +# Line breaks are OK when inside arrays +hosts = [ + "alpha", + "omega" +] +
" +`; + exports[`Supported languages TypeScript should syntax highlight an example 1`] = ` "
let { a, b }: { a: string, b: number } = o;
" diff --git a/src/utils/cm-mode-imports.js b/src/utils/cm-mode-imports.js index bd09114..d5f7b42 100644 --- a/src/utils/cm-mode-imports.js +++ b/src/utils/cm-mode-imports.js @@ -21,4 +21,5 @@ require('codemirror/mode/rust/rust'); require('codemirror/mode/shell/shell'); require('codemirror/mode/sql/sql'); require('codemirror/mode/swift/swift'); +require('codemirror/mode/toml/toml'); require('codemirror/mode/yaml/yaml');