@astrojs/markdoc 0.3.1 → 0.3.3
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/README.md +3 -5
- package/components/Renderer.astro +7 -1
- package/components/TreeNode.ts +3 -11
- package/dist/config.d.ts +34 -29
- package/dist/heading-ids.d.ts +6 -5
- package/dist/index.js +16 -2
- package/dist/load-config.d.ts +2 -2
- package/dist/utils.d.ts +0 -5
- package/dist/utils.js +0 -13
- package/package.json +30 -8
package/README.md
CHANGED
|
@@ -151,9 +151,8 @@ import Heading from './src/components/Heading.astro';
|
|
|
151
151
|
export default defineMarkdocConfig({
|
|
152
152
|
nodes: {
|
|
153
153
|
heading: {
|
|
154
|
+
...nodes.heading, // Preserve default anchor link generation
|
|
154
155
|
render: Heading,
|
|
155
|
-
// Preserve default anchor link generation
|
|
156
|
-
...nodes.heading,
|
|
157
156
|
},
|
|
158
157
|
},
|
|
159
158
|
})
|
|
@@ -225,8 +224,8 @@ import { defineMarkdocConfig, nodes } from '@astrojs/markdoc/config';
|
|
|
225
224
|
export default defineMarkdocConfig({
|
|
226
225
|
nodes: {
|
|
227
226
|
document: {
|
|
228
|
-
render: null, // default 'article'
|
|
229
227
|
...nodes.document, // Apply defaults for other options
|
|
228
|
+
render: null, // default 'article'
|
|
230
229
|
},
|
|
231
230
|
},
|
|
232
231
|
})
|
|
@@ -246,9 +245,8 @@ import Quote from './src/components/Quote.astro';
|
|
|
246
245
|
export default defineMarkdocConfig({
|
|
247
246
|
nodes: {
|
|
248
247
|
blockquote: {
|
|
248
|
+
...nodes.blockquote, // Apply Markdoc's defaults for other options
|
|
249
249
|
render: Quote,
|
|
250
|
-
// Apply Markdoc's defaults for other options
|
|
251
|
-
...nodes.blockquote,
|
|
252
250
|
},
|
|
253
251
|
},
|
|
254
252
|
})
|
|
@@ -15,4 +15,10 @@ const ast = Markdoc.Ast.fromJSON(stringifiedAst);
|
|
|
15
15
|
const content = Markdoc.transform(ast, config);
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
{
|
|
19
|
+
Array.isArray(content) ? (
|
|
20
|
+
content.map(async (c) => <ComponentNode treeNode={await createTreeNode(c)} />)
|
|
21
|
+
) : (
|
|
22
|
+
<ComponentNode treeNode={await createTreeNode(content)} />
|
|
23
|
+
)
|
|
24
|
+
}
|
package/components/TreeNode.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AstroInstance } from 'astro';
|
|
2
|
-
import { Fragment } from 'astro/jsx-runtime';
|
|
3
2
|
import type { RenderableTreeNode } from '@markdoc/markdoc';
|
|
4
3
|
import Markdoc from '@markdoc/markdoc';
|
|
5
4
|
import {
|
|
@@ -106,18 +105,11 @@ export const ComponentNode = createComponent({
|
|
|
106
105
|
propagation: 'self',
|
|
107
106
|
});
|
|
108
107
|
|
|
109
|
-
export async function createTreeNode(node: RenderableTreeNode
|
|
108
|
+
export async function createTreeNode(node: RenderableTreeNode): Promise<TreeNode> {
|
|
110
109
|
if (isHTMLString(node)) {
|
|
111
110
|
return { type: 'text', content: node as HTMLString };
|
|
112
111
|
} else if (typeof node === 'string' || typeof node === 'number') {
|
|
113
112
|
return { type: 'text', content: String(node) };
|
|
114
|
-
} else if (Array.isArray(node)) {
|
|
115
|
-
return {
|
|
116
|
-
type: 'component',
|
|
117
|
-
component: Fragment,
|
|
118
|
-
props: {},
|
|
119
|
-
children: await Promise.all(node.map((child) => createTreeNode(child))),
|
|
120
|
-
};
|
|
121
113
|
} else if (node === null || typeof node !== 'object' || !Markdoc.Tag.isTag(node)) {
|
|
122
114
|
return { type: 'text', content: '' };
|
|
123
115
|
}
|
|
@@ -136,7 +128,7 @@ export async function createTreeNode(node: RenderableTreeNode | RenderableTreeNo
|
|
|
136
128
|
};
|
|
137
129
|
} else if (isPropagatedAssetsModule(node.name)) {
|
|
138
130
|
const { collectedStyles, collectedLinks, collectedScripts } = node.name;
|
|
139
|
-
const component = (await node.name.getMod())
|
|
131
|
+
const component = (await node.name.getMod()).default;
|
|
140
132
|
const props = node.attributes;
|
|
141
133
|
|
|
142
134
|
return {
|
|
@@ -160,7 +152,7 @@ export async function createTreeNode(node: RenderableTreeNode | RenderableTreeNo
|
|
|
160
152
|
|
|
161
153
|
type PropagatedAssetsModule = {
|
|
162
154
|
__astroPropagation: true;
|
|
163
|
-
getMod: () => Promise<AstroInstance
|
|
155
|
+
getMod: () => Promise<AstroInstance>;
|
|
164
156
|
collectedStyles: string[];
|
|
165
157
|
collectedLinks: string[];
|
|
166
158
|
collectedScripts: string[];
|
package/dist/config.d.ts
CHANGED
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
import type { ConfigType as MarkdocConfig } from '@markdoc/markdoc';
|
|
1
|
+
import type { Config, ConfigType as MarkdocConfig, MaybePromise, NodeType, Schema } from '@markdoc/markdoc';
|
|
2
2
|
import _Markdoc from '@markdoc/markdoc';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type { AstroInstance } from 'astro';
|
|
4
|
+
type Render = AstroInstance['default'] | string;
|
|
5
|
+
export type AstroMarkdocConfig<C extends Record<string, any> = Record<string, any>> = Omit<MarkdocConfig, 'tags' | 'nodes'> & Partial<{
|
|
6
|
+
tags: Record<string, Schema<Config, Render>>;
|
|
7
|
+
nodes: Partial<Record<NodeType, Schema<Config, Render>>>;
|
|
8
|
+
ctx: C;
|
|
9
|
+
extends: MaybePromise<ResolvedAstroMarkdocConfig>[];
|
|
10
|
+
}>;
|
|
7
11
|
export type ResolvedAstroMarkdocConfig = Omit<AstroMarkdocConfig, 'extends'>;
|
|
8
12
|
export declare const Markdoc: typeof _Markdoc;
|
|
9
13
|
export declare const nodes: {
|
|
10
|
-
heading:
|
|
11
|
-
document:
|
|
12
|
-
paragraph:
|
|
13
|
-
image:
|
|
14
|
-
fence:
|
|
15
|
-
blockquote:
|
|
16
|
-
item:
|
|
17
|
-
list:
|
|
18
|
-
hr:
|
|
19
|
-
table:
|
|
20
|
-
td:
|
|
21
|
-
th:
|
|
22
|
-
tr:
|
|
23
|
-
tbody:
|
|
24
|
-
thead:
|
|
25
|
-
strong:
|
|
26
|
-
em:
|
|
27
|
-
s:
|
|
28
|
-
inline:
|
|
29
|
-
link:
|
|
30
|
-
code:
|
|
31
|
-
text:
|
|
32
|
-
hardbreak:
|
|
33
|
-
softbreak:
|
|
14
|
+
heading: Schema;
|
|
15
|
+
document: Schema;
|
|
16
|
+
paragraph: Schema;
|
|
17
|
+
image: Schema;
|
|
18
|
+
fence: Schema;
|
|
19
|
+
blockquote: Schema;
|
|
20
|
+
item: Schema;
|
|
21
|
+
list: Schema;
|
|
22
|
+
hr: Schema;
|
|
23
|
+
table: Schema;
|
|
24
|
+
td: Schema;
|
|
25
|
+
th: Schema;
|
|
26
|
+
tr: Schema;
|
|
27
|
+
tbody: Schema;
|
|
28
|
+
thead: Schema;
|
|
29
|
+
strong: Schema;
|
|
30
|
+
em: Schema;
|
|
31
|
+
s: Schema;
|
|
32
|
+
inline: Schema;
|
|
33
|
+
link: Schema;
|
|
34
|
+
code: Schema;
|
|
35
|
+
text: Schema;
|
|
36
|
+
hardbreak: Schema;
|
|
37
|
+
softbreak: Schema;
|
|
34
38
|
comment: {
|
|
35
39
|
attributes: {
|
|
36
40
|
content: {
|
|
@@ -43,3 +47,4 @@ export declare const nodes: {
|
|
|
43
47
|
node: {};
|
|
44
48
|
};
|
|
45
49
|
export declare function defineMarkdocConfig(config: AstroMarkdocConfig): AstroMarkdocConfig;
|
|
50
|
+
export {};
|
package/dist/heading-ids.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { type Schema } from '@markdoc/markdoc';
|
|
1
|
+
import { type Config as MarkdocConfig, type Schema } from '@markdoc/markdoc';
|
|
2
2
|
import Slugger from 'github-slugger';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
type HeadingIdConfig = MarkdocConfig & {
|
|
4
|
+
ctx: {
|
|
5
|
+
headingSlugger: Slugger;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
7
8
|
export declare const heading: Schema;
|
|
8
9
|
export declare function setupHeadingConfig(): HeadingIdConfig;
|
|
9
10
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Markdoc from "@markdoc/markdoc";
|
|
2
|
+
import crypto from "node:crypto";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
5
|
import {
|
|
5
|
-
createNameHash,
|
|
6
6
|
hasContentFlag,
|
|
7
7
|
isValidUrl,
|
|
8
8
|
MarkdocError,
|
|
@@ -68,7 +68,11 @@ function markdocIntegration(legacyConfig) {
|
|
|
68
68
|
const pluginContext = this;
|
|
69
69
|
const markdocConfig = await setupConfig(userMarkdocConfig);
|
|
70
70
|
const filePath = fileURLToPath(fileUrl);
|
|
71
|
-
const validationErrors = Markdoc.validate(
|
|
71
|
+
const validationErrors = Markdoc.validate(
|
|
72
|
+
ast,
|
|
73
|
+
/* Raised generics issue with Markdoc core https://github.com/markdoc/markdoc/discussions/400 */
|
|
74
|
+
markdocConfig
|
|
75
|
+
).filter((e) => {
|
|
72
76
|
return (
|
|
73
77
|
// Ignore `variable-undefined` errors.
|
|
74
78
|
// Variables can be configured at runtime,
|
|
@@ -235,6 +239,16 @@ async function emitOptimizedImages(nodeChildren, ctx) {
|
|
|
235
239
|
function shouldOptimizeImage(src) {
|
|
236
240
|
return !isValidUrl(src) && !src.startsWith("/");
|
|
237
241
|
}
|
|
242
|
+
function createNameHash(baseId, hashIds) {
|
|
243
|
+
const baseName = baseId ? path.parse(baseId).name : "index";
|
|
244
|
+
const hash = crypto.createHash("sha256");
|
|
245
|
+
for (const id of hashIds) {
|
|
246
|
+
hash.update(id, "utf-8");
|
|
247
|
+
}
|
|
248
|
+
const h = hash.digest("hex").slice(0, 8);
|
|
249
|
+
const proposedName = baseName + "." + h;
|
|
250
|
+
return proposedName;
|
|
251
|
+
}
|
|
238
252
|
export {
|
|
239
253
|
markdocIntegration as default
|
|
240
254
|
};
|
package/dist/load-config.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Config as MarkdocConfig } from '@markdoc/markdoc';
|
|
2
1
|
import type { AstroConfig } from 'astro';
|
|
2
|
+
import type { AstroMarkdocConfig } from './config.js';
|
|
3
3
|
export type MarkdocConfigResult = {
|
|
4
|
-
config:
|
|
4
|
+
config: AstroMarkdocConfig;
|
|
5
5
|
fileUrl: URL;
|
|
6
6
|
};
|
|
7
7
|
export declare function loadMarkdocConfig(astroConfig: Pick<AstroConfig, 'root'>): Promise<MarkdocConfigResult | undefined>;
|
package/dist/utils.d.ts
CHANGED
|
@@ -46,9 +46,4 @@ export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
|
46
46
|
* @see 'packages/astro/src/content/utils.ts'
|
|
47
47
|
*/
|
|
48
48
|
export declare function hasContentFlag(viteId: string, flag: string): boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Create build hash for manual Rollup chunks.
|
|
51
|
-
* @see 'packages/astro/src/core/build/plugins/plugin-css.ts'
|
|
52
|
-
*/
|
|
53
|
-
export declare function createNameHash(baseId: string, hashIds: string[]): string;
|
|
54
49
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import matter from "gray-matter";
|
|
2
|
-
import crypto from "node:crypto";
|
|
3
|
-
import path from "node:path";
|
|
4
2
|
function parseFrontmatter(fileContents, filePath) {
|
|
5
3
|
try {
|
|
6
4
|
matter.clearCache();
|
|
@@ -59,20 +57,9 @@ function hasContentFlag(viteId, flag) {
|
|
|
59
57
|
const flags = new URLSearchParams(viteId.split("?")[1] ?? "");
|
|
60
58
|
return flags.has(flag);
|
|
61
59
|
}
|
|
62
|
-
function createNameHash(baseId, hashIds) {
|
|
63
|
-
const baseName = baseId ? path.parse(baseId).name : "index";
|
|
64
|
-
const hash = crypto.createHash("sha256");
|
|
65
|
-
for (const id of hashIds) {
|
|
66
|
-
hash.update(id, "utf-8");
|
|
67
|
-
}
|
|
68
|
-
const h = hash.digest("hex").slice(0, 8);
|
|
69
|
-
const proposedName = baseName + "." + h;
|
|
70
|
-
return proposedName;
|
|
71
|
-
}
|
|
72
60
|
export {
|
|
73
61
|
MarkdocError,
|
|
74
62
|
PROPAGATED_ASSET_FLAG,
|
|
75
|
-
createNameHash,
|
|
76
63
|
hasContentFlag,
|
|
77
64
|
isValidUrl,
|
|
78
65
|
parseFrontmatter,
|
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.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -19,32 +19,54 @@
|
|
|
19
19
|
"bugs": "https://github.com/withastro/astro/issues",
|
|
20
20
|
"homepage": "https://docs.astro.build/en/guides/integrations-guide/markdoc/",
|
|
21
21
|
"exports": {
|
|
22
|
-
"./prism":
|
|
23
|
-
|
|
22
|
+
"./prism": {
|
|
23
|
+
"types": "./dist/extensions/prism.d.ts",
|
|
24
|
+
"default": "./dist/extensions/prism.js"
|
|
25
|
+
},
|
|
26
|
+
"./shiki": {
|
|
27
|
+
"types": "./dist/extensions/shiki.d.ts",
|
|
28
|
+
"default": "./dist/extensions/shiki.js"
|
|
29
|
+
},
|
|
30
|
+
"./config": {
|
|
31
|
+
"types": "./dist/config.d.ts",
|
|
32
|
+
"default": "./dist/config.js"
|
|
33
|
+
},
|
|
24
34
|
".": "./dist/index.js",
|
|
25
35
|
"./components": "./components/index.ts",
|
|
26
36
|
"./runtime": "./dist/runtime.js",
|
|
27
|
-
"./config": "./dist/config.js",
|
|
28
37
|
"./experimental-assets-config": "./dist/experimental-assets-config.js",
|
|
29
38
|
"./package.json": "./package.json"
|
|
30
39
|
},
|
|
40
|
+
"typesVersions": {
|
|
41
|
+
"*": {
|
|
42
|
+
"config": [
|
|
43
|
+
"./dist/config.d.ts"
|
|
44
|
+
],
|
|
45
|
+
"prism": [
|
|
46
|
+
"./dist/extensions/prism.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"shiki": [
|
|
49
|
+
"./dist/extensions/shiki.d.ts"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
31
53
|
"files": [
|
|
32
54
|
"components",
|
|
33
55
|
"dist",
|
|
34
56
|
"template"
|
|
35
57
|
],
|
|
36
58
|
"dependencies": {
|
|
37
|
-
"shiki": "^0.14.1",
|
|
38
59
|
"@astrojs/prism": "^2.1.2",
|
|
39
60
|
"@markdoc/markdoc": "^0.3.0",
|
|
40
61
|
"esbuild": "^0.17.12",
|
|
41
62
|
"github-slugger": "^2.0.0",
|
|
42
63
|
"gray-matter": "^4.0.3",
|
|
43
64
|
"kleur": "^4.1.5",
|
|
65
|
+
"shiki": "^0.14.1",
|
|
44
66
|
"zod": "^3.17.3"
|
|
45
67
|
},
|
|
46
68
|
"peerDependencies": {
|
|
47
|
-
"astro": "^2.
|
|
69
|
+
"astro": "^2.6.3"
|
|
48
70
|
},
|
|
49
71
|
"devDependencies": {
|
|
50
72
|
"@astrojs/markdown-remark": "^2.2.1",
|
|
@@ -52,12 +74,12 @@
|
|
|
52
74
|
"@types/html-escaper": "^3.0.0",
|
|
53
75
|
"@types/mocha": "^9.1.1",
|
|
54
76
|
"chai": "^4.3.6",
|
|
55
|
-
"devalue": "^4.2
|
|
77
|
+
"devalue": "^4.3.2",
|
|
56
78
|
"linkedom": "^0.14.12",
|
|
57
79
|
"mocha": "^9.2.2",
|
|
58
80
|
"rollup": "^3.20.1",
|
|
59
81
|
"vite": "^4.3.1",
|
|
60
|
-
"astro": "2.
|
|
82
|
+
"astro": "2.6.3",
|
|
61
83
|
"astro-scripts": "0.0.14"
|
|
62
84
|
},
|
|
63
85
|
"engines": {
|