Skip to content

Commit 5b6ad70

Browse files
RunDevelopmentmAAdhaTTah
authored andcommitted
Add TOML support (#1488)
Add support for [Tom's Obvious, Minimal Language](https://github.com/toml-lang/toml). Some simplifications: 1. The `.`s of dotted keys are not highlighted. This is because the `.` could be inside quotes and checking that isn't easy. 2. There is no distinction between table `[foo]` and array `[[foo]]`. `foo` will be highlighted as `table` in both cases.
1 parent 2577b6e commit 5b6ad70

File tree

13 files changed

+278
-3
lines changed

13 files changed

+278
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@
731731
"peerDependencies": "css",
732732
"owner": "Golmote"
733733
},
734+
"toml": {
735+
"title": "TOML",
736+
"owner": "RunDevelopment"
737+
},
734738
"tt2": {
735739
"title": "Template Toolkit 2",
736740
"require": ["clike", "markup-templating"],

components/prism-toml.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(function (Prism) {
2+
3+
// pattern: /(?:[\w-]+|'[^'\n\r]*'|"(?:\.|[^\\"\r\n])*")/
4+
var key = "(?:[\\w-]+|'[^'\n\r]*'|\"(?:\\.|[^\\\\\"\r\n])*\")";
5+
6+
Prism.languages.toml = {
7+
'comment': {
8+
pattern: /#.*/,
9+
greedy: true
10+
},
11+
'table': {
12+
pattern: RegExp("(\\[\\s*)" + key + "(?:\\s*\\.\\s*" + key + ")*(?=\\s*\\])"),
13+
lookbehind: true,
14+
greedy: true,
15+
alias: 'class-name'
16+
},
17+
'key': {
18+
pattern: RegExp("(^\\s*|[{,]\\s*)" + key + "(?:\\s*\\.\\s*" + key + ")*(?=\\s*=)", "m"),
19+
lookbehind: true,
20+
greedy: true,
21+
alias: 'property'
22+
},
23+
'string': {
24+
pattern: /"""(?:\\[\s\S]|[^\\])*?"""|'''[\s\S]*?'''|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*"/,
25+
greedy: true
26+
},
27+
'date': [
28+
{
29+
// Offset Date-Time, Local Date-Time, Local Date
30+
pattern: /\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?/i,
31+
alias: 'number'
32+
},
33+
{
34+
// Local Time
35+
pattern: /\d{2}:\d{2}:\d{2}(?:\.\d+)?/i,
36+
alias: 'number'
37+
}
38+
],
39+
'number': /(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?(?:inf|nan)\b/,
40+
'boolean': /\b(?:true|false)\b/,
41+
'punctuation': /[.,=[\]{}]/
42+
};
43+
}(Prism));

components/prism-toml.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
14+
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

plugins/show-language/prism-show-language.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for booleans.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# I'm a comment, you're not.
2+
3+
----------------------------------------------------
4+
5+
[
6+
["comment", "# I'm a comment, you're not."]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks for comments.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
1979-05-27T07:32:00Z
2+
1979-05-27T00:32:00-07:00
3+
1979-05-27T00:32:00.999999-07:00
4+
1979-05-27 07:32:00Z
5+
6+
1979-05-27T07:32:00
7+
1979-05-27T00:32:00.999999
8+
9+
1979-05-27
10+
11+
07:32:00
12+
00:32:00.999999
13+
14+
----------------------------------------------------
15+
16+
[
17+
["date", "1979-05-27T07:32:00Z"],
18+
["date", "1979-05-27T00:32:00-07:00"],
19+
["date", "1979-05-27T00:32:00.999999-07:00"],
20+
["date", "1979-05-27 07:32:00Z"],
21+
22+
["date", "1979-05-27T07:32:00"],
23+
["date", "1979-05-27T00:32:00.999999"],
24+
25+
["date", "1979-05-27"],
26+
27+
["date", "07:32:00"],
28+
["date", "00:32:00.999999"]
29+
]
30+
31+
----------------------------------------------------
32+
33+
Checks for dates.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
abc = "abc"
2+
"abc" = "abc"
3+
"abc".'a"b"c'.abc = "abc"
4+
a . b . c = "abc"
5+
6+
a = { b = "b", c = "c" }
7+
8+
----------------------------------------------------
9+
10+
[
11+
["key", "abc"],
12+
["punctuation", "="],
13+
["string", "\"abc\""],
14+
15+
["key", "\"abc\""],
16+
["punctuation", "="],
17+
["string", "\"abc\""],
18+
19+
["key", "\"abc\".'a\"b\"c'.abc"],
20+
["punctuation", "="],
21+
["string", "\"abc\""],
22+
23+
["key", "a . b . c"],
24+
["punctuation", "="],
25+
["string", "\"abc\""],
26+
27+
["key", "a"],
28+
["punctuation", "="],
29+
["punctuation", "{"],
30+
["key", "b"],
31+
["punctuation", "="],
32+
["string", "\"b\""],
33+
["punctuation", ","],
34+
["key", "c"],
35+
["punctuation", "="],
36+
["string", "\"c\""],
37+
["punctuation", "}"]
38+
]
39+
40+
----------------------------------------------------
41+
42+
Checks for keys.

0 commit comments

Comments
 (0)