🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
61
node_modules/@astrojs/markdown-remark/LICENSE
generated
vendored
Normal file
61
node_modules/@astrojs/markdown-remark/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Fred K. Schott
|
||||
|
||||
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.
|
||||
|
||||
|
||||
"""
|
||||
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
||||
|
||||
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
||||
|
||||
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.
|
||||
"""
|
||||
8
node_modules/@astrojs/markdown-remark/dist/frontmatter-injection.d.ts
generated
vendored
Normal file
8
node_modules/@astrojs/markdown-remark/dist/frontmatter-injection.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import type { VFile, VFileData as Data } from 'vfile';
|
||||
import type { MarkdownAstroData } from './types.js';
|
||||
export declare class InvalidAstroDataError extends TypeError {
|
||||
}
|
||||
export declare function safelyGetAstroData(vfileData: Data): MarkdownAstroData | InvalidAstroDataError;
|
||||
export declare function toRemarkInitializeAstroData({ userFrontmatter, }: {
|
||||
userFrontmatter: Record<string, any>;
|
||||
}): () => (tree: any, vfile: VFile) => void;
|
||||
35
node_modules/@astrojs/markdown-remark/dist/frontmatter-injection.js
generated
vendored
Normal file
35
node_modules/@astrojs/markdown-remark/dist/frontmatter-injection.js
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
function isValidAstroData(obj) {
|
||||
if (typeof obj === "object" && obj !== null && obj.hasOwnProperty("frontmatter")) {
|
||||
const { frontmatter } = obj;
|
||||
try {
|
||||
JSON.stringify(frontmatter);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
return typeof frontmatter === "object" && frontmatter !== null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
class InvalidAstroDataError extends TypeError {
|
||||
}
|
||||
function safelyGetAstroData(vfileData) {
|
||||
const { astro } = vfileData;
|
||||
if (!astro || !isValidAstroData(astro)) {
|
||||
return new InvalidAstroDataError();
|
||||
}
|
||||
return astro;
|
||||
}
|
||||
function toRemarkInitializeAstroData({
|
||||
userFrontmatter
|
||||
}) {
|
||||
return () => function(tree, vfile) {
|
||||
if (!vfile.data.astro) {
|
||||
vfile.data.astro = { frontmatter: userFrontmatter };
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
InvalidAstroDataError,
|
||||
safelyGetAstroData,
|
||||
toRemarkInitializeAstroData
|
||||
};
|
||||
7
node_modules/@astrojs/markdown-remark/dist/index.d.ts
generated
vendored
Normal file
7
node_modules/@astrojs/markdown-remark/dist/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import type { AstroMarkdownOptions, MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
|
||||
export { rehypeHeadingIds } from './rehype-collect-headings.js';
|
||||
export { remarkCollectImages } from './remark-collect-images.js';
|
||||
export * from './types.js';
|
||||
export declare const markdownConfigDefaults: Omit<Required<AstroMarkdownOptions>, 'drafts'>;
|
||||
/** Shared utility for rendering markdown */
|
||||
export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<MarkdownRenderingResult>;
|
||||
133
node_modules/@astrojs/markdown-remark/dist/index.js
generated
vendored
Normal file
133
node_modules/@astrojs/markdown-remark/dist/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
import { toRemarkInitializeAstroData } from "./frontmatter-injection.js";
|
||||
import { loadPlugins } from "./load-plugins.js";
|
||||
import { rehypeHeadingIds } from "./rehype-collect-headings.js";
|
||||
import { remarkCollectImages } from "./remark-collect-images.js";
|
||||
import remarkPrism from "./remark-prism.js";
|
||||
import scopedStyles from "./remark-scoped-styles.js";
|
||||
import remarkShiki from "./remark-shiki.js";
|
||||
import rehypeRaw from "rehype-raw";
|
||||
import rehypeStringify from "rehype-stringify";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import markdown from "remark-parse";
|
||||
import markdownToHtml from "remark-rehype";
|
||||
import remarkSmartypants from "remark-smartypants";
|
||||
import { unified } from "unified";
|
||||
import { VFile } from "vfile";
|
||||
import { rehypeImages } from "./rehype-images.js";
|
||||
import { rehypeHeadingIds as rehypeHeadingIds2 } from "./rehype-collect-headings.js";
|
||||
import { remarkCollectImages as remarkCollectImages2 } from "./remark-collect-images.js";
|
||||
export * from "./types.js";
|
||||
const markdownConfigDefaults = {
|
||||
syntaxHighlight: "shiki",
|
||||
shikiConfig: {
|
||||
langs: [],
|
||||
theme: "github-dark",
|
||||
wrap: false
|
||||
},
|
||||
remarkPlugins: [],
|
||||
rehypePlugins: [],
|
||||
remarkRehype: {},
|
||||
gfm: true,
|
||||
smartypants: true
|
||||
};
|
||||
const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
|
||||
async function renderMarkdown(content, opts) {
|
||||
var _a;
|
||||
let {
|
||||
fileURL,
|
||||
syntaxHighlight = markdownConfigDefaults.syntaxHighlight,
|
||||
shikiConfig = markdownConfigDefaults.shikiConfig,
|
||||
remarkPlugins = markdownConfigDefaults.remarkPlugins,
|
||||
rehypePlugins = markdownConfigDefaults.rehypePlugins,
|
||||
remarkRehype = markdownConfigDefaults.remarkRehype,
|
||||
gfm = markdownConfigDefaults.gfm,
|
||||
smartypants = markdownConfigDefaults.smartypants,
|
||||
frontmatter: userFrontmatter = {}
|
||||
} = opts;
|
||||
const input = new VFile({ value: content, path: fileURL });
|
||||
const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
|
||||
let parser = unified().use(markdown).use(toRemarkInitializeAstroData({ userFrontmatter })).use([]);
|
||||
if (!isPerformanceBenchmark && gfm) {
|
||||
if (gfm) {
|
||||
parser.use(remarkGfm);
|
||||
}
|
||||
if (smartypants) {
|
||||
parser.use(remarkSmartypants);
|
||||
}
|
||||
}
|
||||
const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
|
||||
const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));
|
||||
loadedRemarkPlugins.forEach(([plugin, pluginOpts]) => {
|
||||
parser.use([[plugin, pluginOpts]]);
|
||||
});
|
||||
if (!isPerformanceBenchmark) {
|
||||
if (scopedClassName) {
|
||||
parser.use([scopedStyles(scopedClassName)]);
|
||||
}
|
||||
if (syntaxHighlight === "shiki") {
|
||||
parser.use([await remarkShiki(shikiConfig, scopedClassName)]);
|
||||
} else if (syntaxHighlight === "prism") {
|
||||
parser.use([remarkPrism(scopedClassName)]);
|
||||
}
|
||||
if (opts.experimentalAssets) {
|
||||
parser.use([remarkCollectImages]);
|
||||
}
|
||||
}
|
||||
parser.use([
|
||||
[
|
||||
markdownToHtml,
|
||||
{
|
||||
allowDangerousHtml: true,
|
||||
passThrough: [],
|
||||
...remarkRehype
|
||||
}
|
||||
]
|
||||
]);
|
||||
loadedRehypePlugins.forEach(([plugin, pluginOpts]) => {
|
||||
parser.use([[plugin, pluginOpts]]);
|
||||
});
|
||||
if (opts.experimentalAssets) {
|
||||
parser.use(rehypeImages());
|
||||
}
|
||||
if (!isPerformanceBenchmark) {
|
||||
parser.use([rehypeHeadingIds]);
|
||||
}
|
||||
parser.use([rehypeRaw]).use(rehypeStringify, { allowDangerousHtml: true });
|
||||
let vfile;
|
||||
try {
|
||||
vfile = await parser.process(input);
|
||||
} catch (err) {
|
||||
err = prefixError(err, `Failed to parse Markdown file "${input.path}"`);
|
||||
console.error(err);
|
||||
throw err;
|
||||
}
|
||||
const headings = (vfile == null ? void 0 : vfile.data.__astroHeadings) || [];
|
||||
return {
|
||||
metadata: { headings, source: content, html: String(vfile.value) },
|
||||
code: String(vfile.value),
|
||||
vfile
|
||||
};
|
||||
}
|
||||
function prefixError(err, prefix) {
|
||||
if (err && err.message) {
|
||||
try {
|
||||
err.message = `${prefix}:
|
||||
${err.message}`;
|
||||
return err;
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ""}`);
|
||||
try {
|
||||
wrappedError.stack = err.stack;
|
||||
wrappedError.cause = err;
|
||||
} catch (error) {
|
||||
}
|
||||
return wrappedError;
|
||||
}
|
||||
export {
|
||||
markdownConfigDefaults,
|
||||
rehypeHeadingIds2 as rehypeHeadingIds,
|
||||
remarkCollectImages2 as remarkCollectImages,
|
||||
renderMarkdown
|
||||
};
|
||||
1
node_modules/@astrojs/markdown-remark/dist/internal.d.ts
generated
vendored
Normal file
1
node_modules/@astrojs/markdown-remark/dist/internal.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { InvalidAstroDataError, safelyGetAstroData, toRemarkInitializeAstroData, } from './frontmatter-injection.js';
|
||||
10
node_modules/@astrojs/markdown-remark/dist/internal.js
generated
vendored
Normal file
10
node_modules/@astrojs/markdown-remark/dist/internal.js
generated
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import {
|
||||
InvalidAstroDataError,
|
||||
safelyGetAstroData,
|
||||
toRemarkInitializeAstroData
|
||||
} from "./frontmatter-injection.js";
|
||||
export {
|
||||
InvalidAstroDataError,
|
||||
safelyGetAstroData,
|
||||
toRemarkInitializeAstroData
|
||||
};
|
||||
2
node_modules/@astrojs/markdown-remark/dist/load-plugins.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/markdown-remark/dist/load-plugins.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type * as unified from 'unified';
|
||||
export declare function loadPlugins(items: (string | [string, any] | unified.Plugin<any[], any> | [unified.Plugin<any[], any>, any])[]): Promise<[unified.Plugin, any?]>[];
|
||||
31
node_modules/@astrojs/markdown-remark/dist/load-plugins.js
generated
vendored
Normal file
31
node_modules/@astrojs/markdown-remark/dist/load-plugins.js
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { resolve as importMetaResolve } from "import-meta-resolve";
|
||||
import path from "path";
|
||||
import { pathToFileURL } from "url";
|
||||
const cwdUrlStr = pathToFileURL(path.join(process.cwd(), "package.json")).toString();
|
||||
async function importPlugin(p) {
|
||||
if (typeof p === "string") {
|
||||
try {
|
||||
const importResult2 = await import(p);
|
||||
return importResult2.default;
|
||||
} catch {
|
||||
}
|
||||
const resolved = await importMetaResolve(p, cwdUrlStr);
|
||||
const importResult = await import(resolved);
|
||||
return importResult.default;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
function loadPlugins(items) {
|
||||
return items.map((p) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (Array.isArray(p)) {
|
||||
const [plugin, opts] = p;
|
||||
return importPlugin(plugin).then((m) => resolve([m, opts])).catch((e) => reject(e));
|
||||
}
|
||||
return importPlugin(p).then((m) => resolve([m])).catch((e) => reject(e));
|
||||
});
|
||||
});
|
||||
}
|
||||
export {
|
||||
loadPlugins
|
||||
};
|
||||
2
node_modules/@astrojs/markdown-remark/dist/rehype-collect-headings.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/markdown-remark/dist/rehype-collect-headings.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { RehypePlugin } from './types.js';
|
||||
export declare function rehypeHeadingIds(): ReturnType<RehypePlugin>;
|
||||
99
node_modules/@astrojs/markdown-remark/dist/rehype-collect-headings.js
generated
vendored
Normal file
99
node_modules/@astrojs/markdown-remark/dist/rehype-collect-headings.js
generated
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
import Slugger from "github-slugger";
|
||||
import { visit } from "unist-util-visit";
|
||||
import { InvalidAstroDataError, safelyGetAstroData } from "./frontmatter-injection.js";
|
||||
const rawNodeTypes = /* @__PURE__ */ new Set(["text", "raw", "mdxTextExpression"]);
|
||||
const codeTagNames = /* @__PURE__ */ new Set(["code", "pre"]);
|
||||
function rehypeHeadingIds() {
|
||||
return function(tree, file) {
|
||||
const headings = [];
|
||||
const slugger = new Slugger();
|
||||
const isMDX = isMDXFile(file);
|
||||
const astroData = safelyGetAstroData(file.data);
|
||||
visit(tree, (node) => {
|
||||
if (node.type !== "element")
|
||||
return;
|
||||
const { tagName } = node;
|
||||
if (tagName[0] !== "h")
|
||||
return;
|
||||
const [_, level] = tagName.match(/h([0-6])/) ?? [];
|
||||
if (!level)
|
||||
return;
|
||||
const depth = Number.parseInt(level);
|
||||
let text = "";
|
||||
visit(node, (child, __, parent) => {
|
||||
if (child.type === "element" || parent == null) {
|
||||
return;
|
||||
}
|
||||
if (child.type === "raw") {
|
||||
if (child.value.match(/^\n?<.*>\n?$/)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (rawNodeTypes.has(child.type)) {
|
||||
if (isMDX || codeTagNames.has(parent.tagName)) {
|
||||
let value = child.value;
|
||||
if (isMdxTextExpression(child) && !(astroData instanceof InvalidAstroDataError)) {
|
||||
const frontmatterPath = getMdxFrontmatterVariablePath(child);
|
||||
if (Array.isArray(frontmatterPath) && frontmatterPath.length > 0) {
|
||||
const frontmatterValue = getMdxFrontmatterVariableValue(astroData, frontmatterPath);
|
||||
if (typeof frontmatterValue === "string") {
|
||||
value = frontmatterValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
text += value;
|
||||
} else {
|
||||
text += child.value.replace(/\{/g, "${");
|
||||
}
|
||||
}
|
||||
});
|
||||
node.properties = node.properties || {};
|
||||
if (typeof node.properties.id !== "string") {
|
||||
let slug = slugger.slug(text);
|
||||
if (slug.endsWith("-"))
|
||||
slug = slug.slice(0, -1);
|
||||
node.properties.id = slug;
|
||||
}
|
||||
headings.push({ depth, slug: node.properties.id, text });
|
||||
});
|
||||
file.data.__astroHeadings = headings;
|
||||
};
|
||||
}
|
||||
function isMDXFile(file) {
|
||||
var _a;
|
||||
return Boolean((_a = file.history[0]) == null ? void 0 : _a.endsWith(".mdx"));
|
||||
}
|
||||
function getMdxFrontmatterVariablePath(node) {
|
||||
var _a;
|
||||
if (!((_a = node.data) == null ? void 0 : _a.estree) || node.data.estree.body.length !== 1)
|
||||
return new Error();
|
||||
const statement = node.data.estree.body[0];
|
||||
if ((statement == null ? void 0 : statement.type) !== "ExpressionStatement" || statement.expression.type !== "MemberExpression")
|
||||
return new Error();
|
||||
let expression = statement.expression;
|
||||
const expressionPath = [];
|
||||
while (expression.type === "MemberExpression" && expression.property.type === (expression.computed ? "Literal" : "Identifier")) {
|
||||
expressionPath.push(
|
||||
expression.property.type === "Literal" ? String(expression.property.value) : expression.property.name
|
||||
);
|
||||
expression = expression.object;
|
||||
}
|
||||
if (expression.type !== "Identifier" || expression.name !== "frontmatter")
|
||||
return new Error();
|
||||
return expressionPath.reverse();
|
||||
}
|
||||
function getMdxFrontmatterVariableValue(astroData, path) {
|
||||
let value = astroData.frontmatter;
|
||||
for (const key of path) {
|
||||
if (!value[key])
|
||||
return void 0;
|
||||
value = value[key];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function isMdxTextExpression(node) {
|
||||
return node.type === "mdxTextExpression";
|
||||
}
|
||||
export {
|
||||
rehypeHeadingIds
|
||||
};
|
||||
2
node_modules/@astrojs/markdown-remark/dist/rehype-images.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/markdown-remark/dist/rehype-images.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { MarkdownVFile } from './types.js';
|
||||
export declare function rehypeImages(): () => (tree: any, file: MarkdownVFile) => void;
|
||||
21
node_modules/@astrojs/markdown-remark/dist/rehype-images.js
generated
vendored
Normal file
21
node_modules/@astrojs/markdown-remark/dist/rehype-images.js
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { visit } from "unist-util-visit";
|
||||
function rehypeImages() {
|
||||
return () => function(tree, file) {
|
||||
visit(tree, (node) => {
|
||||
var _a, _b;
|
||||
if (node.type !== "element")
|
||||
return;
|
||||
if (node.tagName !== "img")
|
||||
return;
|
||||
if ((_a = node.properties) == null ? void 0 : _a.src) {
|
||||
if ((_b = file.data.imagePaths) == null ? void 0 : _b.has(node.properties.src)) {
|
||||
node.properties["__ASTRO_IMAGE_"] = node.properties.src;
|
||||
delete node.properties.src;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
export {
|
||||
rehypeImages
|
||||
};
|
||||
2
node_modules/@astrojs/markdown-remark/dist/remark-collect-images.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/markdown-remark/dist/remark-collect-images.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import type { MarkdownVFile } from './types';
|
||||
export declare function remarkCollectImages(): (tree: any, vfile: MarkdownVFile) => void;
|
||||
27
node_modules/@astrojs/markdown-remark/dist/remark-collect-images.js
generated
vendored
Normal file
27
node_modules/@astrojs/markdown-remark/dist/remark-collect-images.js
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { visit } from "unist-util-visit";
|
||||
function remarkCollectImages() {
|
||||
return function(tree, vfile) {
|
||||
if (typeof (vfile == null ? void 0 : vfile.path) !== "string")
|
||||
return;
|
||||
const imagePaths = /* @__PURE__ */ new Set();
|
||||
visit(tree, "image", (node) => {
|
||||
if (shouldOptimizeImage(node.url))
|
||||
imagePaths.add(node.url);
|
||||
});
|
||||
vfile.data.imagePaths = imagePaths;
|
||||
};
|
||||
}
|
||||
function shouldOptimizeImage(src) {
|
||||
return !isValidUrl(src) && !src.startsWith("/");
|
||||
}
|
||||
function isValidUrl(str) {
|
||||
try {
|
||||
new URL(str);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export {
|
||||
remarkCollectImages
|
||||
};
|
||||
3
node_modules/@astrojs/markdown-remark/dist/remark-prism.d.ts
generated
vendored
Normal file
3
node_modules/@astrojs/markdown-remark/dist/remark-prism.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
type MaybeString = string | null | undefined;
|
||||
declare function plugin(className: MaybeString): () => (tree: any) => void;
|
||||
export default plugin;
|
||||
28
node_modules/@astrojs/markdown-remark/dist/remark-prism.js
generated
vendored
Normal file
28
node_modules/@astrojs/markdown-remark/dist/remark-prism.js
generated
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { runHighlighterWithAstro } from "@astrojs/prism/dist/highlighter";
|
||||
import { visit } from "unist-util-visit";
|
||||
const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
|
||||
function transformer(className) {
|
||||
return function(tree) {
|
||||
const visitor = (node) => {
|
||||
let { lang, value } = node;
|
||||
node.type = "html";
|
||||
let { html, classLanguage } = runHighlighterWithAstro(lang, value);
|
||||
let classes = [classLanguage];
|
||||
if (className) {
|
||||
classes.push(className);
|
||||
}
|
||||
node.value = `<pre class="${classes.join(
|
||||
" "
|
||||
)}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
|
||||
return node;
|
||||
};
|
||||
return visit(tree, "code", visitor);
|
||||
};
|
||||
}
|
||||
function plugin(className) {
|
||||
return transformer.bind(null, className);
|
||||
}
|
||||
var remark_prism_default = plugin;
|
||||
export {
|
||||
remark_prism_default as default
|
||||
};
|
||||
2
node_modules/@astrojs/markdown-remark/dist/remark-scoped-styles.d.ts
generated
vendored
Normal file
2
node_modules/@astrojs/markdown-remark/dist/remark-scoped-styles.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/** */
|
||||
export default function scopedStyles(className: string): () => (tree: any) => void;
|
||||
19
node_modules/@astrojs/markdown-remark/dist/remark-scoped-styles.js
generated
vendored
Normal file
19
node_modules/@astrojs/markdown-remark/dist/remark-scoped-styles.js
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { visit } from "unist-util-visit";
|
||||
const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
|
||||
function scopedStyles(className) {
|
||||
const visitor = (node) => {
|
||||
var _a;
|
||||
if (noVisit.has(node.type))
|
||||
return;
|
||||
const { data } = node;
|
||||
let currentClassName = ((_a = data == null ? void 0 : data.hProperties) == null ? void 0 : _a.class) ?? "";
|
||||
node.data = node.data || {};
|
||||
node.data.hProperties = node.data.hProperties || {};
|
||||
node.data.hProperties.class = `${className} ${currentClassName}`.trim();
|
||||
return node;
|
||||
};
|
||||
return () => (tree) => visit(tree, visitor);
|
||||
}
|
||||
export {
|
||||
scopedStyles as default
|
||||
};
|
||||
3
node_modules/@astrojs/markdown-remark/dist/remark-shiki.d.ts
generated
vendored
Normal file
3
node_modules/@astrojs/markdown-remark/dist/remark-shiki.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import type { ShikiConfig } from './types.js';
|
||||
declare const remarkShiki: ({ langs, theme, wrap }: ShikiConfig, scopedClassName?: string | null) => Promise<() => (tree: any) => void>;
|
||||
export default remarkShiki;
|
||||
92
node_modules/@astrojs/markdown-remark/dist/remark-shiki.js
generated
vendored
Normal file
92
node_modules/@astrojs/markdown-remark/dist/remark-shiki.js
generated
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import { getHighlighter } from "shiki";
|
||||
import { visit } from "unist-util-visit";
|
||||
const highlighterCacheAsync = /* @__PURE__ */ new Map();
|
||||
const compatThemes = {
|
||||
"material-darker": "material-theme-darker",
|
||||
"material-default": "material-theme",
|
||||
"material-lighter": "material-theme-lighter",
|
||||
"material-ocean": "material-theme-ocean",
|
||||
"material-palenight": "material-theme-palenight"
|
||||
};
|
||||
const normalizeTheme = (theme) => {
|
||||
if (typeof theme === "string") {
|
||||
return compatThemes[theme] || theme;
|
||||
} else if (compatThemes[theme.name]) {
|
||||
return { ...theme, name: compatThemes[theme.name] };
|
||||
} else {
|
||||
return theme;
|
||||
}
|
||||
};
|
||||
const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }, scopedClassName) => {
|
||||
theme = normalizeTheme(theme);
|
||||
const cacheID = typeof theme === "string" ? theme : theme.name;
|
||||
let highlighterAsync = highlighterCacheAsync.get(cacheID);
|
||||
if (!highlighterAsync) {
|
||||
highlighterAsync = getHighlighter({ theme }).then((hl) => {
|
||||
hl.setColorReplacements({
|
||||
"#000001": "var(--astro-code-color-text)",
|
||||
"#000002": "var(--astro-code-color-background)",
|
||||
"#000004": "var(--astro-code-token-constant)",
|
||||
"#000005": "var(--astro-code-token-string)",
|
||||
"#000006": "var(--astro-code-token-comment)",
|
||||
"#000007": "var(--astro-code-token-keyword)",
|
||||
"#000008": "var(--astro-code-token-parameter)",
|
||||
"#000009": "var(--astro-code-token-function)",
|
||||
"#000010": "var(--astro-code-token-string-expression)",
|
||||
"#000011": "var(--astro-code-token-punctuation)",
|
||||
"#000012": "var(--astro-code-token-link)"
|
||||
});
|
||||
return hl;
|
||||
});
|
||||
highlighterCacheAsync.set(cacheID, highlighterAsync);
|
||||
}
|
||||
const highlighter = await highlighterAsync;
|
||||
for (const lang of langs) {
|
||||
await highlighter.loadLanguage(lang);
|
||||
}
|
||||
return () => (tree) => {
|
||||
visit(tree, "code", (node) => {
|
||||
let lang;
|
||||
if (typeof node.lang === "string") {
|
||||
const langExists = highlighter.getLoadedLanguages().includes(node.lang);
|
||||
if (langExists) {
|
||||
lang = node.lang;
|
||||
} else {
|
||||
console.warn(`The language "${node.lang}" doesn't exist, falling back to plaintext.`);
|
||||
lang = "plaintext";
|
||||
}
|
||||
} else {
|
||||
lang = "plaintext";
|
||||
}
|
||||
let html = highlighter.codeToHtml(node.value, { lang });
|
||||
html = html.replace(
|
||||
/<pre class="(.*?)shiki(.*?)"/,
|
||||
`<pre is:raw class="$1astro-code$2${scopedClassName ? " " + scopedClassName : ""}"`
|
||||
);
|
||||
if (node.lang === "diff") {
|
||||
html = html.replace(
|
||||
/<span class="line"><span style="(.*?)">([\+|\-])/g,
|
||||
'<span class="line"><span style="$1"><span style="user-select: none;">$2</span>'
|
||||
);
|
||||
}
|
||||
if (wrap === false) {
|
||||
html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
|
||||
} else if (wrap === true) {
|
||||
html = html.replace(
|
||||
/style="(.*?)"/,
|
||||
'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
|
||||
);
|
||||
}
|
||||
if (scopedClassName) {
|
||||
html = html.replace(/\<span class="line"\>/g, `<span class="line ${scopedClassName}"`);
|
||||
}
|
||||
node.type = "html";
|
||||
node.value = html;
|
||||
node.children = [];
|
||||
});
|
||||
};
|
||||
};
|
||||
var remark_shiki_default = remarkShiki;
|
||||
export {
|
||||
remark_shiki_default as default
|
||||
};
|
||||
71
node_modules/@astrojs/markdown-remark/dist/types.d.ts
generated
vendored
Normal file
71
node_modules/@astrojs/markdown-remark/dist/types.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import type * as hast from 'hast';
|
||||
import type * as mdast from 'mdast';
|
||||
import type { all as Handlers, one as Handler, Options as RemarkRehypeOptions } from 'remark-rehype';
|
||||
import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
|
||||
import type * as unified from 'unified';
|
||||
import type { VFile } from 'vfile';
|
||||
export type { Node } from 'unist';
|
||||
export type MarkdownAstroData = {
|
||||
frontmatter: Record<string, any>;
|
||||
};
|
||||
export type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, mdast.Root>;
|
||||
export type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
|
||||
export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, hast.Root>;
|
||||
export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
|
||||
export type RemarkRehype = Omit<RemarkRehypeOptions, 'handlers' | 'unknownHandler'> & {
|
||||
handlers?: typeof Handlers;
|
||||
handler?: typeof Handler;
|
||||
};
|
||||
export interface ShikiConfig {
|
||||
langs?: ILanguageRegistration[];
|
||||
theme?: Theme | IThemeRegistration;
|
||||
wrap?: boolean | null;
|
||||
}
|
||||
export interface AstroMarkdownOptions {
|
||||
drafts?: boolean;
|
||||
syntaxHighlight?: 'shiki' | 'prism' | false;
|
||||
shikiConfig?: ShikiConfig;
|
||||
remarkPlugins?: RemarkPlugins;
|
||||
rehypePlugins?: RehypePlugins;
|
||||
remarkRehype?: RemarkRehype;
|
||||
gfm?: boolean;
|
||||
smartypants?: boolean;
|
||||
}
|
||||
export interface ImageMetadata {
|
||||
src: string;
|
||||
width: number;
|
||||
height: number;
|
||||
type: string;
|
||||
}
|
||||
export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
|
||||
/** @internal */
|
||||
fileURL?: URL;
|
||||
/** @internal */
|
||||
$?: {
|
||||
scopedClassName: string | null;
|
||||
};
|
||||
/** Used for frontmatter injection plugins */
|
||||
frontmatter?: Record<string, any>;
|
||||
experimentalAssets?: boolean;
|
||||
}
|
||||
export interface MarkdownHeading {
|
||||
depth: number;
|
||||
slug: string;
|
||||
text: string;
|
||||
}
|
||||
export interface MarkdownMetadata {
|
||||
headings: MarkdownHeading[];
|
||||
source: string;
|
||||
html: string;
|
||||
}
|
||||
export interface MarkdownVFile extends VFile {
|
||||
data: {
|
||||
__astroHeadings?: MarkdownHeading[];
|
||||
imagePaths?: Set<string>;
|
||||
};
|
||||
}
|
||||
export interface MarkdownRenderingResult {
|
||||
metadata: MarkdownMetadata;
|
||||
vfile: MarkdownVFile;
|
||||
code: string;
|
||||
}
|
||||
0
node_modules/@astrojs/markdown-remark/dist/types.js
generated
vendored
Normal file
0
node_modules/@astrojs/markdown-remark/dist/types.js
generated
vendored
Normal file
1
node_modules/@astrojs/markdown-remark/node_modules/.bin/astro
generated
vendored
Symbolic link
1
node_modules/@astrojs/markdown-remark/node_modules/.bin/astro
generated
vendored
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../../../astro/astro.js
|
||||
61
node_modules/@astrojs/markdown-remark/package.json
generated
vendored
Normal file
61
node_modules/@astrojs/markdown-remark/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
{
|
||||
"name": "@astrojs/markdown-remark",
|
||||
"version": "2.2.1",
|
||||
"type": "module",
|
||||
"author": "withastro",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/withastro/astro.git",
|
||||
"directory": "packages/markdown/remark"
|
||||
},
|
||||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://astro.build",
|
||||
"main": "./dist/index.js",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./dist/internal.js": "./dist/internal.js"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"astro": "^2.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/prism": "^2.1.2",
|
||||
"github-slugger": "^1.4.0",
|
||||
"import-meta-resolve": "^2.1.0",
|
||||
"rehype-raw": "^6.1.1",
|
||||
"rehype-stringify": "^9.0.3",
|
||||
"remark-gfm": "^3.0.1",
|
||||
"remark-parse": "^10.0.1",
|
||||
"remark-rehype": "^10.1.0",
|
||||
"remark-smartypants": "^2.0.0",
|
||||
"shiki": "^0.14.1",
|
||||
"unified": "^10.1.2",
|
||||
"unist-util-visit": "^4.1.0",
|
||||
"vfile": "^5.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.3.1",
|
||||
"@types/estree": "^1.0.0",
|
||||
"@types/github-slugger": "^1.3.0",
|
||||
"@types/hast": "^2.3.4",
|
||||
"@types/mdast": "^3.0.10",
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/unist": "^2.0.6",
|
||||
"chai": "^4.3.6",
|
||||
"mdast-util-mdx-expression": "^1.3.1",
|
||||
"mocha": "^9.2.2",
|
||||
"astro-scripts": "0.0.14"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublish": "pnpm build",
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"postbuild": "astro-scripts copy \"src/**/*.js\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
||||
"test": "mocha --exit --timeout 20000"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue