Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8df825e

Browse filesBrowse files
Added support for Systemd configuration files (#3053)
1 parent 87e5a37 commit 8df825e
Copy full SHA for 8df825e

File tree

Expand file treeCollapse file tree

12 files changed

+226
-2
lines changed
Filter options
Expand file treeCollapse file tree

12 files changed

+226
-2
lines changed

‎components.js

Copy file name to clipboardExpand all lines: components.js
+1-1Lines 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

Copy file name to clipboardExpand all lines: components.json
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,10 @@
12331233
"title": "Swift",
12341234
"owner": "chrischares"
12351235
},
1236+
"systemd": {
1237+
"title": "Systemd configuration file",
1238+
"owner": "RunDevelopment"
1239+
},
12361240
"t4-templating": {
12371241
"title": "T4 templating",
12381242
"owner": "RunDevelopment"

‎components/prism-systemd.js

Copy file name to clipboard
+74Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// https://www.freedesktop.org/software/systemd/man/systemd.syntax.html
2+
3+
(function (Prism) {
4+
5+
var comment = {
6+
pattern: /^[;#].*/m,
7+
greedy: true
8+
};
9+
10+
var quotesSource = /"(?:[^\r\n"\\]|\\(?:[^\r]|\r\n?))*"(?!\S)/.source;
11+
12+
Prism.languages.systemd = {
13+
'comment': comment,
14+
15+
'section': {
16+
pattern: /^\[[^\n\r\[\]]*\](?=[ \t]*$)/m,
17+
greedy: true,
18+
inside: {
19+
'punctuation': /^\[|\]$/,
20+
'section-name': {
21+
pattern: /[\s\S]+/,
22+
alias: 'selector'
23+
},
24+
}
25+
},
26+
27+
'key': {
28+
pattern: /^[^\s=]+(?=[ \t]*=)/m,
29+
greedy: true,
30+
alias: 'attr-name'
31+
},
32+
'value': {
33+
// This pattern is quite complex because of two properties:
34+
// 1) Quotes (strings) must be preceded by a space. Since we can't use lookbehinds, we have to "resolve"
35+
// the lookbehind. You will see this in the main loop where spaces are handled separately.
36+
// 2) Line continuations.
37+
// After line continuations, empty lines and comments are ignored so we have to consume them.
38+
pattern: RegExp(
39+
/(=[ \t]*(?!\s))/.source +
40+
// the value either starts with quotes or not
41+
'(?:' + quotesSource + '|(?=[^"\r\n]))' +
42+
// main loop
43+
'(?:' + (
44+
/[^\s\\]/.source +
45+
// handle spaces separately because of quotes
46+
'|' + '[ \t]+(?:(?![ \t"])|' + quotesSource + ')' +
47+
// line continuation
48+
'|' + /\\[\r\n]+(?:[#;].*[\r\n]+)*(?![#;])/.source
49+
) +
50+
')*'
51+
),
52+
lookbehind: true,
53+
greedy: true,
54+
alias: 'attr-value',
55+
inside: {
56+
'comment': comment,
57+
'quoted': {
58+
pattern: RegExp(/(^|\s)/.source + quotesSource),
59+
lookbehind: true,
60+
greedy: true,
61+
},
62+
'punctuation': /\\$/m,
63+
64+
'boolean': {
65+
pattern: /^(?:false|no|off|on|true|yes)$/,
66+
greedy: true
67+
}
68+
}
69+
},
70+
71+
'operator': /=/
72+
};
73+
74+
}(Prism));

‎components/prism-systemd.min.js

Copy file name to clipboardExpand all lines: components/prism-systemd.min.js
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-systemd.html

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h2>Full example</h2>
2+
<pre><code># Source: https://www.freedesktop.org/software/systemd/man/systemd.syntax.html
3+
4+
[Section A]
5+
KeyOne=value 1
6+
KeyTwo=value 2
7+
8+
# a comment
9+
10+
[Section B]
11+
Setting="something" "some thing" "…"
12+
KeyTwo=value 2 \
13+
value 2 continued
14+
15+
[Section C]
16+
KeyThree=value 3\
17+
# this line is ignored
18+
; this line is ignored too
19+
value 3 continued
20+
</code></pre>

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

Copy file name to clipboardExpand all lines: plugins/show-language/prism-show-language.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
"sqf": "SQF: Status Quo Function (Arma 3)",
213213
"sql": "SQL",
214214
"iecst": "Structured Text (IEC 61131-3)",
215+
"systemd": "Systemd configuration file",
215216
"t4-templating": "T4 templating",
216217
"t4-cs": "T4 Text Templates (C#)",
217218
"t4": "T4 Text Templates (C#)",

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

Copy file name to clipboardExpand all lines: plugins/show-language/prism-show-language.min.js
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+46Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
foo=on
2+
foo=true
3+
foo=yes
4+
foo=off
5+
foo=false
6+
foo=no
7+
8+
----------------------------------------------------
9+
10+
[
11+
["key", "foo"],
12+
["operator", "="],
13+
["value", [
14+
["boolean", "on"]
15+
]],
16+
17+
["key", "foo"],
18+
["operator", "="],
19+
["value", [
20+
["boolean", "true"]
21+
]],
22+
23+
["key", "foo"],
24+
["operator", "="],
25+
["value", [
26+
["boolean", "yes"]
27+
]],
28+
29+
["key", "foo"],
30+
["operator", "="],
31+
["value", [
32+
["boolean", "off"]
33+
]],
34+
35+
["key", "foo"],
36+
["operator", "="],
37+
["value", [
38+
["boolean", "false"]
39+
]],
40+
41+
["key", "foo"],
42+
["operator", "="],
43+
["value", [
44+
["boolean", "no"]
45+
]]
46+
]
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# comment
2+
; comment
3+
4+
----------------------------------------------------
5+
6+
[
7+
["comment", "# comment"],
8+
["comment", "; comment"]
9+
]
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
foo=
2+
foo =
3+
4+
----------------------------------------------------
5+
6+
[
7+
["key", "foo"], ["operator", "="],
8+
["key", "foo"], ["operator", "="]
9+
]
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Section Foo]
2+
3+
----------------------------------------------------
4+
5+
[
6+
["section", [
7+
["punctuation", "["],
8+
["section-name", "Section Foo"],
9+
["punctuation", "]"]
10+
]]
11+
]
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
foo= value 2
2+
3+
foo="something" "some thing" "…"
4+
foo= "something" "some thing" "…"
5+
foo=value 2 \
6+
value 2 continued
7+
8+
foo=value 3\
9+
# this line is ignored
10+
; this line is ignored too
11+
value 3 continued
12+
13+
----------------------------------------------------
14+
15+
[
16+
["key", "foo"], ["operator", "="], ["value", ["value 2"]],
17+
18+
["key", "foo"],
19+
["operator", "="],
20+
["value", [
21+
["quoted", "\"something\""],
22+
["quoted", "\"some thing\""],
23+
["quoted", "\"…\""]
24+
]],
25+
26+
["key", "foo"],
27+
["operator", "="],
28+
["value", [
29+
["quoted", "\"something\""],
30+
["quoted", "\"some thing\""],
31+
["quoted", "\"…\""]
32+
]],
33+
34+
["key", "foo"],
35+
["operator", "="],
36+
["value", [
37+
"value 2 ", ["punctuation", "\\"],
38+
"\r\n value 2 continued"
39+
]],
40+
41+
["key", "foo"],
42+
["operator", "="],
43+
["value", [
44+
"value 3", ["punctuation", "\\"],
45+
["comment", "# this line is ignored"],
46+
["comment", "; this line is ignored too"],
47+
"\r\n value 3 continued"
48+
]]
49+
]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.