@astrojs/markdoc 0.1.3 → 0.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/README.md +7 -8
- package/dist/config.d.ts +38 -1
- package/dist/config.js +7 -3
- package/dist/index.js +36 -18
- package/dist/nodes/heading.d.ts +4 -0
- package/dist/nodes/heading.js +39 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +7 -0
- package/dist/runtime.d.ts +16 -0
- package/dist/runtime.js +63 -0
- package/package.json +11 -4
- package/template/content-module-types.d.ts +1 -0
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -138
- package/dist/default-config.d.ts +0 -5
- package/dist/default-config.js +0 -13
- package/src/config.ts +0 -6
- package/src/default-config.ts +0 -18
- package/src/experimental-assets-config.ts +0 -29
- package/src/index.ts +0 -188
- package/src/load-config.ts +0 -109
- package/src/utils.ts +0 -98
- package/test/content-collections.test.js +0 -110
- package/test/entry-prop.test.js +0 -58
- package/test/fixtures/content-collections/astro.config.mjs +0 -7
- package/test/fixtures/content-collections/node_modules/.bin/astro +0 -17
- package/test/fixtures/content-collections/package.json +0 -9
- package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +0 -7
- package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +0 -7
- package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +0 -7
- package/test/fixtures/content-collections/src/content/config.ts +0 -12
- package/test/fixtures/content-collections/src/pages/collection.json.js +0 -10
- package/test/fixtures/content-collections/src/pages/entry.json.js +0 -10
- package/test/fixtures/content-collections/utils.js +0 -8
- package/test/fixtures/entry-prop/astro.config.mjs +0 -7
- package/test/fixtures/entry-prop/node_modules/.bin/astro +0 -17
- package/test/fixtures/entry-prop/package.json +0 -9
- package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +0 -9
- package/test/fixtures/entry-prop/src/content/config.ts +0 -9
- package/test/fixtures/entry-prop/src/pages/index.astro +0 -19
- package/test/fixtures/image-assets/astro.config.mjs +0 -10
- package/test/fixtures/image-assets/node_modules/.bin/astro +0 -17
- package/test/fixtures/image-assets/package.json +0 -9
- package/test/fixtures/image-assets/src/assets/alias/cityscape.jpg +0 -0
- package/test/fixtures/image-assets/src/assets/relative/oar.jpg +0 -0
- package/test/fixtures/image-assets/src/content/docs/intro.mdoc +0 -7
- package/test/fixtures/image-assets/src/pages/index.astro +0 -19
- package/test/fixtures/image-assets/src/public/favicon.svg +0 -9
- package/test/fixtures/render-null/astro.config.mjs +0 -7
- package/test/fixtures/render-null/markdoc.config.mjs +0 -26
- package/test/fixtures/render-null/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-null/package.json +0 -9
- package/test/fixtures/render-null/src/content/blog/render-null.mdoc +0 -7
- package/test/fixtures/render-null/src/pages/index.astro +0 -19
- package/test/fixtures/render-simple/astro.config.mjs +0 -7
- package/test/fixtures/render-simple/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-simple/package.json +0 -9
- package/test/fixtures/render-simple/src/content/blog/simple.mdoc +0 -7
- package/test/fixtures/render-simple/src/pages/index.astro +0 -19
- package/test/fixtures/render-with-components/astro.config.mjs +0 -7
- package/test/fixtures/render-with-components/markdoc.config.mjs +0 -28
- package/test/fixtures/render-with-components/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-with-components/package.json +0 -12
- package/test/fixtures/render-with-components/src/components/Code.astro +0 -12
- package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +0 -1
- package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +0 -17
- package/test/fixtures/render-with-components/src/pages/index.astro +0 -19
- package/test/fixtures/render-with-config/astro.config.mjs +0 -7
- package/test/fixtures/render-with-config/markdoc.config.mjs +0 -15
- package/test/fixtures/render-with-config/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-with-config/package.json +0 -9
- package/test/fixtures/render-with-config/src/content/blog/with-config.mdoc +0 -13
- package/test/fixtures/render-with-config/src/pages/index.astro +0 -19
- package/test/image-assets.test.js +0 -76
- package/test/render.test.js +0 -150
- package/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -143,30 +143,29 @@ Use tags like this fancy "aside" to add some *flair* to your docs.
|
|
|
143
143
|
|
|
144
144
|
#### Render Markdoc nodes / HTML elements as Astro components
|
|
145
145
|
|
|
146
|
-
You may also want to map standard HTML elements like headings and paragraphs to components. For this, you can configure a custom [Markdoc node][markdoc-nodes]. This example overrides Markdoc's `heading` node to render a `Heading` component, and passes through
|
|
146
|
+
You may also want to map standard HTML elements like headings and paragraphs to components. For this, you can configure a custom [Markdoc node][markdoc-nodes]. This example overrides Markdoc's `heading` node to render a `Heading` component, and passes through Astro's default heading properties to define attributes and generate heading ids / slugs:
|
|
147
147
|
|
|
148
148
|
```js
|
|
149
149
|
// markdoc.config.mjs
|
|
150
|
-
import { defineMarkdocConfig,
|
|
150
|
+
import { defineMarkdocConfig, nodes } from '@astrojs/markdoc/config';
|
|
151
151
|
import Heading from './src/components/Heading.astro';
|
|
152
152
|
|
|
153
153
|
export default defineMarkdocConfig({
|
|
154
154
|
nodes: {
|
|
155
155
|
heading: {
|
|
156
156
|
render: Heading,
|
|
157
|
-
|
|
157
|
+
...nodes.heading,
|
|
158
158
|
},
|
|
159
159
|
},
|
|
160
160
|
})
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
All Markdown headings will render the `Heading.astro` component and pass `attributes` as component props. For headings, Astro provides the following attributes by default:
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
- `level: number` The heading level 1 - 6
|
|
166
|
+
- `id: string` An `id` generated from the heading's text contents. This corresponds to the `slug` generated by the [content `render()` function](https://docs.astro.build/en/guides/content-collections/#rendering-content-to-html).
|
|
166
167
|
|
|
167
|
-
|
|
168
|
-
### I'm a level 3 heading!
|
|
169
|
-
```
|
|
168
|
+
For example, the heading `### Level 3 heading!` will pass `level: 3` and `id: 'level-3-heading'` as component props.
|
|
170
169
|
|
|
171
170
|
📚 [Find all of Markdoc's built-in nodes and node attributes on their documentation.](https://markdoc.dev/docs/nodes#built-in-nodes)
|
|
172
171
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
1
|
import type { ConfigType as MarkdocConfig } from '@markdoc/markdoc';
|
|
2
|
-
|
|
2
|
+
import _Markdoc from '@markdoc/markdoc';
|
|
3
|
+
export declare const Markdoc: typeof _Markdoc;
|
|
4
|
+
export declare const nodes: {
|
|
5
|
+
heading: import("@markdoc/markdoc").Schema;
|
|
6
|
+
document: import("@markdoc/markdoc").Schema;
|
|
7
|
+
paragraph: import("@markdoc/markdoc").Schema;
|
|
8
|
+
image: import("@markdoc/markdoc").Schema;
|
|
9
|
+
fence: import("@markdoc/markdoc").Schema;
|
|
10
|
+
blockquote: import("@markdoc/markdoc").Schema;
|
|
11
|
+
item: import("@markdoc/markdoc").Schema;
|
|
12
|
+
list: import("@markdoc/markdoc").Schema;
|
|
13
|
+
hr: import("@markdoc/markdoc").Schema;
|
|
14
|
+
table: import("@markdoc/markdoc").Schema;
|
|
15
|
+
td: import("@markdoc/markdoc").Schema;
|
|
16
|
+
th: import("@markdoc/markdoc").Schema;
|
|
17
|
+
tr: import("@markdoc/markdoc").Schema;
|
|
18
|
+
tbody: import("@markdoc/markdoc").Schema;
|
|
19
|
+
thead: import("@markdoc/markdoc").Schema;
|
|
20
|
+
strong: import("@markdoc/markdoc").Schema;
|
|
21
|
+
em: import("@markdoc/markdoc").Schema;
|
|
22
|
+
s: import("@markdoc/markdoc").Schema;
|
|
23
|
+
inline: import("@markdoc/markdoc").Schema;
|
|
24
|
+
link: import("@markdoc/markdoc").Schema;
|
|
25
|
+
code: import("@markdoc/markdoc").Schema;
|
|
26
|
+
text: import("@markdoc/markdoc").Schema;
|
|
27
|
+
hardbreak: import("@markdoc/markdoc").Schema;
|
|
28
|
+
softbreak: import("@markdoc/markdoc").Schema;
|
|
29
|
+
comment: {
|
|
30
|
+
attributes: {
|
|
31
|
+
content: {
|
|
32
|
+
type: StringConstructor;
|
|
33
|
+
required: boolean;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
error: {};
|
|
38
|
+
node: {};
|
|
39
|
+
};
|
|
3
40
|
export declare function defineMarkdocConfig(config: MarkdocConfig): MarkdocConfig;
|
package/dist/config.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _Markdoc from "@markdoc/markdoc";
|
|
2
|
+
import { nodes as astroNodes } from "./nodes/index.js";
|
|
3
|
+
const Markdoc = _Markdoc;
|
|
4
|
+
const nodes = { ...Markdoc.nodes, ...astroNodes };
|
|
2
5
|
function defineMarkdocConfig(config) {
|
|
3
6
|
return config;
|
|
4
7
|
}
|
|
5
8
|
export {
|
|
6
|
-
|
|
7
|
-
defineMarkdocConfig
|
|
9
|
+
Markdoc,
|
|
10
|
+
defineMarkdocConfig,
|
|
11
|
+
nodes
|
|
8
12
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
4
4
|
import { isValidUrl, MarkdocError, parseFrontmatter, prependForwardSlash } from "./utils.js";
|
|
5
5
|
import { emitESMImage } from "astro/assets";
|
|
6
6
|
import { bold, red, yellow } from "kleur/colors";
|
|
7
|
-
import { applyDefaultConfig } from "./default-config.js";
|
|
8
7
|
import { loadMarkdocConfig } from "./load-config.js";
|
|
8
|
+
import { applyDefaultConfig } from "./runtime.js";
|
|
9
9
|
function markdocIntegration(legacyConfig) {
|
|
10
10
|
if (legacyConfig) {
|
|
11
11
|
console.log(
|
|
@@ -38,7 +38,7 @@ function markdocIntegration(legacyConfig) {
|
|
|
38
38
|
async getRenderModule({ entry, viteId }) {
|
|
39
39
|
const ast = Markdoc.parse(entry.body);
|
|
40
40
|
const pluginContext = this;
|
|
41
|
-
const markdocConfig = applyDefaultConfig(userMarkdocConfig,
|
|
41
|
+
const markdocConfig = applyDefaultConfig(userMarkdocConfig, entry);
|
|
42
42
|
const validationErrors = Markdoc.validate(ast, markdocConfig).filter((e) => {
|
|
43
43
|
return (
|
|
44
44
|
// Ignore `variable-undefined` errors.
|
|
@@ -69,24 +69,42 @@ function markdocIntegration(legacyConfig) {
|
|
|
69
69
|
filePath: entry._internal.filePath
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
import { applyDefaultConfig } from '@astrojs/markdoc/
|
|
75
|
-
import
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
import { experimentalAssetsConfig } from '@astrojs/markdoc/experimental-assets-config'
|
|
72
|
+
const res = `import { jsx as h } from 'astro/jsx-runtime';
|
|
73
|
+
import { Renderer } from '@astrojs/markdoc/components';
|
|
74
|
+
import { collectHeadings, applyDefaultConfig, Markdoc, headingSlugger } from '@astrojs/markdoc/runtime';
|
|
75
|
+
import * as entry from ${JSON.stringify(viteId + "?astroContentCollectionEntry")};
|
|
76
|
+
${markdocConfigResult ? `import _userConfig from ${JSON.stringify(
|
|
77
|
+
markdocConfigResult.fileUrl.pathname
|
|
78
|
+
)};
|
|
79
|
+
const userConfig = _userConfig ?? {};` : "const userConfig = {};"}${astroConfig.experimental.assets ? `
|
|
80
|
+
import { experimentalAssetsConfig } from '@astrojs/markdoc/experimental-assets-config';
|
|
81
|
+
userConfig.nodes = { ...experimentalAssetsConfig.nodes, ...userConfig.nodes };` : ""}
|
|
81
82
|
const stringifiedAst = ${JSON.stringify(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
/* Double stringify to encode *as* stringified JSON */
|
|
84
|
+
JSON.stringify(ast)
|
|
85
|
+
)};
|
|
86
|
+
export function getHeadings() {
|
|
87
|
+
${/* Yes, we are transforming twice (once from `getHeadings()` and again from <Content /> in case of variables).
|
|
88
|
+
TODO: propose new `render()` API to allow Markdoc variable passing to `render()` itself,
|
|
89
|
+
instead of the Content component. Would remove double-transform and unlock variable resolution in heading slugs. */
|
|
90
|
+
""}
|
|
91
|
+
headingSlugger.reset();
|
|
92
|
+
const headingConfig = userConfig.nodes?.heading;
|
|
93
|
+
const config = applyDefaultConfig(headingConfig ? { nodes: { heading: headingConfig } } : {}, entry);
|
|
94
|
+
const ast = Markdoc.Ast.fromJSON(stringifiedAst);
|
|
95
|
+
const content = Markdoc.transform(ast, config);
|
|
96
|
+
return collectHeadings(Array.isArray(content) ? content : content.children);
|
|
97
|
+
}
|
|
85
98
|
export async function Content (props) {
|
|
86
|
-
|
|
87
|
-
config
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
headingSlugger.reset();
|
|
100
|
+
const config = applyDefaultConfig({
|
|
101
|
+
...userConfig,
|
|
102
|
+
variables: { ...userConfig.variables, ...props },
|
|
103
|
+
}, entry);
|
|
104
|
+
|
|
105
|
+
return h(Renderer, { config, stringifiedAst });
|
|
106
|
+
}`;
|
|
107
|
+
return { code: res };
|
|
90
108
|
},
|
|
91
109
|
contentModuleTypes: await fs.promises.readFile(
|
|
92
110
|
new URL("../template/content-module-types.d.ts", import.meta.url),
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Markdoc from "@markdoc/markdoc";
|
|
2
|
+
import Slugger from "github-slugger";
|
|
3
|
+
import { getTextContent } from "../runtime.js";
|
|
4
|
+
const headingSlugger = new Slugger();
|
|
5
|
+
function getSlug(attributes, children) {
|
|
6
|
+
if (attributes.id && typeof attributes.id === "string") {
|
|
7
|
+
return attributes.id;
|
|
8
|
+
}
|
|
9
|
+
const textContent = attributes.content ?? getTextContent(children);
|
|
10
|
+
let slug = headingSlugger.slug(textContent);
|
|
11
|
+
if (slug.endsWith("-"))
|
|
12
|
+
slug = slug.slice(0, -1);
|
|
13
|
+
return slug;
|
|
14
|
+
}
|
|
15
|
+
const heading = {
|
|
16
|
+
children: ["inline"],
|
|
17
|
+
attributes: {
|
|
18
|
+
id: { type: String },
|
|
19
|
+
level: { type: Number, required: true, default: 1 }
|
|
20
|
+
},
|
|
21
|
+
transform(node, config) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const { level, ...attributes } = node.transformAttributes(config);
|
|
24
|
+
const children = node.transformChildren(config);
|
|
25
|
+
const slug = getSlug(attributes, children);
|
|
26
|
+
const render = ((_b = (_a = config.nodes) == null ? void 0 : _a.heading) == null ? void 0 : _b.render) ?? `h${level}`;
|
|
27
|
+
const tagProps = (
|
|
28
|
+
// For components, pass down `level` as a prop,
|
|
29
|
+
// alongside `__collectHeading` for our `headings` collector.
|
|
30
|
+
// Avoid accidentally rendering `level` as an HTML attribute otherwise!
|
|
31
|
+
typeof render === "function" ? { ...attributes, id: slug, __collectHeading: true, level } : { ...attributes, id: slug }
|
|
32
|
+
);
|
|
33
|
+
return new Markdoc.Tag(render, tagProps, children);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
heading,
|
|
38
|
+
headingSlugger
|
|
39
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MarkdownHeading } from '@astrojs/markdown-remark';
|
|
2
|
+
import { type ConfigType as MarkdocConfig, type RenderableTreeNode } from '@markdoc/markdoc';
|
|
3
|
+
import type { ContentEntryModule } from 'astro';
|
|
4
|
+
/** Used to reset Slugger cache on each build at runtime */
|
|
5
|
+
export { default as Markdoc } from '@markdoc/markdoc';
|
|
6
|
+
export { headingSlugger } from './nodes/index.js';
|
|
7
|
+
export declare function applyDefaultConfig(config: MarkdocConfig, entry: ContentEntryModule): MarkdocConfig;
|
|
8
|
+
/**
|
|
9
|
+
* Get text content as a string from a Markdoc transform AST
|
|
10
|
+
*/
|
|
11
|
+
export declare function getTextContent(childNodes: RenderableTreeNode[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* Collect headings from Markdoc transform AST
|
|
14
|
+
* for `headings` result on `render()` return value
|
|
15
|
+
*/
|
|
16
|
+
export declare function collectHeadings(children: RenderableTreeNode[]): MarkdownHeading[];
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Markdoc from "@markdoc/markdoc";
|
|
2
|
+
import { nodes as astroNodes } from "./nodes/index.js";
|
|
3
|
+
import { default as default2 } from "@markdoc/markdoc";
|
|
4
|
+
import { headingSlugger } from "./nodes/index.js";
|
|
5
|
+
function applyDefaultConfig(config, entry) {
|
|
6
|
+
return {
|
|
7
|
+
...config,
|
|
8
|
+
variables: {
|
|
9
|
+
entry,
|
|
10
|
+
...config.variables
|
|
11
|
+
},
|
|
12
|
+
nodes: {
|
|
13
|
+
...astroNodes,
|
|
14
|
+
...config.nodes
|
|
15
|
+
}
|
|
16
|
+
// TODO: Syntax highlighting
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getTextContent(childNodes) {
|
|
20
|
+
let text = "";
|
|
21
|
+
for (const node of childNodes) {
|
|
22
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
23
|
+
text += node;
|
|
24
|
+
} else if (typeof node === "object" && Markdoc.Tag.isTag(node)) {
|
|
25
|
+
text += getTextContent(node.children);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return text;
|
|
29
|
+
}
|
|
30
|
+
const headingLevels = [1, 2, 3, 4, 5, 6];
|
|
31
|
+
function collectHeadings(children) {
|
|
32
|
+
let collectedHeadings = [];
|
|
33
|
+
for (const node of children) {
|
|
34
|
+
if (typeof node !== "object" || !Markdoc.Tag.isTag(node))
|
|
35
|
+
continue;
|
|
36
|
+
if (node.attributes.__collectHeading === true && typeof node.attributes.level === "number") {
|
|
37
|
+
collectedHeadings.push({
|
|
38
|
+
slug: node.attributes.id,
|
|
39
|
+
depth: node.attributes.level,
|
|
40
|
+
text: getTextContent(node.children)
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
for (const level of headingLevels) {
|
|
45
|
+
if (node.name === "h" + level) {
|
|
46
|
+
collectedHeadings.push({
|
|
47
|
+
slug: node.attributes.id,
|
|
48
|
+
depth: level,
|
|
49
|
+
text: getTextContent(node.children)
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
collectedHeadings.concat(collectHeadings(node.children));
|
|
54
|
+
}
|
|
55
|
+
return collectedHeadings;
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
default2 as Markdoc,
|
|
59
|
+
applyDefaultConfig,
|
|
60
|
+
collectHeadings,
|
|
61
|
+
getTextContent,
|
|
62
|
+
headingSlugger
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdoc",
|
|
3
3
|
"description": "Add support for Markdoc pages in your Astro site",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -21,22 +21,29 @@
|
|
|
21
21
|
"exports": {
|
|
22
22
|
".": "./dist/index.js",
|
|
23
23
|
"./components": "./components/index.ts",
|
|
24
|
-
"./
|
|
24
|
+
"./runtime": "./dist/runtime.js",
|
|
25
25
|
"./config": "./dist/config.js",
|
|
26
26
|
"./experimental-assets-config": "./dist/experimental-assets-config.js",
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
|
+
"files": [
|
|
30
|
+
"components",
|
|
31
|
+
"dist",
|
|
32
|
+
"template"
|
|
33
|
+
],
|
|
29
34
|
"dependencies": {
|
|
30
35
|
"@markdoc/markdoc": "^0.2.2",
|
|
31
36
|
"esbuild": "^0.17.12",
|
|
37
|
+
"github-slugger": "^2.0.0",
|
|
32
38
|
"gray-matter": "^4.0.3",
|
|
33
39
|
"kleur": "^4.1.5",
|
|
34
40
|
"zod": "^3.17.3"
|
|
35
41
|
},
|
|
36
42
|
"peerDependencies": {
|
|
37
|
-
"astro": "^2.
|
|
43
|
+
"astro": "^2.5.0"
|
|
38
44
|
},
|
|
39
45
|
"devDependencies": {
|
|
46
|
+
"@astrojs/markdown-remark": "^2.2.1",
|
|
40
47
|
"@types/chai": "^4.3.1",
|
|
41
48
|
"@types/html-escaper": "^3.0.0",
|
|
42
49
|
"@types/mocha": "^9.1.1",
|
|
@@ -46,7 +53,7 @@
|
|
|
46
53
|
"mocha": "^9.2.2",
|
|
47
54
|
"rollup": "^3.20.1",
|
|
48
55
|
"vite": "^4.3.1",
|
|
49
|
-
"astro": "2.
|
|
56
|
+
"astro": "2.5.0",
|
|
50
57
|
"astro-scripts": "0.0.14"
|
|
51
58
|
},
|
|
52
59
|
"engines": {
|
package/.turbo/turbo-build.log
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
# @astrojs/markdoc
|
|
2
|
-
|
|
3
|
-
## 0.1.3
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#7045](https://github.com/withastro/astro/pull/7045) [`3a9f72c7f`](https://github.com/withastro/astro/commit/3a9f72c7f30ed173438fd0a222a094e5997b917d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Improve Markdoc validation errors with full message and file preview.
|
|
8
|
-
|
|
9
|
-
- Updated dependencies [[`48395c815`](https://github.com/withastro/astro/commit/48395c81522f7527126699c4f185f7b4488a4b9a), [`630f8c8ef`](https://github.com/withastro/astro/commit/630f8c8ef68fedfa393899c13a072e50145895e8)]:
|
|
10
|
-
- astro@2.4.4
|
|
11
|
-
|
|
12
|
-
## 0.1.2
|
|
13
|
-
|
|
14
|
-
### Patch Changes
|
|
15
|
-
|
|
16
|
-
- [#6932](https://github.com/withastro/astro/pull/6932) [`49514e4ce`](https://github.com/withastro/astro/commit/49514e4ce40fedb39bf7decd2c296258efbdafc7) Thanks [@bluwy](https://github.com/bluwy)! - Upgrade shiki to v0.14.1. This updates the shiki theme colors and adds the theme name to the `pre` tag, e.g. `<pre class="astro-code github-dark">`.
|
|
17
|
-
|
|
18
|
-
- Updated dependencies [[`818252acd`](https://github.com/withastro/astro/commit/818252acda3c00499cea51ffa0f26d4c2ccd3a02), [`80e3d4d3d`](https://github.com/withastro/astro/commit/80e3d4d3d0f7719d8eae5435bba3805503057511), [`3326492b9`](https://github.com/withastro/astro/commit/3326492b94f76ed2b0154dd9b9a1a9eb883c1e31), [`cac4a321e`](https://github.com/withastro/astro/commit/cac4a321e814fb805eb0e3ced469e25261a50885), [`831b67cdb`](https://github.com/withastro/astro/commit/831b67cdb8250f93f66e3b171fab024652bf80f2), [`49514e4ce`](https://github.com/withastro/astro/commit/49514e4ce40fedb39bf7decd2c296258efbdafc7), [`0883fd487`](https://github.com/withastro/astro/commit/0883fd4875548a613df122f0b87a1ca8b7a7cf7d)]:
|
|
19
|
-
- astro@2.4.0
|
|
20
|
-
|
|
21
|
-
## 0.1.1
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- [#6723](https://github.com/withastro/astro/pull/6723) [`73fcc7627`](https://github.com/withastro/astro/commit/73fcc7627e27a001d3ed2f4d046999d91f1aef85) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix: when using `render: null` in your config, content is now rendered without a wrapper element.
|
|
26
|
-
|
|
27
|
-
- Updated dependencies [[`489dd8d69`](https://github.com/withastro/astro/commit/489dd8d69cdd9d7c243cf8bec96051a914984b9c), [`a1a4f45b5`](https://github.com/withastro/astro/commit/a1a4f45b51a80215fa7598da83bd0d9c5acd20d2), [`a1108e037`](https://github.com/withastro/astro/commit/a1108e037115cdb67d03505286c7d3a4fc2a1ff5), [`8b88e4cf1`](https://github.com/withastro/astro/commit/8b88e4cf15c8bea7942b3985380164e0edf7250b), [`d54cbe413`](https://github.com/withastro/astro/commit/d54cbe41349e55f8544212ad9320705f07325920), [`4c347ab51`](https://github.com/withastro/astro/commit/4c347ab51e46f2319d614f8577fe502e3dc816e2), [`ff0430786`](https://github.com/withastro/astro/commit/ff043078630e678348ae4f4757b3015b3b862c16), [`2f2e572e9`](https://github.com/withastro/astro/commit/2f2e572e937fd25451bbc78a05d55b7caa1ca3ec), [`7116c021a`](https://github.com/withastro/astro/commit/7116c021a39eac15a6e1264dfbd11bef0f5d618a)]:
|
|
28
|
-
- astro@2.2.0
|
|
29
|
-
|
|
30
|
-
## 0.1.0
|
|
31
|
-
|
|
32
|
-
### Minor Changes
|
|
33
|
-
|
|
34
|
-
- [#6653](https://github.com/withastro/astro/pull/6653) [`7c439868a`](https://github.com/withastro/astro/commit/7c439868a3bc7d466418da9af669966014f3d9fe) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Simplify Markdoc configuration with a new `markdoc.config.mjs` file. This lets you import Astro components directly to render as Markdoc tags and nodes, without the need for the previous `components` property. This new configuration also unlocks passing variables to your Markdoc from the `Content` component ([see the new docs](https://docs.astro.build/en/guides/integrations-guide/markdoc/#pass-markdoc-variables)).
|
|
35
|
-
|
|
36
|
-
## Migration
|
|
37
|
-
|
|
38
|
-
Move any existing Markdoc config from your `astro.config` to a new `markdoc.config.mjs` file at the root of your project. This should be applied as a default export, with the optional `defineMarkdocConfig()` helper for autocomplete in your editor.
|
|
39
|
-
|
|
40
|
-
This example configures an `aside` Markdoc tag. Note that components should be imported and applied to the `render` attribute _directly,_ instead of passing the name as a string:
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
// markdoc.config.mjs
|
|
44
|
-
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
45
|
-
import Aside from './src/components/Aside.astro';
|
|
46
|
-
|
|
47
|
-
export default defineMarkdocConfig({
|
|
48
|
-
tags: {
|
|
49
|
-
aside: {
|
|
50
|
-
render: Aside,
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
You should also remove the `components` prop from your `Content` components. Since components are imported into your config directly, this is no longer needed.
|
|
57
|
-
|
|
58
|
-
```diff
|
|
59
|
-
---
|
|
60
|
-
- import Aside from '../components/Aside.astro';
|
|
61
|
-
import { getEntryBySlug } from 'astro:content';
|
|
62
|
-
|
|
63
|
-
const entry = await getEntryBySlug('docs', 'why-markdoc');
|
|
64
|
-
const { Content } = await entry.render();
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
<Content
|
|
68
|
-
- components={{ Aside }}
|
|
69
|
-
/>
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Patch Changes
|
|
73
|
-
|
|
74
|
-
- Updated dependencies [[`1f783e320`](https://github.com/withastro/astro/commit/1f783e32075c20b13063599696644f5d47b75d8d), [`2e92e9aa9`](https://github.com/withastro/astro/commit/2e92e9aa976735c3ddb647152bb9c4850136e386), [`adecda7d6`](https://github.com/withastro/astro/commit/adecda7d6009793c5d20519a997e3b7afb08ad57), [`386336441`](https://github.com/withastro/astro/commit/386336441ad70017eea22db0683591126131db21), [`7c439868a`](https://github.com/withastro/astro/commit/7c439868a3bc7d466418da9af669966014f3d9fe), [`25cd3e574`](https://github.com/withastro/astro/commit/25cd3e574999c1c7294a089ad8c39df27ccdbf17), [`4bf87c64f`](https://github.com/withastro/astro/commit/4bf87c64ff7e9ca49e0f5c27e06bd49faaf60542), [`fc0ed9c53`](https://github.com/withastro/astro/commit/fc0ed9c53cd374860bbdb2503318a55ca09a2662)]:
|
|
75
|
-
- astro@2.1.8
|
|
76
|
-
|
|
77
|
-
## 0.0.5
|
|
78
|
-
|
|
79
|
-
### Patch Changes
|
|
80
|
-
|
|
81
|
-
- [#6630](https://github.com/withastro/astro/pull/6630) [`cfcf2e2ff`](https://github.com/withastro/astro/commit/cfcf2e2ffdaa68ace5c84329c05b83559a29d638) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Support automatic image optimization for Markdoc images when using `experimental.assets`. You can [follow our Assets guide](https://docs.astro.build/en/guides/assets/#enabling-assets-in-your-project) to enable this feature in your project. Then, start using relative or aliased image sources in your Markdoc files for automatic optimization:
|
|
82
|
-
|
|
83
|
-
```md
|
|
84
|
-
<!--Relative paths-->
|
|
85
|
-
|
|
86
|
-

|
|
87
|
-
|
|
88
|
-
<!--Or configured aliases-->
|
|
89
|
-
|
|
90
|
-

|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
- Updated dependencies [[`b7194103e`](https://github.com/withastro/astro/commit/b7194103e39267bf59dcd6ba00f522e424219d16), [`cfcf2e2ff`](https://github.com/withastro/astro/commit/cfcf2e2ffdaa68ace5c84329c05b83559a29d638), [`45da39a86`](https://github.com/withastro/astro/commit/45da39a8642d64eb318840b18dfc2b5ccc6561bc), [`7daef9a29`](https://github.com/withastro/astro/commit/7daef9a2993b5d457f3d243a1ebfd1dd383b3327)]:
|
|
94
|
-
- astro@2.1.7
|
|
95
|
-
|
|
96
|
-
## 0.0.4
|
|
97
|
-
|
|
98
|
-
### Patch Changes
|
|
99
|
-
|
|
100
|
-
- [#6588](https://github.com/withastro/astro/pull/6588) [`f42f47dc6`](https://github.com/withastro/astro/commit/f42f47dc6a91cdb6534dab0ecbf9e8e85f00ba40) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Allow access to content collection entry information (including parsed frontmatter and the entry slug) from your Markdoc using the `$entry` variable:
|
|
101
|
-
|
|
102
|
-
```mdx
|
|
103
|
-
---
|
|
104
|
-
title: Hello Markdoc!
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
# {% $entry.data.title %}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
- [#6607](https://github.com/withastro/astro/pull/6607) [`86273b588`](https://github.com/withastro/astro/commit/86273b5881cc61ebee11d40280b4c0aba8f4bb2e) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix: Update Markdoc renderer internals to remove unneeded dependencies
|
|
111
|
-
|
|
112
|
-
- [#6622](https://github.com/withastro/astro/pull/6622) [`b37b86540`](https://github.com/withastro/astro/commit/b37b865400e77e92878d7e150244acce47e933c6) Thanks [@paulrudy](https://github.com/paulrudy)! - Fix README instructions for installing Markdoc manually.
|
|
113
|
-
|
|
114
|
-
## 0.0.3
|
|
115
|
-
|
|
116
|
-
### Patch Changes
|
|
117
|
-
|
|
118
|
-
- [#6552](https://github.com/withastro/astro/pull/6552) [`392ba3e4d`](https://github.com/withastro/astro/commit/392ba3e4d55f73ce9194bd94a2243f1aa62af079) Thanks [@bluwy](https://github.com/bluwy)! - Fix integration return type
|
|
119
|
-
|
|
120
|
-
## 0.0.2
|
|
121
|
-
|
|
122
|
-
### Patch Changes
|
|
123
|
-
|
|
124
|
-
- [#6494](https://github.com/withastro/astro/pull/6494) [`a13e9d7e3`](https://github.com/withastro/astro/commit/a13e9d7e33baccf51e7d4815f99b481ad174bc57) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Consistency improvements to several package descriptions
|
|
125
|
-
|
|
126
|
-
## 0.0.1
|
|
127
|
-
|
|
128
|
-
### Patch Changes
|
|
129
|
-
|
|
130
|
-
- [#6209](https://github.com/withastro/astro/pull/6209) [`fec583909`](https://github.com/withastro/astro/commit/fec583909ab62829dc0c1600e2387979365f2b94) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introduce the (experimental) `@astrojs/markdoc` integration. This unlocks Markdoc inside your Content Collections, bringing support for Astro and UI components in your content. This also improves Astro core internals to make Content Collections extensible to more file types in the future.
|
|
131
|
-
|
|
132
|
-
You can install this integration using the `astro add` command:
|
|
133
|
-
|
|
134
|
-
```
|
|
135
|
-
astro add markdoc
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
[Read the `@astrojs/markdoc` documentation](https://docs.astro.build/en/guides/integrations-guide/markdoc/) for usage instructions, and browse the [new `with-markdoc` starter](https://astro.new/with-markdoc) to try for yourself.
|
package/dist/default-config.d.ts
DELETED
package/dist/default-config.js
DELETED
package/src/config.ts
DELETED
package/src/default-config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ConfigType as MarkdocConfig } from '@markdoc/markdoc';
|
|
2
|
-
import type { ContentEntryModule } from 'astro';
|
|
3
|
-
|
|
4
|
-
export function applyDefaultConfig(
|
|
5
|
-
config: MarkdocConfig,
|
|
6
|
-
ctx: {
|
|
7
|
-
entry: ContentEntryModule;
|
|
8
|
-
}
|
|
9
|
-
): MarkdocConfig {
|
|
10
|
-
return {
|
|
11
|
-
...config,
|
|
12
|
-
variables: {
|
|
13
|
-
entry: ctx.entry,
|
|
14
|
-
...config.variables,
|
|
15
|
-
},
|
|
16
|
-
// TODO: heading ID calculation, Shiki syntax highlighting
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Config as MarkdocConfig } from '@markdoc/markdoc';
|
|
2
|
-
import Markdoc from '@markdoc/markdoc';
|
|
3
|
-
//@ts-expect-error Cannot find module 'astro:assets' or its corresponding type declarations.
|
|
4
|
-
import { Image } from 'astro:assets';
|
|
5
|
-
|
|
6
|
-
// Separate module to only import `astro:assets` when
|
|
7
|
-
// `experimental.assets` flag is set in a project.
|
|
8
|
-
// TODO: merge with `./default-config.ts` when `experimental.assets` is baselined.
|
|
9
|
-
export const experimentalAssetsConfig: MarkdocConfig = {
|
|
10
|
-
nodes: {
|
|
11
|
-
image: {
|
|
12
|
-
attributes: {
|
|
13
|
-
...Markdoc.nodes.image.attributes,
|
|
14
|
-
__optimizedSrc: { type: 'Object' },
|
|
15
|
-
},
|
|
16
|
-
transform(node, config) {
|
|
17
|
-
const attributes = node.transformAttributes(config);
|
|
18
|
-
const children = node.transformChildren(config);
|
|
19
|
-
|
|
20
|
-
if (node.type === 'image' && '__optimizedSrc' in node.attributes) {
|
|
21
|
-
const { __optimizedSrc, ...rest } = node.attributes;
|
|
22
|
-
return new Markdoc.Tag(Image, { ...rest, src: __optimizedSrc }, children);
|
|
23
|
-
} else {
|
|
24
|
-
return new Markdoc.Tag('img', attributes, children);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|