Skip to content

Commit

Permalink
feat: adding support for TOML highlighting (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion authored Oct 29, 2020
1 parent 543ca91 commit b2e617b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
7 changes: 7 additions & 0 deletions __tests__/__fixtures__/toml/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
language: 'TOML',
mode: {
primary: 'toml',
aliases: {},
},
};
33 changes: 33 additions & 0 deletions __tests__/__fixtures__/toml/sample.toml
Original file line number Diff line number Diff line change
@@ -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"
]
37 changes: 37 additions & 0 deletions __tests__/__snapshots__/codeMirror.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,43 @@ exports[`Supported languages Swift should syntax highlight an example 1`] = `
</div>"
`;
exports[`Supported languages TOML should syntax highlight an example 1`] = `
"<div class=\\"cm-s-neo\\"><span class=\\"cm-comment\\"># This is a TOML document.</span>
<span class=\\"cm-property\\">title</span> = <span class=\\"cm-string\\">&quot;TOML Example&quot;</span>
<span class=\\"cm-atom\\">[owner]</span>
<span class=\\"cm-property\\">name</span> = <span class=\\"cm-string\\">&quot;Tom Preston-Werner&quot;</span>
<span class=\\"cm-property\\">dob</span> = <span class=\\"cm-number\\">1979-05-27</span>T<span class=\\"cm-number\\">07</span>:<span class=\\"cm-number\\">32</span>:<span class=\\"cm-number\\">00-08</span>:<span class=\\"cm-number\\">00</span> <span class=\\"cm-comment\\"># First class dates</span>
<span class=\\"cm-atom\\">[database]</span>
<span class=\\"cm-property\\">server</span> = <span class=\\"cm-string\\">&quot;192.168.1.1&quot;</span>
<span class=\\"cm-property\\">ports</span> = <span class=\\"cm-bracket\\">[</span> <span class=\\"cm-number\\">8000</span>, <span class=\\"cm-number\\">8001</span>, <span class=\\"cm-number\\">8002</span> <span class=\\"cm-bracket\\">]</span>
<span class=\\"cm-property\\">connection_max</span> = <span class=\\"cm-number\\">5000</span>
<span class=\\"cm-property\\">enabled</span> = <span class=\\"cm-atom\\">true</span>
<span class=\\"cm-atom\\">[servers]</span>
<span class=\\"cm-comment\\"># Indentation (tabs and/or spaces) is allowed but not required</span>
<span class=\\"cm-atom\\">[servers.alpha]</span>
<span class=\\"cm-property\\">ip</span> = <span class=\\"cm-string\\">&quot;10.0.0.1&quot;</span>
<span class=\\"cm-property\\">dc</span> = <span class=\\"cm-string\\">&quot;eqdc10&quot;</span>
<span class=\\"cm-atom\\">[servers.beta]</span>
<span class=\\"cm-property\\">ip</span> = <span class=\\"cm-string\\">&quot;10.0.0.2&quot;</span>
<span class=\\"cm-property\\">dc</span> = <span class=\\"cm-string\\">&quot;eqdc10&quot;</span>
<span class=\\"cm-atom\\">[clients]</span>
<span class=\\"cm-property\\">data</span> = <span class=\\"cm-bracket\\">[</span> <span class=\\"cm-bracket\\">[</span><span class=\\"cm-string\\">&quot;gamma&quot;</span>, <span class=\\"cm-string\\">&quot;delta&quot;</span><span class=\\"cm-bracket\\">]</span>, <span class=\\"cm-bracket\\">[</span><span class=\\"cm-number\\">1</span>, <span class=\\"cm-number\\">2</span><span class=\\"cm-bracket\\">]</span> <span class=\\"cm-bracket\\">]</span>
<span class=\\"cm-comment\\"># Line breaks are OK when inside arrays</span>
<span class=\\"cm-property\\">hosts</span> = <span class=\\"cm-bracket\\">[</span>
<span class=\\"cm-string\\">&quot;alpha&quot;</span>,
<span class=\\"cm-string\\">&quot;omega&quot;</span>
<span class=\\"cm-bracket\\">]</span>
</div>"
`;
exports[`Supported languages TypeScript should syntax highlight an example 1`] = `
"<div class=\\"cm-s-neo\\"><span class=\\"cm-keyword\\">let</span> { <span class=\\"cm-def\\">a</span>, <span class=\\"cm-def\\">b</span> }: { <span class=\\"cm-property\\">a</span>: <span class=\\"cm-type\\">string</span>, <span class=\\"cm-property\\">b</span>: <span class=\\"cm-type\\">number</span> } <span class=\\"cm-operator\\">=</span> <span class=\\"cm-variable\\">o</span>;
</div>"
Expand Down
1 change: 1 addition & 0 deletions src/utils/cm-mode-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit b2e617b

Please sign in to comment.