Skip to content

add support for FreeDesktop config file #4299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3c87a29
add XDG Desktop shortcut file highlighter
gg582 Jul 28, 2025
4a9fba3
delete mimetype highlighter; it can't be distinguished from path easily
gg582 Jul 29, 2025
c9217bc
add wider highlighting for *.service
gg582 Jul 29, 2025
5829270
oneshot is sometimes OneShot
gg582 Jul 29, 2025
5ea1300
simple is too general keyword.
gg582 Jul 29, 2025
871b819
expand *.service support to desktop.js
gg582 Jul 29, 2025
70d7db8
it is a better idea to name it as a systemd format
gg582 Jul 30, 2025
03d19f5
Add = in front of a keyword highlighter
gg582 Jul 30, 2025
e218709
= is not interpreted by itself
gg582 Jul 30, 2025
09fcb99
= is not interpreted by itself
gg582 Jul 30, 2025
7395f5d
just move = outside of a group
gg582 Jul 30, 2025
d79bbf9
add contains attribute
gg582 Jul 30, 2025
7b0e71a
distinguishing normal text is puzzling
gg582 Jul 30, 2025
cdef708
removed \s. whitespace should be banned
gg582 Jul 30, 2025
064b2e5
trying value mode
gg582 Jul 30, 2025
9141242
priority problem is too difficult. I need to get some helps from a co…
gg582 Jul 30, 2025
61097c9
distinguish Type, Terminal, etc and match the right side
gg582 Jul 30, 2025
77c4b64
recover left side syntax highlighting
gg582 Jul 30, 2025
81178e9
this is really annoying. rules are conflicting
gg582 Jul 30, 2025
2463865
no, I don't want to highlight every keywords that are not in a position
gg582 Jul 30, 2025
cbed039
support Upper Camel case for Terminal;StartupNotify
gg582 Jul 30, 2025
86cf234
edit systemd format to match INI/TOML
gg582 Aug 2, 2025
e93595e
current highlighter gets too many colors
gg582 Aug 2, 2025
b68efaf
solving whole block highlighting bug
gg582 Aug 2, 2025
9bfef1c
FreeDesktop Configs don't use ; as a comment
gg582 Aug 2, 2025
825ab9d
change systemd.js to freedesktop.js
gg582 Aug 2, 2025
d513536
add omitted keyword for nmconnection
gg582 Aug 2, 2025
6a05f44
found typo that is marked as . instead of ','
gg582 Aug 2, 2025
4dd771b
add wider field codes
gg582 Aug 2, 2025
0998dce
trying to change appliance order to make %c work
gg582 Aug 2, 2025
90feb00
%c bugfix #1
gg582 Aug 2, 2025
32dd096
field code should be matched as 'begin'
gg582 Aug 2, 2025
9b7fde4
make field code to case insensitive one
gg582 Aug 2, 2025
01c0e5c
change field code's match group to key value
gg582 Aug 2, 2025
4f38e30
make field group's relevance to 1
gg582 Aug 2, 2025
83dcba6
match matches a group without considering location; so field codes sh…
gg582 Aug 2, 2025
dd46d3b
freedesktop.js: correct Match Logic
gg582 Aug 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/languages/freedesktop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Language: FreeDesktop Configs
Description: FreeDesktop Config Specification file format
Contributors: Lee Yunjin <[email protected]>
Category: common, config
Website: https://www.freedesktop.org/
*/
export default function(hljs) {
const FIELD_CODES = {
className: 'variable',
match: /%[a-zA-Z]/,
relevance: 1
};

const STRING = {
className: 'string',
begin: /"/,
end: /"/,
contains: [ hljs.BACKSLASH_ESCAPE ],
relevance: 0
};

const COMMENT = {
className: 'comment',
begin: /[#]/,
end: /$/,
relevance: 0
};

const SECTION = {
className: 'section',
begin: /^\[(Desktop Entry|Unit|Service|Install|Socket|Mount|Automount|Swap|Path|Timer|Slice|Scope|Manager|connection|ipv4|wifi|wifi-security|ipv6|802-3-ethernet|802-11-wireless|802-11-wireless-security|vpn|Journal|Bridge|Desktop Action\s+[A-Za-z0-9_-]+)\]$/,
relevance: 10
};

const KEY_NAME = {
className: 'attr',
begin: /^[A-Za-z0-9_-]+(\[[A-Za-z0-9_@.]+\])?/,
end: /\s*=/,
excludeEnd: true,
relevance: 10
};

const OPERATOR = {
className: 'operator',
match: /=/,
relevance: 0
};

const VALUE = {
begin: /=\s*/,
end: /$/,
excludeBegin: true,
contains: [
STRING,
{
className: 'literal',
match: /\b(Application|Link|Directory|forking|oneshot|OneShot|true|false|True|False)\b/,
relevance: 10
}
]
};

const KEY_VALUE = {
begin: /^([A-Za-z0-9_-]+(\[[A-Za-z0-9_@.]+\])?)\s*=/,
returnBegin: true,
contains: [
FIELD_CODES,
KEY_NAME,
OPERATOR,
VALUE
]
};

return {
name: 'FreeDesktop configuration format',
aliases: ['desktop', 'service', 'mount', 'socket', 'timer', 'nmconnection', 'systemd', 'freedesktop'],
case_insensitive: false,
contains: [
COMMENT,
SECTION,
KEY_VALUE
]
};
}