@astrojs/markdoc 0.12.11 → 0.13.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/content-entry-type.js +8 -2
- package/dist/heading-ids.d.ts +2 -1
- package/dist/heading-ids.js +13 -5
- package/dist/runtime.d.ts +4 -4
- package/dist/runtime.js +8 -8
- package/package.json +4 -4
|
@@ -36,7 +36,11 @@ async function getContentEntryType({
|
|
|
36
36
|
const userMarkdocConfig = markdocConfigResult?.config ?? {};
|
|
37
37
|
const markdocConfigUrl = markdocConfigResult?.fileUrl;
|
|
38
38
|
const pluginContext = this;
|
|
39
|
-
const markdocConfig = await setupConfig(
|
|
39
|
+
const markdocConfig = await setupConfig(
|
|
40
|
+
userMarkdocConfig,
|
|
41
|
+
options,
|
|
42
|
+
astroConfig.experimental.headingIdCompat
|
|
43
|
+
);
|
|
40
44
|
const filePath = fileURLToPath(fileUrl);
|
|
41
45
|
raiseValidationErrors({
|
|
42
46
|
ast,
|
|
@@ -93,6 +97,7 @@ markdocConfig.nodes = { ...assetsConfig.nodes, ...markdocConfig.nodes };
|
|
|
93
97
|
|
|
94
98
|
${getStringifiedImports(componentConfigByTagMap, "Tag", astroConfig.root)}
|
|
95
99
|
${getStringifiedImports(componentConfigByNodeMap, "Node", astroConfig.root)}
|
|
100
|
+
const experimentalHeadingIdCompat = ${JSON.stringify(astroConfig.experimental.headingIdCompat || false)}
|
|
96
101
|
|
|
97
102
|
const tagComponentMap = ${getStringifiedMap(componentConfigByTagMap, "Tag")};
|
|
98
103
|
const nodeComponentMap = ${getStringifiedMap(componentConfigByNodeMap, "Node")};
|
|
@@ -104,7 +109,7 @@ const stringifiedAst = ${JSON.stringify(
|
|
|
104
109
|
JSON.stringify(ast)
|
|
105
110
|
)};
|
|
106
111
|
|
|
107
|
-
export const getHeadings = createGetHeadings(stringifiedAst, markdocConfig, options);
|
|
112
|
+
export const getHeadings = createGetHeadings(stringifiedAst, markdocConfig, options, experimentalHeadingIdCompat);
|
|
108
113
|
export const Content = createContentComponent(
|
|
109
114
|
Renderer,
|
|
110
115
|
stringifiedAst,
|
|
@@ -112,6 +117,7 @@ export const Content = createContentComponent(
|
|
|
112
117
|
options,
|
|
113
118
|
tagComponentMap,
|
|
114
119
|
nodeComponentMap,
|
|
120
|
+
experimentalHeadingIdCompat,
|
|
115
121
|
)`;
|
|
116
122
|
return { code: res };
|
|
117
123
|
},
|
package/dist/heading-ids.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import Slugger from 'github-slugger';
|
|
|
3
3
|
type HeadingIdConfig = MarkdocConfig & {
|
|
4
4
|
ctx: {
|
|
5
5
|
headingSlugger: Slugger;
|
|
6
|
+
experimentalHeadingIdCompat: boolean;
|
|
6
7
|
};
|
|
7
8
|
};
|
|
8
9
|
export declare const heading: Schema;
|
|
9
|
-
export declare function setupHeadingConfig(): HeadingIdConfig;
|
|
10
|
+
export declare function setupHeadingConfig(experimentalHeadingIdCompat: boolean): HeadingIdConfig;
|
|
10
11
|
export {};
|
package/dist/heading-ids.js
CHANGED
|
@@ -3,13 +3,15 @@ import Markdoc, {
|
|
|
3
3
|
import Slugger from "github-slugger";
|
|
4
4
|
import { getTextContent } from "./runtime.js";
|
|
5
5
|
import { MarkdocError } from "./utils.js";
|
|
6
|
-
function getSlug(attributes, children, headingSlugger) {
|
|
6
|
+
function getSlug(attributes, children, headingSlugger, experimentalHeadingIdCompat) {
|
|
7
7
|
if (attributes.id && typeof attributes.id === "string") {
|
|
8
8
|
return attributes.id;
|
|
9
9
|
}
|
|
10
10
|
const textContent = attributes.content ?? getTextContent(children);
|
|
11
11
|
let slug = headingSlugger.slug(textContent);
|
|
12
|
-
if (
|
|
12
|
+
if (!experimentalHeadingIdCompat) {
|
|
13
|
+
if (slug.endsWith("-")) slug = slug.slice(0, -1);
|
|
14
|
+
}
|
|
13
15
|
return slug;
|
|
14
16
|
}
|
|
15
17
|
const heading = {
|
|
@@ -26,7 +28,12 @@ const heading = {
|
|
|
26
28
|
message: "Unexpected problem adding heading IDs to Markdoc file. Did you modify the `ctx.headingSlugger` property in your Markdoc config?"
|
|
27
29
|
});
|
|
28
30
|
}
|
|
29
|
-
const slug = getSlug(
|
|
31
|
+
const slug = getSlug(
|
|
32
|
+
attributes,
|
|
33
|
+
children,
|
|
34
|
+
config.ctx.headingSlugger,
|
|
35
|
+
config.ctx.experimentalHeadingIdCompat
|
|
36
|
+
);
|
|
30
37
|
const render = config.nodes?.heading?.render ?? `h${level}`;
|
|
31
38
|
const tagProps = (
|
|
32
39
|
// For components, pass down `level` as a prop,
|
|
@@ -37,11 +44,12 @@ const heading = {
|
|
|
37
44
|
return new Markdoc.Tag(render, tagProps, children);
|
|
38
45
|
}
|
|
39
46
|
};
|
|
40
|
-
function setupHeadingConfig() {
|
|
47
|
+
function setupHeadingConfig(experimentalHeadingIdCompat) {
|
|
41
48
|
const headingSlugger = new Slugger();
|
|
42
49
|
return {
|
|
43
50
|
ctx: {
|
|
44
|
-
headingSlugger
|
|
51
|
+
headingSlugger,
|
|
52
|
+
experimentalHeadingIdCompat
|
|
45
53
|
},
|
|
46
54
|
nodes: {
|
|
47
55
|
heading
|
package/dist/runtime.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ import type { MarkdocIntegrationOptions } from './options.js';
|
|
|
8
8
|
* Called on each file's individual transform.
|
|
9
9
|
* TODO: virtual module to merge configs per-build instead of per-file?
|
|
10
10
|
*/
|
|
11
|
-
export declare function setupConfig(userConfig: AstroMarkdocConfig | undefined, options: MarkdocIntegrationOptions | undefined): Promise<MergedConfig>;
|
|
11
|
+
export declare function setupConfig(userConfig: AstroMarkdocConfig | undefined, options: MarkdocIntegrationOptions | undefined, experimentalHeadingIdCompat: boolean): Promise<MergedConfig>;
|
|
12
12
|
/** Used for synchronous `getHeadings()` function */
|
|
13
|
-
export declare function setupConfigSync(userConfig: AstroMarkdocConfig | undefined, options: MarkdocIntegrationOptions | undefined): MergedConfig;
|
|
13
|
+
export declare function setupConfigSync(userConfig: AstroMarkdocConfig | undefined, options: MarkdocIntegrationOptions | undefined, experimentalHeadingIdCompat: boolean): MergedConfig;
|
|
14
14
|
type MergedConfig = Required<Omit<AstroMarkdocConfig, 'extends'>>;
|
|
15
15
|
/** Merge function from `@markdoc/markdoc` internals */
|
|
16
16
|
export declare function mergeConfig(configA: AstroMarkdocConfig, configB: AstroMarkdocConfig): MergedConfig;
|
|
@@ -24,6 +24,6 @@ export declare function getTextContent(childNodes: RenderableTreeNode[]): string
|
|
|
24
24
|
* for `headings` result on `render()` return value
|
|
25
25
|
*/
|
|
26
26
|
export declare function collectHeadings(children: RenderableTreeNode[], collectedHeadings: MarkdownHeading[]): void;
|
|
27
|
-
export declare function createGetHeadings(stringifiedAst: string, userConfig: AstroMarkdocConfig, options: MarkdocIntegrationOptions | undefined): () => MarkdownHeading[];
|
|
28
|
-
export declare function createContentComponent(Renderer: AstroInstance['default'], stringifiedAst: string, userConfig: AstroMarkdocConfig, options: MarkdocIntegrationOptions | undefined, tagComponentMap: Record<string, AstroInstance['default']>, nodeComponentMap: Record<NodeType, AstroInstance['default']
|
|
27
|
+
export declare function createGetHeadings(stringifiedAst: string, userConfig: AstroMarkdocConfig, options: MarkdocIntegrationOptions | undefined, experimentalHeadingIdCompat: boolean): () => MarkdownHeading[];
|
|
28
|
+
export declare function createContentComponent(Renderer: AstroInstance['default'], stringifiedAst: string, userConfig: AstroMarkdocConfig, options: MarkdocIntegrationOptions | undefined, tagComponentMap: Record<string, AstroInstance['default']>, nodeComponentMap: Record<NodeType, AstroInstance['default']>, experimentalHeadingIdCompat: boolean): import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
29
29
|
export {};
|
package/dist/runtime.js
CHANGED
|
@@ -3,8 +3,8 @@ import Markdoc, {
|
|
|
3
3
|
import { createComponent, renderComponent } from "astro/runtime/server/index.js";
|
|
4
4
|
import { setupHeadingConfig } from "./heading-ids.js";
|
|
5
5
|
import { htmlTag } from "./html/tagdefs/html.tag.js";
|
|
6
|
-
async function setupConfig(userConfig = {}, options) {
|
|
7
|
-
let defaultConfig = setupHeadingConfig();
|
|
6
|
+
async function setupConfig(userConfig = {}, options, experimentalHeadingIdCompat) {
|
|
7
|
+
let defaultConfig = setupHeadingConfig(experimentalHeadingIdCompat);
|
|
8
8
|
if (userConfig.extends) {
|
|
9
9
|
for (let extension of userConfig.extends) {
|
|
10
10
|
if (extension instanceof Promise) {
|
|
@@ -19,8 +19,8 @@ async function setupConfig(userConfig = {}, options) {
|
|
|
19
19
|
}
|
|
20
20
|
return merged;
|
|
21
21
|
}
|
|
22
|
-
function setupConfigSync(userConfig = {}, options) {
|
|
23
|
-
const defaultConfig = setupHeadingConfig();
|
|
22
|
+
function setupConfigSync(userConfig = {}, options, experimentalHeadingIdCompat) {
|
|
23
|
+
const defaultConfig = setupHeadingConfig(experimentalHeadingIdCompat);
|
|
24
24
|
let merged = mergeConfig(defaultConfig, userConfig);
|
|
25
25
|
if (options?.allowHTML) {
|
|
26
26
|
merged = mergeConfig(merged, HTML_CONFIG);
|
|
@@ -107,9 +107,9 @@ function collectHeadings(children, collectedHeadings) {
|
|
|
107
107
|
collectHeadings(node.children, collectedHeadings);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function createGetHeadings(stringifiedAst, userConfig, options) {
|
|
110
|
+
function createGetHeadings(stringifiedAst, userConfig, options, experimentalHeadingIdCompat) {
|
|
111
111
|
return function getHeadings() {
|
|
112
|
-
const config = setupConfigSync(userConfig, options);
|
|
112
|
+
const config = setupConfigSync(userConfig, options, experimentalHeadingIdCompat);
|
|
113
113
|
const ast = Markdoc.Ast.fromJSON(stringifiedAst);
|
|
114
114
|
const content = Markdoc.transform(ast, config);
|
|
115
115
|
let collectedHeadings = [];
|
|
@@ -117,12 +117,12 @@ function createGetHeadings(stringifiedAst, userConfig, options) {
|
|
|
117
117
|
return collectedHeadings;
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
function createContentComponent(Renderer, stringifiedAst, userConfig, options, tagComponentMap, nodeComponentMap) {
|
|
120
|
+
function createContentComponent(Renderer, stringifiedAst, userConfig, options, tagComponentMap, nodeComponentMap, experimentalHeadingIdCompat) {
|
|
121
121
|
return createComponent({
|
|
122
122
|
async factory(result, props) {
|
|
123
123
|
const withVariables = mergeConfig(userConfig, { variables: props });
|
|
124
124
|
const config = resolveComponentImports(
|
|
125
|
-
await setupConfig(withVariables, options),
|
|
125
|
+
await setupConfig(withVariables, options, experimentalHeadingIdCompat),
|
|
126
126
|
tagComponentMap,
|
|
127
127
|
nodeComponentMap
|
|
128
128
|
);
|
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.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"esbuild": "^0.25.0",
|
|
61
61
|
"github-slugger": "^2.0.0",
|
|
62
62
|
"htmlparser2": "^10.0.0",
|
|
63
|
+
"@astrojs/markdown-remark": "6.3.0",
|
|
63
64
|
"@astrojs/internal-helpers": "0.6.1",
|
|
64
|
-
"@astrojs/markdown-remark": "6.2.1",
|
|
65
65
|
"@astrojs/prism": "3.2.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
"@types/markdown-it": "^14.1.2",
|
|
72
72
|
"devalue": "^5.1.1",
|
|
73
73
|
"linkedom": "^0.18.9",
|
|
74
|
-
"vite": "^6.2.
|
|
75
|
-
"astro": "5.
|
|
74
|
+
"vite": "^6.2.1",
|
|
75
|
+
"astro": "5.5.0",
|
|
76
76
|
"astro-scripts": "0.0.14"
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|