@astrojs/markdown-remark 7.1.1 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/highlight.d.ts +0 -1
- package/dist/highlight.js +1 -2
- package/dist/index.d.ts +17 -7
- package/dist/index.js +13 -28
- package/dist/processor.d.ts +40 -0
- package/dist/processor.js +33 -0
- package/dist/rehype-collect-headings.d.ts +1 -1
- package/dist/rehype-prism.js +3 -5
- package/dist/rehype-shiki.d.ts +1 -1
- package/dist/rehype-shiki.js +1 -1
- package/dist/remark-collect-images.d.ts +2 -2
- package/dist/shiki.d.ts +1 -44
- package/dist/shiki.js +2 -159
- package/package.json +7 -16
- package/dist/frontmatter.d.ts +0 -20
- package/dist/frontmatter.js +0 -58
- package/dist/shiki-engine-default.d.ts +0 -2
- package/dist/shiki-engine-default.js +0 -7
- package/dist/shiki-engine-workerd.d.ts +0 -2
- package/dist/shiki-engine-workerd.js +0 -7
- package/dist/types.d.ts +0 -77
- package/dist/types.js +0 -0
package/dist/highlight.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Root } from 'hast';
|
|
|
2
2
|
type Highlighter = (code: string, language: string, options?: {
|
|
3
3
|
meta?: string;
|
|
4
4
|
}) => Promise<Root | string>;
|
|
5
|
-
export declare const defaultExcludeLanguages: string[];
|
|
6
5
|
/**
|
|
7
6
|
* A hast utility to syntax highlight code blocks with a given syntax highlighter.
|
|
8
7
|
*
|
package/dist/highlight.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { defaultExcludeLanguages } from "@astrojs/internal-helpers/markdown";
|
|
1
2
|
import { fromHtml } from "hast-util-from-html";
|
|
2
3
|
import { toText } from "hast-util-to-text";
|
|
3
4
|
import { removePosition } from "unist-util-remove-position";
|
|
4
5
|
import { visitParents } from "unist-util-visit-parents";
|
|
5
6
|
const languagePattern = /\blanguage-(\S+)\b/;
|
|
6
|
-
const defaultExcludeLanguages = ["math"];
|
|
7
7
|
async function highlightCodeBlocks(tree, highlighter, excludeLanguages = []) {
|
|
8
8
|
const nodes = [];
|
|
9
9
|
visitParents(tree, { type: "element", tagName: "code" }, (node, ancestors) => {
|
|
@@ -56,6 +56,5 @@ async function highlightCodeBlocks(tree, highlighter, excludeLanguages = []) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
export {
|
|
59
|
-
defaultExcludeLanguages,
|
|
60
59
|
highlightCodeBlocks
|
|
61
60
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import type { AstroMarkdownOptions,
|
|
2
|
-
|
|
1
|
+
import type { AstroMarkdownOptions, MarkdownHeading, MarkdownRenderer } from '@astrojs/internal-helpers/markdown';
|
|
2
|
+
declare module 'vfile' {
|
|
3
|
+
interface DataMap {
|
|
4
|
+
astro: {
|
|
5
|
+
headings?: MarkdownHeading[];
|
|
6
|
+
localImagePaths?: string[];
|
|
7
|
+
remoteImagePaths?: string[];
|
|
8
|
+
frontmatter?: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export type { Node } from 'unist';
|
|
13
|
+
export type { AstroMarkdownOptions, MarkdownHeading, MarkdownProcessor, MarkdownRenderer, MarkdownRenderOptions, MarkdownRenderResult, RehypePlugin, RehypePlugins, RemarkPlugin, RemarkPlugins, RemarkRehype, ShikiConfig, Smartypants, SyntaxHighlightConfig, SyntaxHighlightConfigType, } from '@astrojs/internal-helpers/markdown';
|
|
14
|
+
export { extractFrontmatter, isFrontmatterValid, type ParseFrontmatterOptions, type ParseFrontmatterResult, parseFrontmatter, } from '@astrojs/internal-helpers/frontmatter';
|
|
3
15
|
export { rehypeHeadingIds } from './rehype-collect-headings.js';
|
|
4
16
|
export { rehypePrism } from './rehype-prism.js';
|
|
5
17
|
export { rehypeShiki } from './rehype-shiki.js';
|
|
6
18
|
export { remarkCollectImages } from './remark-collect-images.js';
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export declare const syntaxHighlightDefaults: Required<SyntaxHighlightConfig>;
|
|
10
|
-
export declare const markdownConfigDefaults: Required<AstroMarkdownOptions>;
|
|
19
|
+
export { isUnifiedProcessor, type UnifiedProcessorOptions, type UnifiedResolvedOptions, unified, } from './processor.js';
|
|
20
|
+
export { markdownConfigDefaults, syntaxHighlightDefaults, } from '@astrojs/internal-helpers/markdown';
|
|
11
21
|
/**
|
|
12
22
|
* Create a markdown preprocessor to render multiple markdown files
|
|
13
23
|
*/
|
|
14
|
-
export declare function createMarkdownProcessor(opts?:
|
|
24
|
+
export declare function createMarkdownProcessor(opts?: AstroMarkdownOptions): Promise<MarkdownRenderer>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markdownConfigDefaults } from "@astrojs/internal-helpers/markdown";
|
|
1
2
|
import rehypeRaw from "rehype-raw";
|
|
2
3
|
import rehypeStringify from "rehype-stringify";
|
|
3
4
|
import remarkGfm from "remark-gfm";
|
|
@@ -6,7 +7,6 @@ import remarkRehype from "remark-rehype";
|
|
|
6
7
|
import remarkSmartypants from "remark-smartypants";
|
|
7
8
|
import { unified } from "unified";
|
|
8
9
|
import { VFile } from "vfile";
|
|
9
|
-
import { defaultExcludeLanguages } from "./highlight.js";
|
|
10
10
|
import { loadPlugins } from "./load-plugins.js";
|
|
11
11
|
import { rehypeHeadingIds } from "./rehype-collect-headings.js";
|
|
12
12
|
import { rehypeImages } from "./rehype-images.js";
|
|
@@ -17,35 +17,19 @@ import {
|
|
|
17
17
|
extractFrontmatter,
|
|
18
18
|
isFrontmatterValid,
|
|
19
19
|
parseFrontmatter
|
|
20
|
-
} from "
|
|
20
|
+
} from "@astrojs/internal-helpers/frontmatter";
|
|
21
21
|
import { rehypeHeadingIds as rehypeHeadingIds2 } from "./rehype-collect-headings.js";
|
|
22
22
|
import { rehypePrism as rehypePrism2 } from "./rehype-prism.js";
|
|
23
23
|
import { rehypeShiki as rehypeShiki2 } from "./rehype-shiki.js";
|
|
24
24
|
import { remarkCollectImages as remarkCollectImages2 } from "./remark-collect-images.js";
|
|
25
25
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
const markdownConfigDefaults = {
|
|
34
|
-
syntaxHighlight: syntaxHighlightDefaults,
|
|
35
|
-
shikiConfig: {
|
|
36
|
-
langs: [],
|
|
37
|
-
theme: "github-dark",
|
|
38
|
-
themes: {},
|
|
39
|
-
wrap: false,
|
|
40
|
-
transformers: [],
|
|
41
|
-
langAlias: {}
|
|
42
|
-
},
|
|
43
|
-
remarkPlugins: [],
|
|
44
|
-
rehypePlugins: [],
|
|
45
|
-
remarkRehype: {},
|
|
46
|
-
gfm: true,
|
|
47
|
-
smartypants: true
|
|
48
|
-
};
|
|
26
|
+
isUnifiedProcessor,
|
|
27
|
+
unified as unified2
|
|
28
|
+
} from "./processor.js";
|
|
29
|
+
import {
|
|
30
|
+
markdownConfigDefaults as markdownConfigDefaults2,
|
|
31
|
+
syntaxHighlightDefaults
|
|
32
|
+
} from "@astrojs/internal-helpers/markdown";
|
|
49
33
|
const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
|
|
50
34
|
async function createMarkdownProcessor(opts) {
|
|
51
35
|
const {
|
|
@@ -144,14 +128,15 @@ ${err.message}`;
|
|
|
144
128
|
}
|
|
145
129
|
export {
|
|
146
130
|
createMarkdownProcessor,
|
|
147
|
-
createShikiHighlighter,
|
|
148
131
|
extractFrontmatter,
|
|
149
132
|
isFrontmatterValid,
|
|
150
|
-
|
|
133
|
+
isUnifiedProcessor,
|
|
134
|
+
markdownConfigDefaults2 as markdownConfigDefaults,
|
|
151
135
|
parseFrontmatter,
|
|
152
136
|
rehypeHeadingIds2 as rehypeHeadingIds,
|
|
153
137
|
rehypePrism2 as rehypePrism,
|
|
154
138
|
rehypeShiki2 as rehypeShiki,
|
|
155
139
|
remarkCollectImages2 as remarkCollectImages,
|
|
156
|
-
syntaxHighlightDefaults
|
|
140
|
+
syntaxHighlightDefaults,
|
|
141
|
+
unified2 as unified
|
|
157
142
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MarkdownProcessor, RehypePlugins, RemarkPlugins, RemarkRehype, Smartypants } from '@astrojs/internal-helpers/markdown';
|
|
2
|
+
export interface UnifiedProcessorOptions {
|
|
3
|
+
remarkPlugins?: RemarkPlugins;
|
|
4
|
+
rehypePlugins?: RehypePlugins;
|
|
5
|
+
remarkRehype?: RemarkRehype;
|
|
6
|
+
/** Enable GitHub-Flavored Markdown. Defaults to `true`. */
|
|
7
|
+
gfm?: boolean;
|
|
8
|
+
/** Enable SmartyPants typography. Defaults to `true`; pass an object to configure it. */
|
|
9
|
+
smartypants?: boolean | Smartypants;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolved options on the processor returned by `unified()`. Always populated
|
|
13
|
+
* (the factory normalises absent inputs into defaults).
|
|
14
|
+
*/
|
|
15
|
+
export interface UnifiedResolvedOptions {
|
|
16
|
+
remarkPlugins: RemarkPlugins;
|
|
17
|
+
rehypePlugins: RehypePlugins;
|
|
18
|
+
remarkRehype: RemarkRehype;
|
|
19
|
+
gfm?: boolean;
|
|
20
|
+
smartypants?: boolean | Smartypants;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Use the default remark/rehype-based Markdown processor for `markdown.processor`.
|
|
24
|
+
* Extend the pipeline with remark or rehype plugins, or pass options to `remark-rehype`.
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* import { unified } from '@astrojs/markdown-remark';
|
|
28
|
+
* import remarkToc from 'remark-toc';
|
|
29
|
+
*
|
|
30
|
+
* export default defineConfig({
|
|
31
|
+
* markdown: {
|
|
32
|
+
* processor: unified({ remarkPlugins: [remarkToc] }),
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function unified(opts?: UnifiedProcessorOptions): MarkdownProcessor<UnifiedResolvedOptions>;
|
|
38
|
+
export declare function isUnifiedProcessor(p: {
|
|
39
|
+
name: string;
|
|
40
|
+
}): p is MarkdownProcessor<UnifiedResolvedOptions>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function unified(opts = {}) {
|
|
2
|
+
const processor = {
|
|
3
|
+
name: "unified",
|
|
4
|
+
options: {
|
|
5
|
+
remarkPlugins: [...opts.remarkPlugins ?? []],
|
|
6
|
+
rehypePlugins: [...opts.rehypePlugins ?? []],
|
|
7
|
+
remarkRehype: { ...opts.remarkRehype },
|
|
8
|
+
gfm: opts.gfm,
|
|
9
|
+
smartypants: opts.smartypants
|
|
10
|
+
},
|
|
11
|
+
async createRenderer(shared) {
|
|
12
|
+
const { createMarkdownProcessor } = await import("./index.js");
|
|
13
|
+
return createMarkdownProcessor({
|
|
14
|
+
...shared,
|
|
15
|
+
remarkPlugins: processor.options.remarkPlugins,
|
|
16
|
+
rehypePlugins: processor.options.rehypePlugins,
|
|
17
|
+
remarkRehype: processor.options.remarkRehype,
|
|
18
|
+
// `unified({ gfm, smartypants })` wins; fall back to the deprecated
|
|
19
|
+
// top-level `markdown.gfm` / `markdown.smartypants` while they still exist.
|
|
20
|
+
gfm: processor.options.gfm ?? shared.gfm,
|
|
21
|
+
smartypants: processor.options.smartypants ?? shared.smartypants
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return processor;
|
|
26
|
+
}
|
|
27
|
+
function isUnifiedProcessor(p) {
|
|
28
|
+
return p.name === "unified";
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
isUnifiedProcessor,
|
|
32
|
+
unified
|
|
33
|
+
};
|
package/dist/rehype-prism.js
CHANGED
|
@@ -4,11 +4,9 @@ const rehypePrism = (excludeLangs) => {
|
|
|
4
4
|
return async (tree) => {
|
|
5
5
|
await highlightCodeBlocks(
|
|
6
6
|
tree,
|
|
7
|
-
(code, language) => {
|
|
8
|
-
let { html, classLanguage } = runHighlighterWithAstro(language, code);
|
|
9
|
-
return
|
|
10
|
-
`<pre class="${classLanguage}" data-language="${language}"><code class="${classLanguage}">${html}</code></pre>`
|
|
11
|
-
);
|
|
7
|
+
async (code, language) => {
|
|
8
|
+
let { html, classLanguage } = await runHighlighterWithAstro(language, code);
|
|
9
|
+
return `<pre class="${classLanguage}" data-language="${language}"><code class="${classLanguage}">${html}</code></pre>`;
|
|
12
10
|
},
|
|
13
11
|
excludeLangs
|
|
14
12
|
);
|
package/dist/rehype-shiki.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Root } from 'hast';
|
|
2
2
|
import type { Plugin } from 'unified';
|
|
3
|
-
import type { ShikiConfig } from '
|
|
3
|
+
import type { ShikiConfig } from '@astrojs/internal-helpers/markdown';
|
|
4
4
|
export declare const rehypeShiki: Plugin<[ShikiConfig, string[]?], Root>;
|
package/dist/rehype-shiki.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { highlightCodeBlocks } from "./highlight.js";
|
|
2
|
-
import { createShikiHighlighter } from "
|
|
2
|
+
import { createShikiHighlighter } from "@astrojs/internal-helpers/shiki";
|
|
3
3
|
const rehypeShiki = (config, excludeLangs) => {
|
|
4
4
|
let highlighterAsync;
|
|
5
5
|
return async (tree) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
2
|
import type { VFile } from 'vfile';
|
|
3
|
-
import type {
|
|
4
|
-
export declare function remarkCollectImages(opts:
|
|
3
|
+
import type { AstroMarkdownOptions } from '@astrojs/internal-helpers/markdown';
|
|
4
|
+
export declare function remarkCollectImages(opts: AstroMarkdownOptions['image']): (tree: Root, vfile: VFile) => void;
|
package/dist/shiki.d.ts
CHANGED
|
@@ -1,44 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { type HighlighterCoreOptions, type LanguageRegistration, type ShikiTransformer, type ThemeRegistration, type ThemeRegistrationRaw } from 'shiki';
|
|
3
|
-
import type { ThemePresets } from './types.js';
|
|
4
|
-
export interface ShikiHighlighter {
|
|
5
|
-
codeToHast(code: string, lang?: string, options?: ShikiHighlighterHighlightOptions): Promise<Root>;
|
|
6
|
-
codeToHtml(code: string, lang?: string, options?: ShikiHighlighterHighlightOptions): Promise<string>;
|
|
7
|
-
}
|
|
8
|
-
export interface CreateShikiHighlighterOptions {
|
|
9
|
-
langs?: LanguageRegistration[];
|
|
10
|
-
theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
|
|
11
|
-
themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
|
|
12
|
-
langAlias?: HighlighterCoreOptions['langAlias'];
|
|
13
|
-
}
|
|
14
|
-
export interface ShikiHighlighterHighlightOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Generate inline code element only, without the pre element wrapper.
|
|
17
|
-
*/
|
|
18
|
-
inline?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Enable word wrapping.
|
|
21
|
-
* - true: enabled.
|
|
22
|
-
* - false: disabled.
|
|
23
|
-
* - null: All overflow styling removed. Code will overflow the element by default.
|
|
24
|
-
*/
|
|
25
|
-
wrap?: boolean | null;
|
|
26
|
-
/**
|
|
27
|
-
* Chooses a theme from the "themes" option that you've defined as the default styling theme.
|
|
28
|
-
*/
|
|
29
|
-
defaultColor?: 'light' | 'dark' | string | false;
|
|
30
|
-
/**
|
|
31
|
-
* Shiki transformers to customize the generated HTML by manipulating the hast tree.
|
|
32
|
-
*/
|
|
33
|
-
transformers?: ShikiTransformer[];
|
|
34
|
-
/**
|
|
35
|
-
* Additional attributes to be added to the root code block element.
|
|
36
|
-
*/
|
|
37
|
-
attributes?: Record<string, string>;
|
|
38
|
-
/**
|
|
39
|
-
* Raw `meta` information to be used by Shiki transformers.
|
|
40
|
-
*/
|
|
41
|
-
meta?: string;
|
|
42
|
-
}
|
|
43
|
-
export declare function createShikiHighlighter(options?: CreateShikiHighlighterOptions): Promise<ShikiHighlighter>;
|
|
44
|
-
export type { ThemePresets };
|
|
1
|
+
export { type CreateShikiHighlighterOptions, createShikiHighlighter, type ShikiHighlighter, type ShikiHighlighterHighlightOptions, type ThemePresets, } from '@astrojs/internal-helpers/shiki';
|
package/dist/shiki.js
CHANGED
|
@@ -1,163 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
isSpecialLang
|
|
5
|
-
} from "shiki";
|
|
6
|
-
import { loadShikiEngine } from "#shiki-engine";
|
|
7
|
-
let _cssVariablesTheme;
|
|
8
|
-
const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = createCssVariablesTheme({
|
|
9
|
-
variablePrefix: "--astro-code-"
|
|
10
|
-
}));
|
|
11
|
-
const cachedHighlighters = /* @__PURE__ */ new Map();
|
|
12
|
-
function clearShikiHighlighterCache() {
|
|
13
|
-
cachedHighlighters.clear();
|
|
14
|
-
}
|
|
15
|
-
function createShikiHighlighter(options) {
|
|
16
|
-
const key = getCacheKey(options);
|
|
17
|
-
let highlighterPromise = cachedHighlighters.get(key);
|
|
18
|
-
if (!highlighterPromise) {
|
|
19
|
-
highlighterPromise = createShikiHighlighterInternal(options);
|
|
20
|
-
cachedHighlighters.set(key, highlighterPromise);
|
|
21
|
-
}
|
|
22
|
-
return ensureLanguagesLoaded(highlighterPromise, options?.langs);
|
|
23
|
-
}
|
|
24
|
-
function getCacheKey(options) {
|
|
25
|
-
const keyCache = [];
|
|
26
|
-
const { theme, themes, langAlias } = options ?? {};
|
|
27
|
-
if (theme) {
|
|
28
|
-
keyCache.push(theme);
|
|
29
|
-
}
|
|
30
|
-
if (themes) {
|
|
31
|
-
keyCache.push(Object.entries(themes).sort());
|
|
32
|
-
}
|
|
33
|
-
if (langAlias) {
|
|
34
|
-
keyCache.push(Object.entries(langAlias).sort());
|
|
35
|
-
}
|
|
36
|
-
return keyCache.length > 0 ? JSON.stringify(keyCache) : "";
|
|
37
|
-
}
|
|
38
|
-
async function ensureLanguagesLoaded(promise, langs) {
|
|
39
|
-
const highlighter = await promise;
|
|
40
|
-
if (!langs) {
|
|
41
|
-
return highlighter;
|
|
42
|
-
}
|
|
43
|
-
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
44
|
-
for (const lang of langs) {
|
|
45
|
-
if (typeof lang === "string" && (isSpecialLang(lang) || loadedLanguages.includes(lang))) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
await highlighter.loadLanguage(lang);
|
|
49
|
-
}
|
|
50
|
-
return highlighter;
|
|
51
|
-
}
|
|
52
|
-
let shikiEngine = void 0;
|
|
53
|
-
async function createShikiHighlighterInternal({
|
|
54
|
-
langs = [],
|
|
55
|
-
theme = "github-dark",
|
|
56
|
-
themes = {},
|
|
57
|
-
langAlias = {}
|
|
58
|
-
} = {}) {
|
|
59
|
-
theme = theme === "css-variables" ? cssVariablesTheme() : theme;
|
|
60
|
-
if (shikiEngine === void 0) {
|
|
61
|
-
shikiEngine = await loadShikiEngine();
|
|
62
|
-
}
|
|
63
|
-
const highlighter = await createHighlighter({
|
|
64
|
-
langs: ["plaintext", ...langs],
|
|
65
|
-
langAlias,
|
|
66
|
-
themes: Object.values(themes).length ? Object.values(themes) : [theme],
|
|
67
|
-
engine: shikiEngine
|
|
68
|
-
});
|
|
69
|
-
async function highlight(code, lang = "plaintext", options, to) {
|
|
70
|
-
const resolvedLang = langAlias[lang] ?? lang;
|
|
71
|
-
const loadedLanguages = highlighter.getLoadedLanguages();
|
|
72
|
-
if (!isSpecialLang(lang) && !loadedLanguages.includes(resolvedLang)) {
|
|
73
|
-
try {
|
|
74
|
-
await highlighter.loadLanguage(resolvedLang);
|
|
75
|
-
} catch (_err) {
|
|
76
|
-
const langStr = lang === resolvedLang ? `"${lang}"` : `"${lang}" (aliased to "${resolvedLang}")`;
|
|
77
|
-
console.warn(`[Shiki] The language ${langStr} doesn't exist, falling back to "plaintext".`);
|
|
78
|
-
lang = "plaintext";
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
code = code.replace(/(?:\r\n|\r|\n)$/, "");
|
|
82
|
-
const themeOptions = Object.values(themes).length ? { themes } : { theme };
|
|
83
|
-
const inline = options?.inline ?? false;
|
|
84
|
-
return highlighter[to === "html" ? "codeToHtml" : "codeToHast"](code, {
|
|
85
|
-
...themeOptions,
|
|
86
|
-
defaultColor: options.defaultColor,
|
|
87
|
-
lang,
|
|
88
|
-
// NOTE: while we can spread `options.attributes` here so that Shiki can auto-serialize this as rendered
|
|
89
|
-
// attributes on the top-level tag, it's not clear whether it is fine to pass all attributes as meta, as
|
|
90
|
-
// they're technically neither meta nor parsed from Shiki's `parseMetaString` API.
|
|
91
|
-
meta: options?.meta ? { __raw: options?.meta } : void 0,
|
|
92
|
-
transformers: [
|
|
93
|
-
{
|
|
94
|
-
pre(node) {
|
|
95
|
-
if (inline) {
|
|
96
|
-
node.tagName = "code";
|
|
97
|
-
}
|
|
98
|
-
const {
|
|
99
|
-
class: attributesClass,
|
|
100
|
-
style: attributesStyle,
|
|
101
|
-
...rest
|
|
102
|
-
} = options?.attributes ?? {};
|
|
103
|
-
Object.assign(node.properties, rest);
|
|
104
|
-
const classValue = (normalizePropAsString(node.properties.class) ?? "") + (attributesClass ? ` ${attributesClass}` : "");
|
|
105
|
-
const styleValue = (normalizePropAsString(node.properties.style) ?? "") + (attributesStyle ? `; ${attributesStyle}` : "");
|
|
106
|
-
node.properties.class = classValue.replace(/shiki/g, "astro-code");
|
|
107
|
-
node.properties.dataLanguage = lang;
|
|
108
|
-
if (options.wrap === false || options.wrap === void 0) {
|
|
109
|
-
node.properties.style = styleValue + "; overflow-x: auto;";
|
|
110
|
-
} else if (options.wrap === true) {
|
|
111
|
-
node.properties.style = styleValue + "; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;";
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
line(node) {
|
|
115
|
-
if (resolvedLang === "diff") {
|
|
116
|
-
const innerSpanNode = node.children[0];
|
|
117
|
-
const innerSpanTextNode = innerSpanNode?.type === "element" && innerSpanNode.children?.[0];
|
|
118
|
-
if (innerSpanTextNode && innerSpanTextNode.type === "text") {
|
|
119
|
-
const start = innerSpanTextNode.value[0];
|
|
120
|
-
if (start === "+" || start === "-") {
|
|
121
|
-
innerSpanTextNode.value = innerSpanTextNode.value.slice(1);
|
|
122
|
-
innerSpanNode.children.unshift({
|
|
123
|
-
type: "element",
|
|
124
|
-
tagName: "span",
|
|
125
|
-
properties: { style: "user-select: none;" },
|
|
126
|
-
children: [{ type: "text", value: start }]
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
code(node) {
|
|
133
|
-
if (inline) {
|
|
134
|
-
return node.children[0];
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
...options.transformers ?? []
|
|
139
|
-
]
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
codeToHast(code, lang, options = {}) {
|
|
144
|
-
return highlight(code, lang, options, "hast");
|
|
145
|
-
},
|
|
146
|
-
codeToHtml(code, lang, options = {}) {
|
|
147
|
-
return highlight(code, lang, options, "html");
|
|
148
|
-
},
|
|
149
|
-
loadLanguage(...newLangs) {
|
|
150
|
-
return highlighter.loadLanguage(...newLangs);
|
|
151
|
-
},
|
|
152
|
-
getLoadedLanguages() {
|
|
153
|
-
return highlighter.getLoadedLanguages();
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function normalizePropAsString(value) {
|
|
158
|
-
return Array.isArray(value) ? value.join(" ") : value;
|
|
159
|
-
}
|
|
2
|
+
createShikiHighlighter
|
|
3
|
+
} from "@astrojs/internal-helpers/shiki";
|
|
160
4
|
export {
|
|
161
|
-
clearShikiHighlighterCache,
|
|
162
5
|
createShikiHighlighter
|
|
163
6
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdown-remark",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "withastro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,10 +20,6 @@
|
|
|
20
20
|
"#import-plugin": {
|
|
21
21
|
"browser": "./dist/import-plugin-browser.js",
|
|
22
22
|
"default": "./dist/import-plugin-default.js"
|
|
23
|
-
},
|
|
24
|
-
"#shiki-engine": {
|
|
25
|
-
"workerd": "./dist/shiki-engine-workerd.js",
|
|
26
|
-
"default": "./dist/shiki-engine-default.js"
|
|
27
23
|
}
|
|
28
24
|
},
|
|
29
25
|
"files": [
|
|
@@ -33,7 +29,6 @@
|
|
|
33
29
|
"github-slugger": "^2.0.0",
|
|
34
30
|
"hast-util-from-html": "^2.0.3",
|
|
35
31
|
"hast-util-to-text": "^4.0.2",
|
|
36
|
-
"js-yaml": "^4.1.1",
|
|
37
32
|
"mdast-util-definitions": "^6.0.0",
|
|
38
33
|
"rehype-raw": "^7.0.0",
|
|
39
34
|
"rehype-stringify": "^10.0.1",
|
|
@@ -41,25 +36,22 @@
|
|
|
41
36
|
"remark-parse": "^11.0.0",
|
|
42
37
|
"remark-rehype": "^11.1.2",
|
|
43
38
|
"remark-smartypants": "^3.0.2",
|
|
44
|
-
"retext-smartypants": "^6.2.0",
|
|
45
|
-
"shiki": "^4.0.0",
|
|
46
|
-
"smol-toml": "^1.6.0",
|
|
47
39
|
"unified": "^11.0.5",
|
|
48
40
|
"unist-util-remove-position": "^5.0.0",
|
|
49
41
|
"unist-util-visit": "^5.1.0",
|
|
50
42
|
"unist-util-visit-parents": "^6.0.2",
|
|
51
43
|
"vfile": "^6.0.3",
|
|
52
|
-
"@astrojs/internal-helpers": "0.
|
|
53
|
-
"@astrojs/prism": "4.0.
|
|
44
|
+
"@astrojs/internal-helpers": "0.10.0",
|
|
45
|
+
"@astrojs/prism": "4.0.2"
|
|
54
46
|
},
|
|
55
47
|
"devDependencies": {
|
|
56
48
|
"@types/estree": "^1.0.8",
|
|
57
49
|
"@types/hast": "^3.0.4",
|
|
58
|
-
"@types/js-yaml": "^4.0.9",
|
|
59
50
|
"@types/mdast": "^4.0.4",
|
|
60
51
|
"@types/unist": "^3.0.3",
|
|
61
|
-
"esbuild": "^0.
|
|
52
|
+
"esbuild": "^0.28.0",
|
|
62
53
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
54
|
+
"shiki": "^4.0.0",
|
|
63
55
|
"astro-scripts": "0.0.14"
|
|
64
56
|
},
|
|
65
57
|
"publishConfig": {
|
|
@@ -67,10 +59,9 @@
|
|
|
67
59
|
},
|
|
68
60
|
"scripts": {
|
|
69
61
|
"prepublish": "pnpm build",
|
|
70
|
-
"build": "astro-scripts build \"src/**/*.ts\" && tsc -
|
|
62
|
+
"build": "astro-scripts build \"src/**/*.ts\" && tsc -b",
|
|
71
63
|
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
72
64
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
73
|
-
"test": "astro-scripts test \"test/**/*.test.ts\""
|
|
74
|
-
"typecheck:tests": "tsc --build tsconfig.test.json"
|
|
65
|
+
"test": "astro-scripts test \"test/**/*.test.ts\""
|
|
75
66
|
}
|
|
76
67
|
}
|
package/dist/frontmatter.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare function isFrontmatterValid(frontmatter: Record<string, any>): boolean;
|
|
2
|
-
export declare function extractFrontmatter(code: string): string | undefined;
|
|
3
|
-
export interface ParseFrontmatterOptions {
|
|
4
|
-
/**
|
|
5
|
-
* How the frontmatter should be handled in the returned `content` string.
|
|
6
|
-
* - `preserve`: Keep the frontmatter.
|
|
7
|
-
* - `remove`: Remove the frontmatter.
|
|
8
|
-
* - `empty-with-spaces`: Replace the frontmatter with empty spaces. (preserves sourcemap line/col/offset)
|
|
9
|
-
* - `empty-with-lines`: Replace the frontmatter with empty line breaks. (preserves sourcemap line/col)
|
|
10
|
-
*
|
|
11
|
-
* @default 'remove'
|
|
12
|
-
*/
|
|
13
|
-
frontmatter: 'preserve' | 'remove' | 'empty-with-spaces' | 'empty-with-lines';
|
|
14
|
-
}
|
|
15
|
-
export interface ParseFrontmatterResult {
|
|
16
|
-
frontmatter: Record<string, any>;
|
|
17
|
-
rawFrontmatter: string;
|
|
18
|
-
content: string;
|
|
19
|
-
}
|
|
20
|
-
export declare function parseFrontmatter(code: string, options?: ParseFrontmatterOptions): ParseFrontmatterResult;
|
package/dist/frontmatter.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import yaml from "js-yaml";
|
|
2
|
-
import * as toml from "smol-toml";
|
|
3
|
-
function isFrontmatterValid(frontmatter) {
|
|
4
|
-
try {
|
|
5
|
-
JSON.stringify(frontmatter);
|
|
6
|
-
} catch {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
return typeof frontmatter === "object" && frontmatter !== null;
|
|
10
|
-
}
|
|
11
|
-
const frontmatterRE = /(?:^\uFEFF?|^\s*\n)(?:---|\+\+\+)([\s\S]*?\n)(?:---|\+\+\+)/;
|
|
12
|
-
const frontmatterTypeRE = /(?:^\uFEFF?|^\s*\n)(---|\+\+\+)/;
|
|
13
|
-
function extractFrontmatter(code) {
|
|
14
|
-
return frontmatterRE.exec(code)?.[1];
|
|
15
|
-
}
|
|
16
|
-
function getFrontmatterParser(code) {
|
|
17
|
-
return frontmatterTypeRE.exec(code)?.[1] === "+++" ? ["+++", toml.parse] : ["---", yaml.load];
|
|
18
|
-
}
|
|
19
|
-
function parseFrontmatter(code, options) {
|
|
20
|
-
const rawFrontmatter = extractFrontmatter(code);
|
|
21
|
-
if (rawFrontmatter == null) {
|
|
22
|
-
return { frontmatter: {}, rawFrontmatter: "", content: code };
|
|
23
|
-
}
|
|
24
|
-
const [delims, parser] = getFrontmatterParser(code);
|
|
25
|
-
const parsed = parser(rawFrontmatter);
|
|
26
|
-
const frontmatter = parsed && typeof parsed === "object" ? parsed : {};
|
|
27
|
-
let content;
|
|
28
|
-
switch (options?.frontmatter ?? "remove") {
|
|
29
|
-
case "preserve":
|
|
30
|
-
content = code;
|
|
31
|
-
break;
|
|
32
|
-
case "remove":
|
|
33
|
-
content = code.replace(`${delims}${rawFrontmatter}${delims}`, "");
|
|
34
|
-
break;
|
|
35
|
-
case "empty-with-spaces":
|
|
36
|
-
content = code.replace(
|
|
37
|
-
`${delims}${rawFrontmatter}${delims}`,
|
|
38
|
-
` ${rawFrontmatter.replace(/[^\r\n]/g, " ")} `
|
|
39
|
-
);
|
|
40
|
-
break;
|
|
41
|
-
case "empty-with-lines":
|
|
42
|
-
content = code.replace(
|
|
43
|
-
`${delims}${rawFrontmatter}${delims}`,
|
|
44
|
-
rawFrontmatter.replace(/[^\r\n]/g, "")
|
|
45
|
-
);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
frontmatter,
|
|
50
|
-
rawFrontmatter,
|
|
51
|
-
content
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
export {
|
|
55
|
-
extractFrontmatter,
|
|
56
|
-
isFrontmatterValid,
|
|
57
|
-
parseFrontmatter
|
|
58
|
-
};
|
package/dist/types.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { RemotePattern } from '@astrojs/internal-helpers/remote';
|
|
2
|
-
import type * as hast from 'hast';
|
|
3
|
-
import type * as mdast from 'mdast';
|
|
4
|
-
import type { Options as RemarkRehypeOptions } from 'remark-rehype';
|
|
5
|
-
import type { Options as SmartypantsOptions } from 'retext-smartypants';
|
|
6
|
-
import type { BuiltinTheme } from 'shiki';
|
|
7
|
-
import type * as unified from 'unified';
|
|
8
|
-
import type { CreateShikiHighlighterOptions, ShikiHighlighterHighlightOptions } from './shiki.js';
|
|
9
|
-
export type { Node } from 'unist';
|
|
10
|
-
declare module 'vfile' {
|
|
11
|
-
interface DataMap {
|
|
12
|
-
astro: {
|
|
13
|
-
headings?: MarkdownHeading[];
|
|
14
|
-
localImagePaths?: string[];
|
|
15
|
-
remoteImagePaths?: string[];
|
|
16
|
-
frontmatter?: Record<string, any>;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export type RemarkPlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, mdast.Root>;
|
|
21
|
-
export type RemarkPlugins = (string | [string, any] | RemarkPlugin | [RemarkPlugin, any])[];
|
|
22
|
-
export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugin<PluginParameters, hast.Root>;
|
|
23
|
-
export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
|
|
24
|
-
export type RemarkRehype = RemarkRehypeOptions;
|
|
25
|
-
export type Smartypants = SmartypantsOptions;
|
|
26
|
-
export type ThemePresets = BuiltinTheme | 'css-variables';
|
|
27
|
-
export type SyntaxHighlightConfigType = 'shiki' | 'prism';
|
|
28
|
-
export interface SyntaxHighlightConfig {
|
|
29
|
-
type: SyntaxHighlightConfigType;
|
|
30
|
-
excludeLangs?: string[];
|
|
31
|
-
}
|
|
32
|
-
export interface ShikiConfig extends Pick<CreateShikiHighlighterOptions, 'langs' | 'theme' | 'themes' | 'langAlias'>, Pick<ShikiHighlighterHighlightOptions, 'defaultColor' | 'wrap' | 'transformers'> {
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Configuration options that end up in the markdown section of AstroConfig
|
|
36
|
-
*/
|
|
37
|
-
export interface AstroMarkdownOptions {
|
|
38
|
-
syntaxHighlight?: SyntaxHighlightConfig | SyntaxHighlightConfigType | false;
|
|
39
|
-
shikiConfig?: ShikiConfig;
|
|
40
|
-
remarkPlugins?: RemarkPlugins;
|
|
41
|
-
rehypePlugins?: RehypePlugins;
|
|
42
|
-
remarkRehype?: RemarkRehype;
|
|
43
|
-
gfm?: boolean;
|
|
44
|
-
smartypants?: boolean | SmartypantsOptions;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Extra configuration options from other parts of AstroConfig that get injected into this plugin
|
|
48
|
-
*/
|
|
49
|
-
export interface AstroMarkdownProcessorOptions extends AstroMarkdownOptions {
|
|
50
|
-
image?: {
|
|
51
|
-
domains?: string[];
|
|
52
|
-
remotePatterns?: RemotePattern[];
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export interface MarkdownProcessor {
|
|
56
|
-
render: (content: string, opts?: MarkdownProcessorRenderOptions) => Promise<MarkdownProcessorRenderResult>;
|
|
57
|
-
}
|
|
58
|
-
export interface MarkdownProcessorRenderOptions {
|
|
59
|
-
/** The URL of the file being rendered, used for resolving relative image paths */
|
|
60
|
-
fileURL?: URL;
|
|
61
|
-
/** Used for frontmatter injection plugins */
|
|
62
|
-
frontmatter?: Record<string, any>;
|
|
63
|
-
}
|
|
64
|
-
export interface MarkdownProcessorRenderResult {
|
|
65
|
-
code: string;
|
|
66
|
-
metadata: {
|
|
67
|
-
headings: MarkdownHeading[];
|
|
68
|
-
localImagePaths: string[];
|
|
69
|
-
remoteImagePaths: string[];
|
|
70
|
-
frontmatter: Record<string, any>;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export interface MarkdownHeading {
|
|
74
|
-
depth: number;
|
|
75
|
-
slug: string;
|
|
76
|
-
text: string;
|
|
77
|
-
}
|
package/dist/types.js
DELETED
|
File without changes
|