@astrojs/markdoc 1.0.0-beta.1 → 1.0.0-beta.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/LICENSE +0 -2
- package/README.md +21 -436
- package/components/Renderer.astro +8 -9
- package/components/TreeNode.ts +90 -78
- package/dist/content-entry-type.js +182 -81
- package/dist/extensions/shiki.d.ts +1 -1
- package/dist/extensions/shiki.js +14 -85
- package/dist/heading-ids.d.ts +2 -2
- package/dist/heading-ids.js +1 -4
- package/dist/html/css/parse-inline-css-to-react.js +1 -1
- package/dist/html/css/parse-inline-styles.js +8 -14
- package/dist/html/tagdefs/html.tag.js +35 -0
- package/dist/html/transform/html-token-transform.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/load-config.js +4 -7
- package/dist/options.d.ts +2 -0
- package/dist/{experimental-assets-config.d.ts → runtime-assets-config.d.ts} +1 -1
- package/dist/{experimental-assets-config.js → runtime-assets-config.js} +3 -3
- package/dist/runtime.js +3 -6
- package/dist/tokenizer.js +6 -0
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +1 -9
- package/package.json +20 -28
- package/dist/html/index.d.ts +0 -2
- package/dist/html/index.js +0 -6
|
@@ -11,7 +11,7 @@ function parseInlineCSSToReactLikeObject(css) {
|
|
|
11
11
|
return void 0;
|
|
12
12
|
}
|
|
13
13
|
function convertCssDirectiveNameToReactCamelCase(original) {
|
|
14
|
-
const replaced = original.replace(/-([a-
|
|
14
|
+
const replaced = original.replace(/-([a-z\d])/gi, (_match, char) => {
|
|
15
15
|
return char.toUpperCase();
|
|
16
16
|
});
|
|
17
17
|
return replaced;
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
const COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
|
15
15
|
const NEWLINE_REGEX = /\n/g;
|
|
16
16
|
const WHITESPACE_REGEX = /^\s*/;
|
|
17
|
-
const PROPERTY_REGEX = /^(
|
|
17
|
+
const PROPERTY_REGEX = /^([-#/*\\\w]+(\[[\da-z_-]+\])?)\s*/;
|
|
18
18
|
const COLON_REGEX = /^:\s*/;
|
|
19
|
-
const VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]
|
|
19
|
+
const VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*\)|[^};])+)/;
|
|
20
20
|
const SEMICOLON_REGEX = /^[;\s]*/;
|
|
21
21
|
const TRIM_REGEX = /^\s+|\s+$/g;
|
|
22
22
|
const NEWLINE = "\n";
|
|
@@ -29,15 +29,13 @@ function parseInlineStyles(style, options) {
|
|
|
29
29
|
if (typeof style !== "string") {
|
|
30
30
|
throw new TypeError("First argument must be a string");
|
|
31
31
|
}
|
|
32
|
-
if (!style)
|
|
33
|
-
return [];
|
|
32
|
+
if (!style) return [];
|
|
34
33
|
options = options || {};
|
|
35
34
|
let lineno = 1;
|
|
36
35
|
let column = 1;
|
|
37
36
|
function updatePosition(str) {
|
|
38
37
|
let lines = str.match(NEWLINE_REGEX);
|
|
39
|
-
if (lines)
|
|
40
|
-
lineno += lines.length;
|
|
38
|
+
if (lines) lineno += lines.length;
|
|
41
39
|
let i = str.lastIndexOf(NEWLINE);
|
|
42
40
|
column = ~i ? str.length - i : column + str.length;
|
|
43
41
|
}
|
|
@@ -71,8 +69,7 @@ function parseInlineStyles(style, options) {
|
|
|
71
69
|
}
|
|
72
70
|
function match(re) {
|
|
73
71
|
const m = re.exec(style);
|
|
74
|
-
if (!m)
|
|
75
|
-
return;
|
|
72
|
+
if (!m) return;
|
|
76
73
|
const str = m[0];
|
|
77
74
|
updatePosition(str);
|
|
78
75
|
style = style.slice(str.length);
|
|
@@ -93,8 +90,7 @@ function parseInlineStyles(style, options) {
|
|
|
93
90
|
}
|
|
94
91
|
function comment() {
|
|
95
92
|
const pos = position();
|
|
96
|
-
if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1))
|
|
97
|
-
return;
|
|
93
|
+
if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
|
|
98
94
|
let i = 2;
|
|
99
95
|
while (EMPTY_STRING != style.charAt(i) && (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))) {
|
|
100
96
|
++i;
|
|
@@ -116,11 +112,9 @@ function parseInlineStyles(style, options) {
|
|
|
116
112
|
function declaration() {
|
|
117
113
|
const pos = position();
|
|
118
114
|
const prop = match(PROPERTY_REGEX);
|
|
119
|
-
if (!prop)
|
|
120
|
-
return;
|
|
115
|
+
if (!prop) return;
|
|
121
116
|
comment();
|
|
122
|
-
if (!match(COLON_REGEX))
|
|
123
|
-
return error("property missing ':'");
|
|
117
|
+
if (!match(COLON_REGEX)) return error("property missing ':'");
|
|
124
118
|
const val = match(VALUE_REGEX);
|
|
125
119
|
const ret = pos({
|
|
126
120
|
type: TYPE_DECLARATION,
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
import Markdoc from "@markdoc/markdoc";
|
|
2
|
+
const booleanAttributes = /* @__PURE__ */ new Set([
|
|
3
|
+
"allowfullscreen",
|
|
4
|
+
"async",
|
|
5
|
+
"autofocus",
|
|
6
|
+
"autoplay",
|
|
7
|
+
"checked",
|
|
8
|
+
"controls",
|
|
9
|
+
"default",
|
|
10
|
+
"defer",
|
|
11
|
+
"disabled",
|
|
12
|
+
"disablepictureinpicture",
|
|
13
|
+
"disableremoteplayback",
|
|
14
|
+
"download",
|
|
15
|
+
"formnovalidate",
|
|
16
|
+
"hidden",
|
|
17
|
+
"inert",
|
|
18
|
+
"ismap",
|
|
19
|
+
"itemscope",
|
|
20
|
+
"loop",
|
|
21
|
+
"multiple",
|
|
22
|
+
"muted",
|
|
23
|
+
"nomodule",
|
|
24
|
+
"novalidate",
|
|
25
|
+
"open",
|
|
26
|
+
"playsinline",
|
|
27
|
+
"readonly",
|
|
28
|
+
"required",
|
|
29
|
+
"reversed",
|
|
30
|
+
"selected"
|
|
31
|
+
]);
|
|
2
32
|
import { parseInlineCSSToReactLikeObject } from "../css/parse-inline-css-to-react.js";
|
|
3
33
|
const htmlTag = {
|
|
4
34
|
attributes: {
|
|
@@ -9,6 +39,11 @@ const htmlTag = {
|
|
|
9
39
|
const { name, attrs: unsafeAttributes } = node.attributes;
|
|
10
40
|
const children = node.transformChildren(config);
|
|
11
41
|
const { style, ...safeAttributes } = unsafeAttributes;
|
|
42
|
+
for (const [key, value] of Object.entries(safeAttributes)) {
|
|
43
|
+
if (booleanAttributes.has(key)) {
|
|
44
|
+
safeAttributes[key] = value === "" || value === true || value === "true";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
12
47
|
if (typeof style === "string") {
|
|
13
48
|
const styleObject = parseInlineCSSToReactLikeObject(style);
|
|
14
49
|
safeAttributes.style = styleObject;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** biome-ignore-all lint/correctness/noUnusedImports: not correctly detected because type isn't exported */
|
|
1
2
|
import type { Tokenizer } from '@markdoc/markdoc';
|
|
2
3
|
import type * as Token from 'markdown-it/lib/token';
|
|
3
4
|
export declare function htmlTokenTransform(tokenizer: Tokenizer, tokens: Token[]): Token[];
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getContentEntryType } from "./content-entry-type.js";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
loadMarkdocConfig,
|
|
4
|
+
SUPPORTED_MARKDOC_CONFIG_FILES
|
|
5
5
|
} from "./load-config.js";
|
|
6
6
|
function markdocIntegration(options) {
|
|
7
7
|
let markdocConfigResult;
|
|
@@ -25,7 +25,7 @@ function markdocIntegration(options) {
|
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
27
|
"astro:server:setup": async ({ server }) => {
|
|
28
|
-
server.watcher.on("all", (
|
|
28
|
+
server.watcher.on("all", (_event, entry) => {
|
|
29
29
|
if (SUPPORTED_MARKDOC_CONFIG_FILES.some((f) => entry.endsWith(f))) {
|
|
30
30
|
server.restart();
|
|
31
31
|
}
|
package/dist/load-config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { build as esbuild } from "esbuild";
|
|
2
1
|
import * as fs from "node:fs";
|
|
3
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { build as esbuild } from "esbuild";
|
|
4
4
|
import { MarkdocError } from "./utils.js";
|
|
5
5
|
const SUPPORTED_MARKDOC_CONFIG_FILES = [
|
|
6
6
|
"markdoc.config.js",
|
|
@@ -12,13 +12,11 @@ async function loadMarkdocConfig(astroConfig) {
|
|
|
12
12
|
let markdocConfigUrl;
|
|
13
13
|
for (const filename of SUPPORTED_MARKDOC_CONFIG_FILES) {
|
|
14
14
|
const filePath = new URL(filename, astroConfig.root);
|
|
15
|
-
if (!fs.existsSync(filePath))
|
|
16
|
-
continue;
|
|
15
|
+
if (!fs.existsSync(filePath)) continue;
|
|
17
16
|
markdocConfigUrl = filePath;
|
|
18
17
|
break;
|
|
19
18
|
}
|
|
20
|
-
if (!markdocConfigUrl)
|
|
21
|
-
return;
|
|
19
|
+
if (!markdocConfigUrl) return;
|
|
22
20
|
const { code } = await bundleConfigFile({
|
|
23
21
|
markdocConfigUrl,
|
|
24
22
|
astroConfig
|
|
@@ -65,8 +63,7 @@ async function bundleConfigFile({
|
|
|
65
63
|
}
|
|
66
64
|
]
|
|
67
65
|
});
|
|
68
|
-
if (markdocError)
|
|
69
|
-
throw markdocError;
|
|
66
|
+
if (markdocError) throw markdocError;
|
|
70
67
|
const { text } = result.outputFiles[0];
|
|
71
68
|
return {
|
|
72
69
|
code: text,
|
package/dist/options.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Config as MarkdocConfig } from '@markdoc/markdoc';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const assetsConfig: MarkdocConfig;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Markdoc from "@markdoc/markdoc";
|
|
2
1
|
import { Image } from "astro:assets";
|
|
3
|
-
|
|
2
|
+
import Markdoc from "@markdoc/markdoc";
|
|
3
|
+
const assetsConfig = {
|
|
4
4
|
nodes: {
|
|
5
5
|
image: {
|
|
6
6
|
attributes: {
|
|
@@ -21,5 +21,5 @@ const experimentalAssetsConfig = {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export {
|
|
24
|
-
|
|
24
|
+
assetsConfig
|
|
25
25
|
};
|
package/dist/runtime.js
CHANGED
|
@@ -64,13 +64,11 @@ function mergeConfig(configA, configB) {
|
|
|
64
64
|
function resolveComponentImports(markdocConfig, tagComponentMap, nodeComponentMap) {
|
|
65
65
|
for (const [tag, render] of Object.entries(tagComponentMap)) {
|
|
66
66
|
const config = markdocConfig.tags[tag];
|
|
67
|
-
if (config)
|
|
68
|
-
config.render = render;
|
|
67
|
+
if (config) config.render = render;
|
|
69
68
|
}
|
|
70
69
|
for (const [node, render] of Object.entries(nodeComponentMap)) {
|
|
71
70
|
const config = markdocConfig.nodes[node];
|
|
72
|
-
if (config)
|
|
73
|
-
config.render = render;
|
|
71
|
+
if (config) config.render = render;
|
|
74
72
|
}
|
|
75
73
|
return markdocConfig;
|
|
76
74
|
}
|
|
@@ -88,8 +86,7 @@ function getTextContent(childNodes) {
|
|
|
88
86
|
const headingLevels = [1, 2, 3, 4, 5, 6];
|
|
89
87
|
function collectHeadings(children, collectedHeadings) {
|
|
90
88
|
for (const node of children) {
|
|
91
|
-
if (typeof node !== "object" || !Markdoc.Tag.isTag(node))
|
|
92
|
-
continue;
|
|
89
|
+
if (typeof node !== "object" || !Markdoc.Tag.isTag(node)) continue;
|
|
93
90
|
if (node.attributes.__collectHeading === true && typeof node.attributes.level === "number") {
|
|
94
91
|
collectedHeadings.push({
|
|
95
92
|
slug: node.attributes.id,
|
package/dist/tokenizer.js
CHANGED
|
@@ -11,6 +11,12 @@ function getMarkdocTokenizer(options) {
|
|
|
11
11
|
tokenizerOptions.allowIndentation = true;
|
|
12
12
|
tokenizerOptions.html = true;
|
|
13
13
|
}
|
|
14
|
+
if (options?.ignoreIndentation) {
|
|
15
|
+
tokenizerOptions.allowIndentation = true;
|
|
16
|
+
}
|
|
17
|
+
if (options?.typographer) {
|
|
18
|
+
tokenizerOptions.typographer = options.typographer;
|
|
19
|
+
}
|
|
14
20
|
_cachedMarkdocTokenizers[key] = new Markdoc.Tokenizer(tokenizerOptions);
|
|
15
21
|
}
|
|
16
22
|
return _cachedMarkdocTokenizers[key];
|
package/dist/utils.d.ts
CHANGED
|
@@ -31,15 +31,6 @@ interface ErrorProperties {
|
|
|
31
31
|
*/
|
|
32
32
|
export declare function prependForwardSlash(str: string): string;
|
|
33
33
|
export declare function isValidUrl(str: string): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Identifies Astro components with propagated assets
|
|
36
|
-
* @see 'packages/astro/src/content/consts.ts'
|
|
37
|
-
*/
|
|
38
|
-
export declare const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
39
|
-
/**
|
|
40
|
-
* @see 'packages/astro/src/content/utils.ts'
|
|
41
|
-
*/
|
|
42
|
-
export declare function hasContentFlag(viteId: string, flag: string): boolean;
|
|
43
34
|
/** Identifier for components imports passed as `tags` or `nodes` configuration. */
|
|
44
35
|
export declare const componentConfigSymbol: unique symbol;
|
|
45
36
|
export declare function isComponentConfig(value: unknown): value is ComponentConfig;
|
package/dist/utils.js
CHANGED
|
@@ -8,8 +8,7 @@ class MarkdocError extends Error {
|
|
|
8
8
|
super(...params);
|
|
9
9
|
const { title = "MarkdocError", message, stack, location, hint, frame } = props;
|
|
10
10
|
this.title = title;
|
|
11
|
-
if (message)
|
|
12
|
-
this.message = message;
|
|
11
|
+
if (message) this.message = message;
|
|
13
12
|
this.stack = stack ? stack : this.stack;
|
|
14
13
|
this.loc = location;
|
|
15
14
|
this.hint = hint;
|
|
@@ -27,20 +26,13 @@ function isValidUrl(str) {
|
|
|
27
26
|
return false;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
|
-
const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
31
|
-
function hasContentFlag(viteId, flag) {
|
|
32
|
-
const flags = new URLSearchParams(viteId.split("?")[1] ?? "");
|
|
33
|
-
return flags.has(flag);
|
|
34
|
-
}
|
|
35
29
|
const componentConfigSymbol = Symbol.for("@astrojs/markdoc/component-config");
|
|
36
30
|
function isComponentConfig(value) {
|
|
37
31
|
return typeof value === "object" && value !== null && componentConfigSymbol in value;
|
|
38
32
|
}
|
|
39
33
|
export {
|
|
40
34
|
MarkdocError,
|
|
41
|
-
PROPAGATED_ASSET_FLAG,
|
|
42
35
|
componentConfigSymbol,
|
|
43
|
-
hasContentFlag,
|
|
44
36
|
isComponentConfig,
|
|
45
37
|
isValidUrl,
|
|
46
38
|
prependForwardSlash
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdoc",
|
|
3
3
|
"description": "Add support for Markdoc in your Astro site",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/withastro/astro.git",
|
|
11
|
+
"url": "git+https://github.com/withastro/astro.git",
|
|
12
12
|
"directory": "packages/integrations/markdoc"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
".": "./dist/index.js",
|
|
35
35
|
"./components": "./components/index.ts",
|
|
36
36
|
"./runtime": "./dist/runtime.js",
|
|
37
|
-
"./
|
|
37
|
+
"./runtime-assets-config": "./dist/runtime-assets-config.js",
|
|
38
38
|
"./package.json": "./package.json"
|
|
39
39
|
},
|
|
40
40
|
"typesVersions": {
|
|
@@ -56,43 +56,35 @@
|
|
|
56
56
|
"template"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@markdoc/markdoc": "^0.
|
|
60
|
-
"esbuild": "^0.
|
|
59
|
+
"@markdoc/markdoc": "^0.5.4",
|
|
60
|
+
"esbuild": "^0.25.0",
|
|
61
61
|
"github-slugger": "^2.0.0",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"zod": "^3.17.3",
|
|
67
|
-
"@astrojs/internal-helpers": "0.2.0-beta.1",
|
|
68
|
-
"@astrojs/prism": "3.0.0-beta.0"
|
|
62
|
+
"htmlparser2": "^10.0.0",
|
|
63
|
+
"@astrojs/internal-helpers": "0.7.5",
|
|
64
|
+
"@astrojs/markdown-remark": "7.0.0-alpha.0",
|
|
65
|
+
"@astrojs/prism": "4.0.0-alpha.0"
|
|
69
66
|
},
|
|
70
67
|
"peerDependencies": {
|
|
71
|
-
"astro": "^
|
|
68
|
+
"astro": "^6.0.0-alpha.0"
|
|
72
69
|
},
|
|
73
70
|
"devDependencies": {
|
|
74
|
-
"@types/
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"devalue": "^4.3.2",
|
|
80
|
-
"linkedom": "^0.14.26",
|
|
81
|
-
"mocha": "^9.2.2",
|
|
82
|
-
"rollup": "^3.25.1",
|
|
83
|
-
"vite": "^4.4.6",
|
|
84
|
-
"@astrojs/markdown-remark": "3.0.0-beta.0",
|
|
85
|
-
"astro": "3.0.0-beta.2",
|
|
71
|
+
"@types/markdown-it": "^14.1.2",
|
|
72
|
+
"devalue": "^5.6.1",
|
|
73
|
+
"linkedom": "^0.18.12",
|
|
74
|
+
"vite": "^7.1.7",
|
|
75
|
+
"astro": "6.0.0-beta.0",
|
|
86
76
|
"astro-scripts": "0.0.14"
|
|
87
77
|
},
|
|
88
78
|
"engines": {
|
|
89
|
-
"node": ">=
|
|
79
|
+
"node": "^20.19.5 || >=22.12.0"
|
|
80
|
+
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"provenance": true
|
|
90
83
|
},
|
|
91
84
|
"scripts": {
|
|
92
85
|
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
|
93
86
|
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
94
87
|
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
95
|
-
"test": "
|
|
96
|
-
"test:match": "mocha --timeout 20000 -g"
|
|
88
|
+
"test": "astro-scripts test --timeout 100000 \"test/**/*.test.js\""
|
|
97
89
|
}
|
|
98
90
|
}
|
package/dist/html/index.d.ts
DELETED