mirror of
https://github.com/sern-handler/website
synced 2026-06-22 15:52:30 +00:00
feat: migrate to starlight
This commit is contained in:
21
node_modules/rehype-expressive-code/LICENSE
generated
vendored
Normal file
21
node_modules/rehype-expressive-code/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Tibor Schiemann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
15
node_modules/rehype-expressive-code/README.md
generated
vendored
Normal file
15
node_modules/rehype-expressive-code/README.md
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# rehype-expressive-code [](https://www.npmjs.com/package/rehype-expressive-code) [](https://npmjs.org/package/rehype-expressive-code)
|
||||
|
||||
This package is a [unified](https://github.com/unifiedjs/unified) ([rehype](https://github.com/rehypejs/rehype)) plugin to automatically render code blocks in your markdown / MDX documents using [Expressive Code](https://expressive-code.com/).
|
||||
|
||||
## Documentation
|
||||
|
||||
[Read the Expressive Code docs](https://expressive-code.com/) to learn more about the features provided by Expressive Code and this integration.
|
||||
|
||||
## When should I use this?
|
||||
|
||||
When you're using markdown / MDX and want to improve the design and functionality of all contained code blocks using Expressive Code.
|
||||
|
||||
## Installation
|
||||
|
||||
Read the [installation instructions](https://expressive-code.com/installation/) to learn how to install Expressive Code.
|
||||
1
node_modules/rehype-expressive-code/dist/hast.d.ts
generated
vendored
Normal file
1
node_modules/rehype-expressive-code/dist/hast.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from 'expressive-code/hast';
|
||||
3
node_modules/rehype-expressive-code/dist/hast.js
generated
vendored
Normal file
3
node_modules/rehype-expressive-code/dist/hast.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/hast.ts
|
||||
export * from "expressive-code/hast";
|
||||
//# sourceMappingURL=hast.js.map
|
||||
1
node_modules/rehype-expressive-code/dist/hast.js.map
generated
vendored
Normal file
1
node_modules/rehype-expressive-code/dist/hast.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../src/hast.ts"],"sourcesContent":["export * from 'expressive-code/hast'\n"],"mappings":";AAAA,cAAc;","names":[]}
|
||||
95
node_modules/rehype-expressive-code/dist/index.d.ts
generated
vendored
Normal file
95
node_modules/rehype-expressive-code/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import { VFileWithOutput } from 'unified';
|
||||
import { VFile } from 'vfile';
|
||||
import { ExpressiveCodeConfig, ExpressiveCodeBlockOptions, ExpressiveCodeBlock, BundledShikiTheme, ExpressiveCodeTheme, ExpressiveCodeThemeInput, ExpressiveCode } from 'expressive-code';
|
||||
export * from 'expressive-code';
|
||||
import { Root } from 'expressive-code/hast';
|
||||
|
||||
type AnyVFile = VFile | VFileWithOutput<null>;
|
||||
|
||||
type RehypeExpressiveCodeOptions = Omit<ExpressiveCodeConfig, 'themes'> & {
|
||||
/**
|
||||
* The color themes that should be available for your code blocks.
|
||||
*
|
||||
* CSS variables will be generated for all themes, allowing to select the theme to display
|
||||
* using CSS. If you specify one dark and one light theme, a `prefers-color-scheme` media query
|
||||
* will also be generated by default. You can customize this to match your site's needs
|
||||
* through the `useDarkModeMediaQuery` and `themeCssSelector` options.
|
||||
*
|
||||
* The following item types are supported in this array:
|
||||
* - any theme name bundled with Shiki (e.g. `dracula`)
|
||||
* - any theme object compatible with VS Code or Shiki (e.g. imported from an NPM theme package)
|
||||
* - any ExpressiveCodeTheme instance (e.g. using `ExpressiveCodeTheme.fromJSONString(...)`
|
||||
* to load a custom JSON/JSONC theme file yourself)
|
||||
*
|
||||
* Defaults to `['github-dark', 'github-light']`, two themes bundled with Shiki.
|
||||
*/
|
||||
themes?: ThemeObjectOrShikiThemeName[] | undefined;
|
||||
/**
|
||||
* The number of spaces that should be used to render tabs. Defaults to 2.
|
||||
*
|
||||
* Any tabs found in code blocks in your markdown/MDX documents will be replaced
|
||||
* with the specified number of spaces. This ensures that the code blocks are
|
||||
* rendered consistently across browsers and platforms.
|
||||
*
|
||||
* If you want to preserve tabs in your code blocks, set this option to 0.
|
||||
*/
|
||||
tabWidth?: number | undefined;
|
||||
/**
|
||||
* This optional function provides support for multi-language sites by allowing you
|
||||
* to customize the locale used for a given code block.
|
||||
*
|
||||
* If the function returns `undefined`, the default locale provided in the
|
||||
* Expressive Code configuration is used.
|
||||
*/
|
||||
getBlockLocale?: (({ input, file }: {
|
||||
input: ExpressiveCodeBlockOptions;
|
||||
file: AnyVFile;
|
||||
}) => string | undefined | Promise<string | undefined>) | undefined;
|
||||
/**
|
||||
* This optional function allows you to customize how `ExpressiveCodeBlock`
|
||||
* instances are created from code blocks found in the Markdown document.
|
||||
*
|
||||
* The function is called with an object containing the following properties:
|
||||
* - `input`: Block data for the `ExpressiveCodeBlock` constructor.
|
||||
* - `file`: A `VFile` instance representing the Markdown document.
|
||||
*
|
||||
* The function is expected to return an `ExpressiveCodeBlock` instance
|
||||
* or a promise resolving to one.
|
||||
*/
|
||||
customCreateBlock?: (({ input, file }: {
|
||||
input: ExpressiveCodeBlockOptions;
|
||||
file: AnyVFile;
|
||||
}) => ExpressiveCodeBlock | Promise<ExpressiveCodeBlock>) | undefined;
|
||||
/**
|
||||
* This advanced option allows you to influence the rendering process by creating
|
||||
* your own `ExpressiveCode` instance or processing the base styles and JS modules
|
||||
* added to every page.
|
||||
*
|
||||
* The return value will be cached and used for all code blocks on the site.
|
||||
*/
|
||||
customCreateRenderer?: ((options: RehypeExpressiveCodeOptions) => Promise<RehypeExpressiveCodeRenderer> | RehypeExpressiveCodeRenderer) | undefined;
|
||||
};
|
||||
type ThemeObjectOrShikiThemeName = BundledShikiTheme | ExpressiveCodeTheme | ExpressiveCodeThemeInput;
|
||||
type RehypeExpressiveCodeDocument = {
|
||||
/**
|
||||
* The full path to the source file containing the code block.
|
||||
*/
|
||||
sourceFilePath?: string | undefined;
|
||||
};
|
||||
type RehypeExpressiveCodeRenderer = {
|
||||
ec: ExpressiveCode;
|
||||
baseStyles: string;
|
||||
themeStyles: string;
|
||||
jsModules: string[];
|
||||
};
|
||||
/**
|
||||
* Creates an `ExpressiveCode` instance using the given `options`,
|
||||
* including support to load themes bundled with Shiki by name.
|
||||
*
|
||||
* Returns the created `ExpressiveCode` instance together with the base styles and JS modules
|
||||
* that should be added to every page.
|
||||
*/
|
||||
declare function createRenderer(options?: RehypeExpressiveCodeOptions): Promise<RehypeExpressiveCodeRenderer>;
|
||||
declare function rehypeExpressiveCode(options?: RehypeExpressiveCodeOptions): (tree: Root, file: AnyVFile) => Promise<void>;
|
||||
|
||||
export { RehypeExpressiveCodeDocument, RehypeExpressiveCodeOptions, RehypeExpressiveCodeRenderer, ThemeObjectOrShikiThemeName, createRenderer, rehypeExpressiveCode as default };
|
||||
243
node_modules/rehype-expressive-code/dist/index.js
generated
vendored
Normal file
243
node_modules/rehype-expressive-code/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,243 @@
|
||||
// src/index.ts
|
||||
import {
|
||||
loadShikiTheme,
|
||||
ExpressiveCode,
|
||||
ExpressiveCodeTheme,
|
||||
ExpressiveCodeBlock
|
||||
} from "expressive-code";
|
||||
import { visit } from "expressive-code/hast";
|
||||
|
||||
// src/utils.ts
|
||||
import { getClassNames } from "expressive-code/hast";
|
||||
function getCodeBlockInfo(pre) {
|
||||
if (pre.tagName !== "pre" || pre.children.length !== 1)
|
||||
return;
|
||||
const code = pre.children[0];
|
||||
if (code.type !== "element" || code.tagName !== "code")
|
||||
return;
|
||||
const text = code.children[0];
|
||||
if (text.type !== "text")
|
||||
return;
|
||||
const langClass = getClassNames(code).find((c) => c.startsWith("language-")) ?? "";
|
||||
const lang = langClass.replace("language-", "");
|
||||
const meta = code.data?.meta ?? code.properties?.metastring ?? "";
|
||||
return {
|
||||
pre,
|
||||
code,
|
||||
lang,
|
||||
text: text.value,
|
||||
meta
|
||||
};
|
||||
}
|
||||
function createInlineAssetElement({
|
||||
tagName,
|
||||
properties = {},
|
||||
innerHTML,
|
||||
useMdxJsx
|
||||
}) {
|
||||
if (useMdxJsx)
|
||||
return createMdxJsxElementWithInnerHTML(tagName, properties, innerHTML);
|
||||
return {
|
||||
type: "element",
|
||||
tagName,
|
||||
properties,
|
||||
children: [{ type: "text", value: innerHTML }]
|
||||
};
|
||||
}
|
||||
function createMdxJsxElementWithInnerHTML(tagName, properties, innerHTML) {
|
||||
const attrs = Object.entries(properties).map(([name, value]) => ({
|
||||
type: "mdxJsxAttribute",
|
||||
name,
|
||||
value
|
||||
}));
|
||||
return {
|
||||
type: "mdxJsxFlowElement",
|
||||
name: tagName,
|
||||
attributes: [
|
||||
...attrs,
|
||||
{
|
||||
type: "mdxJsxAttribute",
|
||||
name: "dangerouslySetInnerHTML",
|
||||
value: {
|
||||
type: "mdxJsxAttributeValueExpression",
|
||||
value: `{__html:${JSON.stringify(innerHTML)}}`,
|
||||
data: {
|
||||
estree: {
|
||||
type: "Program",
|
||||
body: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "ObjectExpression",
|
||||
properties: [
|
||||
{
|
||||
type: "Property",
|
||||
method: false,
|
||||
shorthand: false,
|
||||
computed: false,
|
||||
key: {
|
||||
type: "Identifier",
|
||||
name: "__html"
|
||||
},
|
||||
value: {
|
||||
type: "Literal",
|
||||
value: innerHTML,
|
||||
raw: JSON.stringify(innerHTML)
|
||||
},
|
||||
kind: "init"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
sourceType: "module",
|
||||
comments: []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
data: {
|
||||
_mdxExplicitJsx: true
|
||||
},
|
||||
children: []
|
||||
};
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
export * from "expressive-code";
|
||||
async function createRenderer(options = {}) {
|
||||
const deprecatedOptions = options;
|
||||
if (deprecatedOptions.theme && !options.themes) {
|
||||
options.themes = Array.isArray(deprecatedOptions.theme) ? deprecatedOptions.theme : [deprecatedOptions.theme];
|
||||
delete deprecatedOptions.theme;
|
||||
}
|
||||
const { themes, ...ecOptions } = options;
|
||||
const loadedThemes = themes && await Promise.all(
|
||||
(Array.isArray(themes) ? themes : [themes]).map(async (theme) => {
|
||||
const mustLoadTheme = theme !== void 0 && !(theme instanceof ExpressiveCodeTheme);
|
||||
const optLoadedTheme = mustLoadTheme ? new ExpressiveCodeTheme(typeof theme === "string" ? await loadShikiTheme(theme) : theme) : theme;
|
||||
return optLoadedTheme;
|
||||
})
|
||||
);
|
||||
const ec = new ExpressiveCode({
|
||||
themes: loadedThemes,
|
||||
...ecOptions
|
||||
});
|
||||
const baseStyles = await ec.getBaseStyles();
|
||||
const themeStyles = await ec.getThemeStyles();
|
||||
const jsModules = await ec.getJsModules();
|
||||
return {
|
||||
ec,
|
||||
baseStyles,
|
||||
themeStyles,
|
||||
jsModules
|
||||
};
|
||||
}
|
||||
function rehypeExpressiveCode(options = {}) {
|
||||
const { tabWidth = 2, getBlockLocale, customCreateRenderer, customCreateBlock } = options;
|
||||
let asyncRenderer;
|
||||
const renderBlockToHast = async ({
|
||||
codeBlock,
|
||||
renderer,
|
||||
addedStyles,
|
||||
addedJsModules,
|
||||
useMdxJsx
|
||||
}) => {
|
||||
const { ec, baseStyles, themeStyles, jsModules } = renderer;
|
||||
const { renderedGroupAst, styles } = await ec.render(codeBlock);
|
||||
const extraElements = [];
|
||||
const stylesToPrepend = [];
|
||||
if (baseStyles && !addedStyles.has(baseStyles)) {
|
||||
addedStyles.add(baseStyles);
|
||||
stylesToPrepend.push(baseStyles);
|
||||
}
|
||||
if (themeStyles && !addedStyles.has(themeStyles)) {
|
||||
addedStyles.add(themeStyles);
|
||||
stylesToPrepend.push(themeStyles);
|
||||
}
|
||||
for (const style of styles) {
|
||||
if (addedStyles.has(style))
|
||||
continue;
|
||||
addedStyles.add(style);
|
||||
stylesToPrepend.push(style);
|
||||
}
|
||||
if (stylesToPrepend.length) {
|
||||
extraElements.push(
|
||||
createInlineAssetElement({
|
||||
tagName: "style",
|
||||
innerHTML: stylesToPrepend.join(""),
|
||||
useMdxJsx
|
||||
})
|
||||
);
|
||||
}
|
||||
jsModules.forEach((moduleCode) => {
|
||||
if (addedJsModules.has(moduleCode))
|
||||
return;
|
||||
addedJsModules.add(moduleCode);
|
||||
extraElements.push(
|
||||
createInlineAssetElement({
|
||||
tagName: "script",
|
||||
properties: { type: "module" },
|
||||
innerHTML: moduleCode,
|
||||
useMdxJsx
|
||||
})
|
||||
);
|
||||
});
|
||||
renderedGroupAst.children.unshift(...extraElements);
|
||||
return renderedGroupAst;
|
||||
};
|
||||
const transformer = async (tree, file) => {
|
||||
const nodesToProcess = [];
|
||||
visit(tree, "element", (element, index, parent) => {
|
||||
if (index === null || !parent)
|
||||
return;
|
||||
const codeBlockInfo = getCodeBlockInfo(element);
|
||||
if (codeBlockInfo)
|
||||
nodesToProcess.push([parent, codeBlockInfo]);
|
||||
});
|
||||
if (nodesToProcess.length === 0)
|
||||
return;
|
||||
if (asyncRenderer === void 0) {
|
||||
asyncRenderer = (customCreateRenderer ?? createRenderer)(options);
|
||||
}
|
||||
const renderer = await asyncRenderer;
|
||||
const isAstro = file.data?.astro !== void 0;
|
||||
const isMdx = file.path?.endsWith(".mdx") ?? false;
|
||||
const useMdxJsx = !isAstro && isMdx;
|
||||
const addedStyles = /* @__PURE__ */ new Set();
|
||||
const addedJsModules = /* @__PURE__ */ new Set();
|
||||
for (let groupIndex = 0; groupIndex < nodesToProcess.length; groupIndex++) {
|
||||
const [parent, code] = nodesToProcess[groupIndex];
|
||||
let normalizedCode = code.text;
|
||||
if (tabWidth > 0)
|
||||
normalizedCode = normalizedCode.replace(/\t/g, " ".repeat(tabWidth));
|
||||
const input = {
|
||||
code: normalizedCode,
|
||||
language: code.lang || "",
|
||||
meta: code.meta || "",
|
||||
parentDocument: {
|
||||
sourceFilePath: file.path,
|
||||
documentRoot: tree,
|
||||
positionInDocument: {
|
||||
groupIndex,
|
||||
totalGroups: nodesToProcess.length
|
||||
}
|
||||
}
|
||||
};
|
||||
if (getBlockLocale) {
|
||||
input.locale = await getBlockLocale({ input, file });
|
||||
}
|
||||
const codeBlock = customCreateBlock ? await customCreateBlock({ input, file }) : new ExpressiveCodeBlock(input);
|
||||
const renderedBlock = await renderBlockToHast({ codeBlock, renderer, addedStyles, addedJsModules, useMdxJsx });
|
||||
parent.children.splice(parent.children.indexOf(code.pre), 1, renderedBlock);
|
||||
}
|
||||
};
|
||||
return transformer;
|
||||
}
|
||||
var src_default = rehypeExpressiveCode;
|
||||
export {
|
||||
createRenderer,
|
||||
src_default as default
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/rehype-expressive-code/dist/index.js.map
generated
vendored
Normal file
1
node_modules/rehype-expressive-code/dist/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
60
node_modules/rehype-expressive-code/package.json
generated
vendored
Normal file
60
node_modules/rehype-expressive-code/package.json
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"name": "rehype-expressive-code",
|
||||
"version": "0.35.3",
|
||||
"description": "Rehype plugin for Expressive Code, a text marking & annotation engine for presenting source code on the web.",
|
||||
"keywords": [],
|
||||
"author": "Tibor Schiemann",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/expressive-code/expressive-code.git",
|
||||
"directory": "packages/rehype-expressive-code"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./hast": {
|
||||
"types": "./dist/hast.d.ts",
|
||||
"default": "./dist/hast.js"
|
||||
}
|
||||
},
|
||||
"types": "./dist/index.d.ts",
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"hast": [
|
||||
"dist/hast.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"dependencies": {
|
||||
"expressive-code": "^0.35.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mdast": "^3.0.11",
|
||||
"@types/unist": "^2.0.6",
|
||||
"mdast-util-mdx-jsx": "^3.1.2",
|
||||
"rehype-stringify": "^9.0.3",
|
||||
"remark-parse": "^10.0.1",
|
||||
"remark-rehype": "^10.1.0",
|
||||
"shiki": "^1.1.7",
|
||||
"unified": "^10.1.2",
|
||||
"vfile": "^6.0.1",
|
||||
"@internal/test-utils": "^0.2.28"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup ./src/index.ts ./src/hast.ts --format esm --dts --sourcemap --clean",
|
||||
"coverage": "vitest run --coverage",
|
||||
"test": "vitest run --reporter verbose",
|
||||
"test-short": "vitest run --reporter basic",
|
||||
"test-watch": "vitest --reporter verbose",
|
||||
"watch": "pnpm build --watch src"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user