mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
Add Prism.js and highlight.js syntax highlight definitions
This commit is contained in:
parent
f575b43b51
commit
bd836c868a
@ -5,3 +5,11 @@
|
|||||||
1. Open an `idea` folder
|
1. Open an `idea` folder
|
||||||
2. Add all files and folders to zip archive, e.g. `settings.zip`
|
2. Add all files and folders to zip archive, e.g. `settings.zip`
|
||||||
3. File -> Manage IDE Settings -> Import. Select your zip file.
|
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
44
editors/highlighjs/own.js
Normal 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
|
||||||
|
]
|
||||||
|
};
|
||||||
|
};
|
@ -13,7 +13,7 @@
|
|||||||
</options>
|
</options>
|
||||||
<keywords keywords="break;case;class;continue;def;do;else;extract;for;if;match;new;print;println;return;while" ignore_case="false" />
|
<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" />
|
<keywords2 keywords="echo;newarray;try" />
|
||||||
<keywords3 keywords="false;this;true" />
|
<keywords3 keywords="false;null;this;true" />
|
||||||
<keywords4 keywords="include;use" />
|
<keywords4 keywords="include;use" />
|
||||||
</highlighting>
|
</highlighting>
|
||||||
<extensionMap>
|
<extensionMap>
|
||||||
|
19
editors/prismjs/own-language.js
Normal file
19
editors/prismjs/own-language.js
Normal 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': /[{}[\];(),.:`]/
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user