-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust the highlighting component of mdbook to get syntax highlighting for the Stef schema files. As a nice side effect, remove any unused languages from the highlighter to reduce the file size.
- Loading branch information
Showing
27 changed files
with
704 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules | ||
/target | ||
.lycheecache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/book | ||
/theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.3.3/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"formatter": { | ||
"indentStyle": "space", | ||
"indentWidth": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "highlight", | ||
"private": true, | ||
"scripts": { | ||
"esbuild": "esbuild src/*.{css,ts} --outdir=../theme --target=es2016 --global-name=hljs --legal-comments=none --bundle", | ||
"watch": "pnpm run esbuild --watch", | ||
"build": "pnpm run esbuild --minify", | ||
"lint": "biome check --apply src/**/*.ts" | ||
}, | ||
"dependencies": { | ||
"highlight.js": "^11.9.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.3.3", | ||
"esbuild": "^0.19.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
@import "./css/overrides.css"; | ||
|
||
/* | ||
Based off of the Ayu theme | ||
Original by Dempfi (https://github.com/dempfi/ayu) | ||
*/ | ||
|
||
.hljs { | ||
display: block; | ||
overflow-x: auto; | ||
background: #191f26; | ||
color: #e6e1cf; | ||
} | ||
|
||
.hljs-comment, | ||
.hljs-quote { | ||
color: #5c6773; | ||
font-style: italic; | ||
} | ||
|
||
.hljs-variable, | ||
.hljs-template-variable, | ||
.hljs-attribute, | ||
.hljs-attr, | ||
.hljs-regexp, | ||
.hljs-link, | ||
.hljs-selector-id, | ||
.hljs-selector-class { | ||
color: #ff7733; | ||
} | ||
|
||
.hljs-number, | ||
.hljs-meta, | ||
.hljs-builtin-name, | ||
.hljs-literal, | ||
.hljs-type, | ||
.hljs-params { | ||
color: #ffee99; | ||
} | ||
|
||
.hljs-string, | ||
.hljs-bullet { | ||
color: #b8cc52; | ||
} | ||
|
||
.hljs-title, | ||
.hljs-built_in, | ||
.hljs-section { | ||
color: #ffb454; | ||
} | ||
|
||
.hljs-keyword, | ||
.hljs-selector-tag, | ||
.hljs-symbol { | ||
color: #ff7733; | ||
} | ||
|
||
.hljs-name { | ||
color: #36a3d9; | ||
} | ||
|
||
.hljs-tag { | ||
color: #00568d; | ||
} | ||
|
||
.hljs-emphasis { | ||
font-style: italic; | ||
} | ||
|
||
.hljs-strong { | ||
font-weight: bold; | ||
} | ||
|
||
.hljs-addition { | ||
color: #91b362; | ||
} | ||
|
||
.hljs-deletion { | ||
color: #d96c75; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pre { | ||
tab-size: 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@import "./css/overrides.css"; | ||
|
||
/* | ||
* An increased contrast highlighting scheme loosely based on the | ||
* "Base16 Atelier Dune Light" theme by Bram de Haan | ||
* (http://atelierbram.github.io/syntax-highlighting/atelier-schemes/dune) | ||
* Original Base16 color scheme by Chris Kempson | ||
* (https://github.com/chriskempson/base16) | ||
*/ | ||
|
||
/* Comment */ | ||
.hljs-comment, | ||
.hljs-quote { | ||
color: #575757; | ||
} | ||
|
||
/* Red */ | ||
.hljs-variable, | ||
.hljs-template-variable, | ||
.hljs-attribute, | ||
.hljs-tag, | ||
.hljs-name, | ||
.hljs-regexp, | ||
.hljs-link, | ||
.hljs-name, | ||
.hljs-selector-id, | ||
.hljs-selector-class { | ||
color: #d70025; | ||
} | ||
|
||
/* Orange */ | ||
.hljs-number, | ||
.hljs-meta, | ||
.hljs-built_in, | ||
.hljs-builtin-name, | ||
.hljs-literal, | ||
.hljs-type, | ||
.hljs-params { | ||
color: #b21e00; | ||
} | ||
|
||
/* Green */ | ||
.hljs-string, | ||
.hljs-symbol, | ||
.hljs-bullet { | ||
color: #008200; | ||
} | ||
|
||
/* Blue */ | ||
.hljs-title, | ||
.hljs-section { | ||
color: #0030f2; | ||
} | ||
|
||
/* Purple */ | ||
.hljs-keyword, | ||
.hljs-selector-tag { | ||
color: #9d00ec; | ||
} | ||
|
||
.hljs { | ||
display: block; | ||
overflow-x: auto; | ||
background: #f6f7f6; | ||
color: #000; | ||
} | ||
|
||
.hljs-emphasis { | ||
font-style: italic; | ||
} | ||
|
||
.hljs-strong { | ||
font-weight: bold; | ||
} | ||
|
||
.hljs-addition { | ||
color: #22863a; | ||
background-color: #f0fff4; | ||
} | ||
|
||
.hljs-deletion { | ||
color: #b31d28; | ||
background-color: #ffeef0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { HLJSOptions } from "highlight.js"; | ||
import hljs from "highlight.js/lib/core"; | ||
import bash from "highlight.js/lib/languages/bash"; | ||
import go from "highlight.js/lib/languages/go"; | ||
import kotlin from "highlight.js/lib/languages/kotlin"; | ||
import python from "highlight.js/lib/languages/python"; | ||
import rust from "highlight.js/lib/languages/rust"; | ||
import toml from "highlight.js/lib/languages/ini"; | ||
import typescript from "highlight.js/lib/languages/typescript"; | ||
import { stef } from "./languages/stef"; | ||
|
||
hljs.registerLanguage("bash", bash); | ||
hljs.registerLanguage("go", go); | ||
hljs.registerLanguage("kotlin", kotlin); | ||
hljs.registerLanguage("python", python); | ||
hljs.registerLanguage("rust", rust); | ||
hljs.registerLanguage("toml", toml); | ||
hljs.registerLanguage("typescript", typescript); | ||
|
||
hljs.registerLanguage("stef", stef); | ||
|
||
export function configure(options: Partial<HLJSOptions>) { | ||
hljs.configure(options); | ||
} | ||
|
||
export function highlightBlock(element: HTMLElement) { | ||
hljs.highlightElement(element); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
Language: Stef | ||
Author: Dominik Nakamura <dnaka91@gmail.com> | ||
Category: common, system | ||
*/ | ||
|
||
import { HLJSApi, Language } from "highlight.js"; | ||
|
||
export function stef(hljs: HLJSApi): Language { | ||
const KEYWORDS = ["mod", "struct", "enum", "const", "type", "use"]; | ||
const LITERALS = ["true", "false"]; | ||
const TYPES = [ | ||
"bool", | ||
"u8", | ||
"u16", | ||
"u32", | ||
"u64", | ||
"u128", | ||
"i8", | ||
"i16", | ||
"i32", | ||
"i64", | ||
"i128", | ||
"f32", | ||
"f64", | ||
"string", | ||
"bytes", | ||
"box", | ||
"vec", | ||
"hash_map", | ||
"hash_set", | ||
"option", | ||
"non_zero", | ||
]; | ||
return { | ||
name: "Stef", | ||
keywords: { | ||
type: TYPES, | ||
keyword: KEYWORDS, | ||
literal: LITERALS, | ||
}, | ||
illegal: "</", | ||
contains: [ | ||
hljs.C_LINE_COMMENT_MODE, | ||
hljs.COMMENT("///", /\n/, {}), | ||
hljs.inherit(hljs.QUOTE_STRING_MODE, { | ||
begin: /b?"/, | ||
illegal: null, | ||
}), | ||
{ | ||
scope: "string", | ||
variants: [ | ||
{ begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ }, | ||
{ begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ }, | ||
], | ||
}, | ||
{ | ||
scope: "symbol", | ||
match: /'[a-zA-Z_][a-zA-Z0-9_]*/, | ||
}, | ||
{ | ||
scope: "number", | ||
variants: [{ begin: /\b(\d+(\.[0-9]+)?)/ }], | ||
relevance: 0, | ||
}, | ||
{ | ||
scope: "meta", | ||
begin: "#!?\\[", | ||
end: "\\]", | ||
contains: [ | ||
{ | ||
className: "string", | ||
begin: /"/, | ||
end: /"/, | ||
}, | ||
], | ||
}, | ||
{ | ||
match: [/(?:enum|struct|type)/, /\s+/, /[a-zA-Z0-9_]+/], | ||
scope: { | ||
1: "keyword", | ||
3: "title.class", | ||
}, | ||
}, | ||
{ | ||
match: ["const", /\s+/, /[a-zA-Z0-9_]+/], | ||
scope: { | ||
1: "keyword", | ||
3: "variable.constant", | ||
}, | ||
}, | ||
{ | ||
match: [/[a-z0-9_]+/, ":", /[a-zA-Z0-9_<>:,& ]+/, /@\d+/, /,?/], | ||
scope: { | ||
1: "attr", | ||
2: "punctuation", | ||
3: "type", | ||
4: "symbol", | ||
5: "punctuation", | ||
}, | ||
relevance: 2, | ||
}, | ||
{ | ||
match: [/[a-zA-Z0-9_<>,& ]+/, /@\d+/, /,?/], | ||
scope: { | ||
1: "type", | ||
2: "symbol", | ||
3: "punctuation", | ||
}, | ||
relevance: 1, | ||
}, | ||
{ | ||
match: `${hljs.IDENT_RE}::`, | ||
keywords: { | ||
type: TYPES, | ||
}, | ||
}, | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import "highlight.js/styles/tokyo-night-dark.css"; | ||
@import "./css/overrides.css"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Examples | ||
|
||
```rust,ignore | ||
```stef | ||
{{#include examples/01.stef}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.