Add Prism.js and highlight.js syntax highlight definitions

This commit is contained in:
aNNiMON 2023-11-15 21:16:08 +02:00 committed by Victor Melnik
parent f575b43b51
commit bd836c868a
4 changed files with 72 additions and 1 deletions

View File

@ -5,3 +5,11 @@
1. Open an `idea` folder
2. Add all files and folders to zip archive, e.g. `settings.zip`
3. File -> Manage IDE Settings -> Import. Select your zip file.
## Prism.js
```javascript
import Prism from 'prismjs';
import definePrismOwnLang from './prismjs/own-language.js'
definePrismOwnLang(Prism)
```

44
editors/highlighjs/own.js Normal file
View File

@ -0,0 +1,44 @@
export default function(hljs) {
const STRING = {
className: 'string',
variants: [{
begin: '"', end: '"',
contains: [hljs.BACKSLASH_ESCAPE]
}]
};
const EXTENDED_LITERAL = {
className: 'literal',
variants: [{
begin: '`', end: '`',
illegal: '\\n'
}]
};
const METHOD = {
className: 'function',
beginKeywords: 'def',
end: /[:={\[(\n;]/,
excludeEnd: true,
contains: [{
className: 'title',
begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,
relevance: 0
}]
};
return {
keywords: {
literal: 'true false this null',
keyword: 'break class continue def else for if match print println return use while do case extract include'
},
contains: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
STRING,
EXTENDED_LITERAL,
METHOD,
hljs.C_NUMBER_MODE
]
};
};

View File

@ -13,7 +13,7 @@
</options>
<keywords keywords="break;case;class;continue;def;do;else;extract;for;if;match;new;print;println;return;while" ignore_case="false" />
<keywords2 keywords="echo;newarray;try" />
<keywords3 keywords="false;this;true" />
<keywords3 keywords="false;null;this;true" />
<keywords4 keywords="include;use" />
</highlighting>
<extensionMap>

View File

@ -0,0 +1,19 @@
export default function(Prism) {
Prism.languages.own = Prism.languages.extend('clike', {
'string': {
pattern: /(^|[^\\])"(?:\\.|[^"\\])*"/,
lookbehind: true,
greedy: true
},
'keyword': /\b(?:break|case|class|continue|def|do|else|extract|for|if|include|match|new|print|println|return|while|use)\b/,
'function': {
pattern: /((?:^|\s)def\s*)([a-zA-Z_]\w*)?(?=\s*\()/g,
lookbehind: true
},
'operator': {
pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\*\*|\|\||::|\.\.\.?|[?:~]|[-+*/%&|^!=<>]=?)/m,
lookbehind: true
},
'punctuation': /[{}[\];(),.:`]/
});
}