-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup, improve article parsing, add terminal grammar
- Loading branch information
Showing
10 changed files
with
138 additions
and
9 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules/ | |
app.config.timestamp* | ||
input/ | ||
generated/ | ||
*.bundled_*.mjs |
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
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { ShikiTransformer } from "@shikijs/core"; | ||
import type { Element } from "hast"; | ||
|
||
export interface shikiColorNotationOptions { | ||
colors?: string[]; | ||
} | ||
|
||
type MetaNode = Element & { meta?: Record<string, any> }; | ||
|
||
export function shikiColorNotation( | ||
options: shikiColorNotationOptions = {} | ||
): ShikiTransformer { | ||
const { colors = ["red", "blue", "green", "orange", "gray"] } = options; | ||
|
||
return { | ||
name: "shiki-color-notation", | ||
code(node: MetaNode) { | ||
if (!node.meta?.colors) return; | ||
|
||
const lines = node.children.filter( | ||
(node) => node.type === "element" | ||
) as Element[]; | ||
|
||
lines.forEach((line) => { | ||
for (let i = 0; i < line.children.length; i++) { | ||
const child = line.children[i]; | ||
|
||
if (child.type !== "element") continue; | ||
const text = child.children[0]; | ||
if (text.type !== "text") continue; | ||
|
||
const m = /(.*)%(.+)%(.*)%\2%(.*)/.exec(text.value); | ||
|
||
if (!m) continue; | ||
|
||
const [raw, before, color, inner, after] = m; | ||
|
||
if (colors.includes(color)) { | ||
text.value = inner; | ||
|
||
if (inner) { | ||
child.properties.class = `color-${color}`; | ||
} | ||
|
||
if (after) { | ||
line.children.splice(i + 1, 0, { | ||
type: "element", | ||
tagName: "span", | ||
properties: {}, | ||
children: [{ type: "text", value: after }], | ||
}); | ||
} | ||
|
||
if (before) { | ||
line.children.splice(i, 0, { | ||
type: "element", | ||
tagName: "span", | ||
properties: {}, | ||
children: [{ type: "text", value: before }], | ||
}); | ||
i--; | ||
} | ||
} | ||
} | ||
}); | ||
}, | ||
}; | ||
} |
File renamed without changes.
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,24 @@ | ||
{ | ||
"displayName": "Terminal", | ||
"name": "terminal", | ||
"patterns": [ | ||
{ | ||
"include": "#prompt" | ||
} | ||
], | ||
"repository": { | ||
"prompt": { | ||
"begin": "^\\[", | ||
"end": "\\]# ([^ ]+)", | ||
"beginCaptures": { | ||
"0": { "name": "string" } | ||
}, | ||
"endCaptures": { | ||
"0": { "name": "string" }, | ||
"1": { "name": "variable" } | ||
}, | ||
"name": "variable" | ||
} | ||
}, | ||
"scopeName": "text.colors" | ||
} |
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