@astrojs/markdoc 0.7.0 → 0.7.2
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.
|
@@ -80,7 +80,7 @@ async function getContentEntryType({
|
|
|
80
80
|
});
|
|
81
81
|
const res = `import { Renderer } from '@astrojs/markdoc/components';
|
|
82
82
|
import { createGetHeadings, createContentComponent } from '@astrojs/markdoc/runtime';
|
|
83
|
-
${markdocConfigUrl ? `import markdocConfig from ${JSON.stringify(markdocConfigUrl
|
|
83
|
+
${markdocConfigUrl ? `import markdocConfig from ${JSON.stringify(fileURLToPath(markdocConfigUrl))};` : "const markdocConfig = {};"}
|
|
84
84
|
|
|
85
85
|
import { assetsConfig } from '@astrojs/markdoc/runtime-assets-config';
|
|
86
86
|
markdocConfig.nodes = { ...assetsConfig.nodes, ...markdocConfig.nodes };
|
|
@@ -164,7 +164,7 @@ function getStringifiedImports(componentConfigMap, componentNamePrefix, root) {
|
|
|
164
164
|
let stringifiedComponentImports = "";
|
|
165
165
|
for (const [key, config] of Object.entries(componentConfigMap)) {
|
|
166
166
|
const importName = config.namedExport ? `{ ${config.namedExport} as ${componentNamePrefix + toImportName(key)} }` : componentNamePrefix + toImportName(key);
|
|
167
|
-
const resolvedPath = config.type === "local" ? new URL(config.path, root)
|
|
167
|
+
const resolvedPath = config.type === "local" ? fileURLToPath(new URL(config.path, root)) : config.path;
|
|
168
168
|
stringifiedComponentImports += `import ${importName} from ${JSON.stringify(resolvedPath)};
|
|
169
169
|
`;
|
|
170
170
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ShikiConfig } from 'astro';
|
|
2
2
|
import type { AstroMarkdocConfig } from '../config.js';
|
|
3
|
-
export default function shiki(
|
|
3
|
+
export default function shiki(config?: ShikiConfig): Promise<AstroMarkdocConfig>;
|
package/dist/extensions/shiki.js
CHANGED
|
@@ -1,90 +1,21 @@
|
|
|
1
|
+
import { createShikiHighlighter } from "@astrojs/markdown-remark";
|
|
1
2
|
import Markdoc from "@markdoc/markdoc";
|
|
2
3
|
import { unescapeHTML } from "astro/runtime/server/index.js";
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
"#000001": "var(--astro-code-color-text)",
|
|
6
|
-
"#000002": "var(--astro-code-color-background)",
|
|
7
|
-
"#000004": "var(--astro-code-token-constant)",
|
|
8
|
-
"#000005": "var(--astro-code-token-string)",
|
|
9
|
-
"#000006": "var(--astro-code-token-comment)",
|
|
10
|
-
"#000007": "var(--astro-code-token-keyword)",
|
|
11
|
-
"#000008": "var(--astro-code-token-parameter)",
|
|
12
|
-
"#000009": "var(--astro-code-token-function)",
|
|
13
|
-
"#000010": "var(--astro-code-token-string-expression)",
|
|
14
|
-
"#000011": "var(--astro-code-token-punctuation)",
|
|
15
|
-
"#000012": "var(--astro-code-token-link)"
|
|
16
|
-
};
|
|
17
|
-
const COLOR_REPLACEMENT_REGEX = new RegExp(
|
|
18
|
-
`(${Object.keys(ASTRO_COLOR_REPLACEMENTS).join("|")})`,
|
|
19
|
-
"g"
|
|
20
|
-
);
|
|
21
|
-
const PRE_SELECTOR = /<pre class="(.*?)shiki(.*?)"/;
|
|
22
|
-
const LINE_SELECTOR = /<span class="line"><span style="(.*?)">([\+|\-])/g;
|
|
23
|
-
const INLINE_STYLE_SELECTOR = /style="(.*?)"/;
|
|
24
|
-
const INLINE_STYLE_SELECTOR_GLOBAL = /style="(.*?)"/g;
|
|
25
|
-
const highlighterCache = /* @__PURE__ */ new Map();
|
|
26
|
-
async function shiki({
|
|
27
|
-
langs = [],
|
|
28
|
-
theme = "github-dark",
|
|
29
|
-
wrap = false
|
|
30
|
-
} = {}) {
|
|
31
|
-
const cacheId = typeof theme === "string" ? theme : theme.name || "";
|
|
32
|
-
let highlighter = highlighterCache.get(cacheId);
|
|
33
|
-
if (!highlighter) {
|
|
34
|
-
highlighter = await getHighlighter({
|
|
35
|
-
langs: langs.length ? langs : Object.keys(bundledLanguages),
|
|
36
|
-
themes: [theme]
|
|
37
|
-
});
|
|
38
|
-
highlighterCache.set(cacheId, highlighter);
|
|
39
|
-
}
|
|
4
|
+
async function shiki(config) {
|
|
5
|
+
const highlighter = await createShikiHighlighter(config);
|
|
40
6
|
return {
|
|
41
7
|
nodes: {
|
|
42
8
|
fence: {
|
|
43
9
|
attributes: Markdoc.nodes.fence.attributes,
|
|
44
10
|
transform({ attributes }) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const langExists = highlighter.getLoadedLanguages().includes(attributes.language);
|
|
48
|
-
if (langExists) {
|
|
49
|
-
lang = attributes.language;
|
|
50
|
-
} else {
|
|
51
|
-
console.warn(
|
|
52
|
-
`[Shiki highlighter] The language "${attributes.language}" doesn't exist, falling back to plaintext.`
|
|
53
|
-
);
|
|
54
|
-
lang = "plaintext";
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
lang = "plaintext";
|
|
58
|
-
}
|
|
59
|
-
let html = highlighter.codeToHtml(attributes.content, { lang, theme });
|
|
60
|
-
html = html.replace(PRE_SELECTOR, `<pre class="$1astro-code$2"`);
|
|
61
|
-
if (attributes.language === "diff") {
|
|
62
|
-
html = html.replace(
|
|
63
|
-
LINE_SELECTOR,
|
|
64
|
-
'<span class="line"><span style="$1"><span style="user-select: none;">$2</span>'
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
if (wrap === false) {
|
|
68
|
-
html = html.replace(INLINE_STYLE_SELECTOR, 'style="$1; overflow-x: auto;"');
|
|
69
|
-
} else if (wrap === true) {
|
|
70
|
-
html = html.replace(
|
|
71
|
-
INLINE_STYLE_SELECTOR,
|
|
72
|
-
'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
76
|
-
if (themeName === "css-variables") {
|
|
77
|
-
html = html.replace(INLINE_STYLE_SELECTOR_GLOBAL, (m) => replaceCssVariables(m));
|
|
78
|
-
}
|
|
11
|
+
const lang = typeof attributes.language === "string" ? attributes.language : "plaintext";
|
|
12
|
+
const html = highlighter.highlight(attributes.content, lang);
|
|
79
13
|
return unescapeHTML(html);
|
|
80
14
|
}
|
|
81
15
|
}
|
|
82
16
|
}
|
|
83
17
|
};
|
|
84
18
|
}
|
|
85
|
-
function replaceCssVariables(str) {
|
|
86
|
-
return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
|
|
87
|
-
}
|
|
88
19
|
export {
|
|
89
20
|
shiki as default
|
|
90
21
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdoc",
|
|
3
3
|
"description": "Add support for Markdoc in your Astro site",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"htmlparser2": "^9.0.0",
|
|
64
64
|
"kleur": "^4.1.5",
|
|
65
65
|
"shikiji": "^0.6.8",
|
|
66
|
-
"zod": "3.
|
|
66
|
+
"zod": "^3.22.4",
|
|
67
67
|
"@astrojs/internal-helpers": "0.2.1",
|
|
68
68
|
"@astrojs/prism": "3.0.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"astro": "^3.
|
|
71
|
+
"astro": "^3.0.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/chai": "^4.3.5",
|
|
@@ -81,8 +81,8 @@
|
|
|
81
81
|
"mocha": "^10.2.0",
|
|
82
82
|
"rollup": "^3.28.1",
|
|
83
83
|
"vite": "^4.4.9",
|
|
84
|
-
"@astrojs/markdown-remark": "3.
|
|
85
|
-
"astro": "3.
|
|
84
|
+
"@astrojs/markdown-remark": "3.5.0",
|
|
85
|
+
"astro": "3.5.4",
|
|
86
86
|
"astro-scripts": "0.0.14"
|
|
87
87
|
},
|
|
88
88
|
"engines": {
|