From bf44f644fd66b688502320cf476e5f272329b77b Mon Sep 17 00:00:00 2001 From: sup39 Date: Tue, 22 Feb 2022 11:18:29 +0900 Subject: [PATCH] init --- .eslintrc.js | 7 + .gitignore | 1 + README.md | 39 ++++ index.js | 29 +++ jsconfig.json | 10 + package.json | 17 ++ yarn.lock | 570 ++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 673 insertions(+) create mode 100644 .eslintrc.js create mode 100644 .gitignore create mode 100644 README.md create mode 100644 index.js create mode 100644 jsconfig.json create mode 100644 package.json create mode 100644 yarn.lock diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..3e67a54 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + env: { + es2020: true, + node: true, + }, + extends: ['@sup39/basic'], +}; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..237064b --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# hljs-SunScript +[highlight.js](https://github.com/highlightjs/highlight.js) language definition for SunScript + +## Usage +```javascript +const hljs = require('highlight.js'); +const ss = require('@sup39/hljs-SunScript'); + +// register language +hljs.registerLanguage('SunScript', ss); +// register alias as needed +hljs.registerAliases(['sunscript', 'ss'], {languageName: 'SunScript'}); +``` + +## CSS +The following classes will be used for highlight: +- `.hljs-comment`: comments (`//`, `/* */`) +- `.hljs-keyword`: keywords (e.g. `var`, `if`) +- `.hljs-bracket`: `{`, `}`, and `(`, `)` after `if`, `for`, `while` +- `.hljs-number`: int, float, hex, address (e.g. `39`, `12.07`, `0xEC0`, `$80426428`) +- `.hljs-string`: single-quoted and double-quoted strings (e.g. `'SMS'`, `"サンシャイン"`) +- `.hljs-logical`: `&&` and `||` + +The following is an sample css for dark theme: +```css +.hljs-comment { + color: #7d6; +} +.hljs-keyword, .hljs-bracket { + color: #ffa; + font-weight: bold; +} +.hljs-number, .hljs-string { + color: #ffb7e7; +} +.hljs-logical { + color: #aff; +} +``` diff --git a/index.js b/index.js new file mode 100644 index 0000000..5109ab6 --- /dev/null +++ b/index.js @@ -0,0 +1,29 @@ +/** @param {import('highlight.js').default} hljs */ +module.exports = hljs => ({ + case_insensitive: false, + keywords: 'break continue return yield exit block unlock const var local import do while for else if function builtin', + contains: [ + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE, + hljs.QUOTE_STRING_MODE, + { + scope: 'string', + begin: /'/, + end: /'/, + illegal: '\\n', + contains: [{begin: /\\[\s\S]/, relevance: 0}], + }, + { + scope: 'bracket', + begin: /(?<=(if|for|while)\s*)\(|(\)\s*)?\{|\}/, + }, + { + scope: 'logical', + begin: /&&|\|\|/, + }, + { + scope: 'number', + begin: /(?