Skip to content

Commit 3c87a29

Browse files
committed
add XDG Desktop shortcut file highlighter
1 parent 5697ae5 commit 3c87a29

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

src/languages/desktop.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Language: XDGDesktop
3+
Description: XDG Desktop Entry Specification file format.
4+
Contributors: Lee Yunjin <[email protected]>
5+
Category: common, config
6+
Website: https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/
7+
*/
8+
9+
export default function(hljs) {
10+
const LITERALS = {
11+
className: 'literal',
12+
begin: /\b(true|false|Application|Link|Directory)\b/,
13+
relevance: 0
14+
};
15+
16+
const FIELD_CODES = {
17+
className: 'variable',
18+
match: /%[fFuUcCiIkKvV]/
19+
};
20+
21+
const QUOTED_STRING = {
22+
className: 'string',
23+
begin: /"/,
24+
end: /"/,
25+
contains: [ hljs.BACKSLASH_ESCAPE ],
26+
relevance: 0
27+
};
28+
29+
const COMMENT_MODE = {
30+
className: 'comment',
31+
begin: /#/,
32+
end: /$/,
33+
relevance: 0
34+
};
35+
36+
const SECTION_HEADER = {
37+
className: 'section',
38+
begin: /^\[(Desktop Entry|Desktop Action\s+[A-Za-z0-9_-]+)\]/,
39+
relevance: 10
40+
};
41+
42+
const MIMETYPE_FORMAT = {
43+
className: 'type',
44+
match: /\b[a-zA-Z0-9_.+-]+\/[a-zA-Z0-9_.+-]+/,
45+
relevance: 0
46+
};
47+
48+
const KEY_VALUE_PAIR = {
49+
begin: /^[A-Za-z0-9_-]+(\[[A-Za-z0-9_@.]+\])?\s*=/,
50+
end: /$/,
51+
returnBegin: true,
52+
contains: [
53+
{
54+
className: 'attribute',
55+
begin: /^[A-Za-z0-9_-]+(\[[A-Za-z0-9_@.]+\])?/,
56+
relevance: 10
57+
},
58+
{
59+
className: 'operator',
60+
match: /=/,
61+
relevance: 0
62+
},
63+
COMMENT_MODE,
64+
LITERALS,
65+
QUOTED_STRING,
66+
FIELD_CODES,
67+
MIMETYPE_FORMAT,
68+
{
69+
className: 'punctuation',
70+
match: /;/,
71+
relevance: 0
72+
}
73+
]
74+
};
75+
76+
return {
77+
name: 'Desktop',
78+
aliases: ['desktop'],
79+
case_insensitive: false,
80+
contains: [
81+
COMMENT_MODE,
82+
SECTION_HEADER,
83+
KEY_VALUE_PAIR
84+
]
85+
};
86+
}
87+

0 commit comments

Comments
 (0)