diff --git a/editors/README.md b/editors/README.md index 2c52659..9d41cb8 100644 --- a/editors/README.md +++ b/editors/README.md @@ -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) +``` diff --git a/editors/highlighjs/own.js b/editors/highlighjs/own.js new file mode 100644 index 0000000..309ce06 --- /dev/null +++ b/editors/highlighjs/own.js @@ -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 + ] + }; +}; \ No newline at end of file diff --git a/editors/idea/filetypes/OwnLang.xml b/editors/idea/filetypes/OwnLang.xml index 324962e..af5ab47 100644 --- a/editors/idea/filetypes/OwnLang.xml +++ b/editors/idea/filetypes/OwnLang.xml @@ -13,7 +13,7 @@ - + diff --git a/editors/prismjs/own-language.js b/editors/prismjs/own-language.js new file mode 100644 index 0000000..d12c786 --- /dev/null +++ b/editors/prismjs/own-language.js @@ -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': /[{}[\];(),.:`]/ + }); +} \ No newline at end of file