@andesine/converters 0.1.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/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +366 -0
- package/dist/anchors.d.ts +18 -0
- package/dist/anchors.js +36 -0
- package/dist/anchors.js.map +1 -0
- package/dist/chunks/adapter-CeNgvE5W.js +177 -0
- package/dist/chunks/adapter-CeNgvE5W.js.map +1 -0
- package/dist/chunks/core-DC64ddB7.js +372 -0
- package/dist/chunks/core-DC64ddB7.js.map +1 -0
- package/dist/chunks/decode-B-xzTJFV.js +102 -0
- package/dist/chunks/decode-B-xzTJFV.js.map +1 -0
- package/dist/chunks/decode-BLP2Olia.d.ts +6 -0
- package/dist/chunks/stringify-DdPaV2y4.js +71 -0
- package/dist/chunks/stringify-DdPaV2y4.js.map +1 -0
- package/dist/chunks/types-SDFWRP3z.d.ts +185 -0
- package/dist/html.d.ts +49 -0
- package/dist/html.js +252 -0
- package/dist/html.js.map +1 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/markdoc.d.ts +49 -0
- package/dist/markdoc.js +310 -0
- package/dist/markdoc.js.map +1 -0
- package/dist/markdown.d.ts +48 -0
- package/dist/markdown.js +49 -0
- package/dist/markdown.js.map +1 -0
- package/dist/mdx.d.ts +50 -0
- package/dist/mdx.js +110 -0
- package/dist/mdx.js.map +1 -0
- package/dist/text.d.ts +36 -0
- package/dist/text.js +69 -0
- package/dist/text.js.map +1 -0
- package/package.json +98 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getHeadingAnchors } from "./anchors.js";
|
|
2
|
+
import { a as element, c as textContent, i as ConversionError, l as textNode, n as createExportConverter, r as createImportConverter, t as createConverter, u as withMark } from "./chunks/core-DC64ddB7.js";
|
|
3
|
+
//#region src/images.ts
|
|
4
|
+
/**
|
|
5
|
+
* Create an async imageURL callback from published asset references.
|
|
6
|
+
* @param assets - Assets from the same entry and snapshot as the document being converted.
|
|
7
|
+
* @param options - Image variant or async variant selector. Defaults to "display".
|
|
8
|
+
* @returns A callback that looks up node.attrs.assetID and returns the supplied URL unchanged.
|
|
9
|
+
* It does not fetch images, refresh expiring URLs, or fall back to another variant.
|
|
10
|
+
* @throws ConversionError when the callback cannot find the requested asset and variant.
|
|
11
|
+
*/
|
|
12
|
+
const createImageURLResolver = (assets, options = {}) => {
|
|
13
|
+
const urls = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const asset of assets) {
|
|
15
|
+
const variants = urls.get(asset.assetID) || /* @__PURE__ */ new Map();
|
|
16
|
+
variants.set(asset.variant, asset.url);
|
|
17
|
+
urls.set(asset.assetID, variants);
|
|
18
|
+
}
|
|
19
|
+
return async (node) => {
|
|
20
|
+
const assetID = node.attrs?.assetID;
|
|
21
|
+
const variant = typeof options.variant === "function" ? await options.variant(node) : options.variant ?? "display";
|
|
22
|
+
const url = typeof assetID === "string" ? urls.get(assetID)?.get(variant) : void 0;
|
|
23
|
+
if (!url) throw new ConversionError(`Image asset ${String(assetID)} has no URL for variant ${variant}`);
|
|
24
|
+
return url;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Supply converter options derived from a published-content response or full list item.
|
|
29
|
+
* @param page - An object with the document's published asset references; no SDK type is required.
|
|
30
|
+
* @param options - Image variant settings passed to createImageURLResolver().
|
|
31
|
+
* @returns An imageURL callback only. Title, fragment, and property defaults remain unchanged.
|
|
32
|
+
* Missing asset URLs throw ConversionError when an image is converted, not during this call.
|
|
33
|
+
* @example
|
|
34
|
+
* const html = await toHTML(page.content, { ...publishedContentOptions(page), title: "omit" });
|
|
35
|
+
*/
|
|
36
|
+
const publishedContentOptions = (page, options) => ({ imageURL: createImageURLResolver(page.assets, options) });
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ConversionError, createConverter, createExportConverter, createImageURLResolver, createImportConverter, element, getHeadingAnchors, publishedContentOptions, textContent, textNode, withMark };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/images.ts"],"sourcesContent":["import type { Awaitable, ContentNode } from \"./types\";\nimport { ConversionError } from \"./utils\";\n\ninterface ImageAsset {\n assetID: string;\n variant: string;\n url: string;\n}\ninterface ImageURLOptions {\n /** Variant to resolve, or an async selector for each image. Defaults to \"display\". */\n variant?: string | ((node: ContentNode) => Awaitable<string>);\n}\ninterface PublishedImageContent {\n assets: readonly ImageAsset[];\n}\n\n/**\n * Create an async imageURL callback from published asset references.\n * @param assets - Assets from the same entry and snapshot as the document being converted.\n * @param options - Image variant or async variant selector. Defaults to \"display\".\n * @returns A callback that looks up node.attrs.assetID and returns the supplied URL unchanged.\n * It does not fetch images, refresh expiring URLs, or fall back to another variant.\n * @throws ConversionError when the callback cannot find the requested asset and variant.\n */\nconst createImageURLResolver = (assets: readonly ImageAsset[], options: ImageURLOptions = {}) => {\n const urls = new Map<string, Map<string, string>>();\n\n for (const asset of assets) {\n const variants = urls.get(asset.assetID) || new Map<string, string>();\n variants.set(asset.variant, asset.url);\n urls.set(asset.assetID, variants);\n }\n\n return async (node: ContentNode): Promise<string> => {\n const assetID = node.attrs?.assetID;\n const variant =\n typeof options.variant === \"function\"\n ? await options.variant(node)\n : (options.variant ?? \"display\");\n const url = typeof assetID === \"string\" ? urls.get(assetID)?.get(variant) : undefined;\n\n if (!url) {\n throw new ConversionError(`Image asset ${String(assetID)} has no URL for variant ${variant}`);\n }\n\n return url;\n };\n};\n/**\n * Supply converter options derived from a published-content response or full list item.\n * @param page - An object with the document's published asset references; no SDK type is required.\n * @param options - Image variant settings passed to createImageURLResolver().\n * @returns An imageURL callback only. Title, fragment, and property defaults remain unchanged.\n * Missing asset URLs throw ConversionError when an image is converted, not during this call.\n * @example\n * const html = await toHTML(page.content, { ...publishedContentOptions(page), title: \"omit\" });\n */\nconst publishedContentOptions = (page: PublishedImageContent, options?: ImageURLOptions) => ({\n imageURL: createImageURLResolver(page.assets, options)\n});\n\nexport { createImageURLResolver, publishedContentOptions };\nexport type { ImageAsset, ImageURLOptions, PublishedImageContent };\n"],"mappings":";;;;;;;;;;;AAwBA,MAAM,0BAA0B,QAA+B,UAA2B,CAAC,MAAM;CAC/F,MAAM,uBAAO,IAAI,IAAiC;CAElD,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,WAAW,KAAK,IAAI,MAAM,OAAO,qBAAK,IAAI,IAAoB;EACpE,SAAS,IAAI,MAAM,SAAS,MAAM,GAAG;EACrC,KAAK,IAAI,MAAM,SAAS,QAAQ;CAClC;CAEA,OAAO,OAAO,SAAuC;EACnD,MAAM,UAAU,KAAK,OAAO;EAC5B,MAAM,UACJ,OAAO,QAAQ,YAAY,aACvB,MAAM,QAAQ,QAAQ,IAAI,IACzB,QAAQ,WAAW;EAC1B,MAAM,MAAM,OAAO,YAAY,WAAW,KAAK,IAAI,OAAO,CAAC,EAAE,IAAI,OAAO,IAAI,KAAA;EAE5E,IAAI,CAAC,KACH,MAAM,IAAI,gBAAgB,eAAe,OAAO,OAAO,EAAE,0BAA0B,SAAS;EAG9F,OAAO;CACT;AACF;;;;;;;;;;AAUA,MAAM,2BAA2B,MAA6B,aAA+B,EAC3F,UAAU,uBAAuB,KAAK,QAAQ,OAAO,EACvD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { a as Converter, f as ExportConverterOptions, i as ConvertedAST, m as FormatAdapter, o as ConverterOptions, r as ContentNode, y as ImportConverterOptions } from "./chunks/types-SDFWRP3z.js";
|
|
2
|
+
import Markdoc from "@markdoc/markdoc";
|
|
3
|
+
//#region src/markdoc.d.ts
|
|
4
|
+
type MarkdocNode = InstanceType<typeof Markdoc.Ast.Node>;
|
|
5
|
+
type MarkdocOptions = ConverterOptions<MarkdocNode>;
|
|
6
|
+
/** Markdoc adapter for createConverter(), including its parser and node/mark mappings. */
|
|
7
|
+
declare const markdocAdapter: FormatAdapter<MarkdocNode>;
|
|
8
|
+
/**
|
|
9
|
+
* Create a reusable async Markdoc converter with application-specific defaults.
|
|
10
|
+
* @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.
|
|
11
|
+
* @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.
|
|
12
|
+
* Custom elements use Markdoc tags with static properties.
|
|
13
|
+
*/
|
|
14
|
+
declare const createMarkdocConverter: (options?: MarkdocOptions) => Converter<import("@markdoc/markdoc").Node>;
|
|
15
|
+
/**
|
|
16
|
+
* Export ProseMirror JSON as Markdoc.
|
|
17
|
+
* @param document - Entry or fragment document. Fragment wrappers are removed by default.
|
|
18
|
+
* @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.
|
|
19
|
+
* @returns Serialized Markdoc. Omitted metadata and unwrapped fragment boundaries are not recoverable.
|
|
20
|
+
* @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.
|
|
21
|
+
*/
|
|
22
|
+
declare const toMarkdoc: (document: ContentNode, options?: ExportConverterOptions<import("@markdoc/markdoc").Node> | undefined) => Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Import Markdoc as ProseMirror JSON without saving content or uploading assets.
|
|
25
|
+
* @param source - Source text to parse. Custom elements use Markdoc tags with static properties.
|
|
26
|
+
* @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.
|
|
27
|
+
* @returns An entry document; use document: "fragment" to omit the title and retain the first H1 as body content.
|
|
28
|
+
* @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.
|
|
29
|
+
*/
|
|
30
|
+
declare const fromMarkdoc: (source: string, options?: ImportConverterOptions<import("@markdoc/markdoc").Node> | undefined) => Promise<ContentNode>;
|
|
31
|
+
/**
|
|
32
|
+
* Export ProseMirror JSON as a Markdoc AST with separate frontmatter.
|
|
33
|
+
* @param document - Source entry or fragment document.
|
|
34
|
+
* @param options - Export mappings and async handlers, including imageURL for images.
|
|
35
|
+
* @returns The format tree and metadata without string serialization.
|
|
36
|
+
* @throws The same conversion errors as toMarkdoc(), including unsupported frontmatter mappings.
|
|
37
|
+
*/
|
|
38
|
+
declare const toMarkdocAST: (document: ContentNode, options?: ExportConverterOptions<import("@markdoc/markdoc").Node> | undefined) => Promise<ConvertedAST<import("@markdoc/markdoc").Node>>;
|
|
39
|
+
/**
|
|
40
|
+
* Import a parsed Markdoc AST and its frontmatter as ProseMirror JSON.
|
|
41
|
+
* @param input - Tree and frontmatter object; use an empty object when metadata is absent.
|
|
42
|
+
* @param options - Import mappings and async handlers, including imageAssetID for images.
|
|
43
|
+
* @returns An entry document by default, or a fragment document when requested.
|
|
44
|
+
* @throws The same conversion errors as fromMarkdoc(), excluding string-parser errors.
|
|
45
|
+
*/
|
|
46
|
+
declare const fromMarkdocAST: (input: ConvertedAST<import("@markdoc/markdoc").Node>, options?: ImportConverterOptions<import("@markdoc/markdoc").Node> | undefined) => Promise<ContentNode>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { type MarkdocNode, type MarkdocOptions, createMarkdocConverter, fromMarkdoc, fromMarkdocAST, markdocAdapter, toMarkdoc, toMarkdocAST };
|
|
49
|
+
//# sourceMappingURL=markdoc.d.ts.map
|
package/dist/markdoc.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { a as element, c as textContent, i as ConversionError, l as textNode, o as isJSONValue, s as lookup, t as createConverter, u as withMark } from "./chunks/core-DC64ddB7.js";
|
|
2
|
+
import { n as paragraphContent } from "./chunks/decode-B-xzTJFV.js";
|
|
3
|
+
import { n as normalizeMarkdown, t as markdownStringifyOptions } from "./chunks/stringify-DdPaV2y4.js";
|
|
4
|
+
import { unified } from "unified";
|
|
5
|
+
import remarkStringify from "remark-stringify";
|
|
6
|
+
import remarkGFM from "remark-gfm";
|
|
7
|
+
import Markdoc from "@markdoc/markdoc";
|
|
8
|
+
//#region src/markdoc/serialize.ts
|
|
9
|
+
const processor = unified().use(remarkGFM).use(remarkStringify, {
|
|
10
|
+
...markdownStringifyOptions,
|
|
11
|
+
unsafe: [{
|
|
12
|
+
character: "{",
|
|
13
|
+
after: "%"
|
|
14
|
+
}]
|
|
15
|
+
});
|
|
16
|
+
const serializeMarkdoc = (tree) => {
|
|
17
|
+
const convert = (node) => {
|
|
18
|
+
const attrs = node.attributes;
|
|
19
|
+
const children = node.children.flatMap(convert);
|
|
20
|
+
const inline = children;
|
|
21
|
+
switch (node.type) {
|
|
22
|
+
case "document": return [{
|
|
23
|
+
type: "root",
|
|
24
|
+
children
|
|
25
|
+
}];
|
|
26
|
+
case "inline":
|
|
27
|
+
case "thead":
|
|
28
|
+
case "tbody": return children;
|
|
29
|
+
case "text": return [{
|
|
30
|
+
type: "text",
|
|
31
|
+
value: String(attrs.content || "")
|
|
32
|
+
}];
|
|
33
|
+
case "paragraph": return [{
|
|
34
|
+
type: "paragraph",
|
|
35
|
+
children: inline
|
|
36
|
+
}];
|
|
37
|
+
case "heading": return [{
|
|
38
|
+
type: "heading",
|
|
39
|
+
depth: Number(attrs.level || 1),
|
|
40
|
+
children: inline
|
|
41
|
+
}];
|
|
42
|
+
case "strong": return [{
|
|
43
|
+
type: "strong",
|
|
44
|
+
children: inline
|
|
45
|
+
}];
|
|
46
|
+
case "em": return [{
|
|
47
|
+
type: "emphasis",
|
|
48
|
+
children: inline
|
|
49
|
+
}];
|
|
50
|
+
case "s": return [{
|
|
51
|
+
type: "delete",
|
|
52
|
+
children: inline
|
|
53
|
+
}];
|
|
54
|
+
case "code": return [{
|
|
55
|
+
type: "inlineCode",
|
|
56
|
+
value: String(attrs.content || "")
|
|
57
|
+
}];
|
|
58
|
+
case "link": return [{
|
|
59
|
+
type: "link",
|
|
60
|
+
url: String(attrs.href || ""),
|
|
61
|
+
children: inline
|
|
62
|
+
}];
|
|
63
|
+
case "image": return [{
|
|
64
|
+
type: "image",
|
|
65
|
+
url: String(attrs.src || ""),
|
|
66
|
+
alt: String(attrs.alt || ""),
|
|
67
|
+
title: attrs.title || null
|
|
68
|
+
}];
|
|
69
|
+
case "blockquote": return [{
|
|
70
|
+
type: "blockquote",
|
|
71
|
+
children
|
|
72
|
+
}];
|
|
73
|
+
case "list": return [{
|
|
74
|
+
type: "list",
|
|
75
|
+
ordered: Boolean(attrs.ordered),
|
|
76
|
+
start: Number(attrs.start || 1),
|
|
77
|
+
children
|
|
78
|
+
}];
|
|
79
|
+
case "item": return [{
|
|
80
|
+
type: "listItem",
|
|
81
|
+
children
|
|
82
|
+
}];
|
|
83
|
+
case "fence": return [{
|
|
84
|
+
type: "code",
|
|
85
|
+
lang: String(attrs.language || ""),
|
|
86
|
+
value: String(attrs.content || "")
|
|
87
|
+
}];
|
|
88
|
+
case "hardbreak": return [{ type: "break" }];
|
|
89
|
+
case "softbreak": return [{
|
|
90
|
+
type: "text",
|
|
91
|
+
value: "\n"
|
|
92
|
+
}];
|
|
93
|
+
case "hr": return [{ type: "thematicBreak" }];
|
|
94
|
+
case "table": return [{
|
|
95
|
+
type: "table",
|
|
96
|
+
children
|
|
97
|
+
}];
|
|
98
|
+
case "tr": return [{
|
|
99
|
+
type: "tableRow",
|
|
100
|
+
children
|
|
101
|
+
}];
|
|
102
|
+
case "td":
|
|
103
|
+
case "th": return [{
|
|
104
|
+
type: "tableCell",
|
|
105
|
+
children: inline
|
|
106
|
+
}];
|
|
107
|
+
case "tag": {
|
|
108
|
+
const opening = Markdoc.format(new Markdoc.Ast.Node("tag", attrs, [], node.tag)).trim();
|
|
109
|
+
const body = processor.stringify(normalizeMarkdown({
|
|
110
|
+
type: "root",
|
|
111
|
+
children
|
|
112
|
+
}));
|
|
113
|
+
return [{
|
|
114
|
+
type: "html",
|
|
115
|
+
value: children.length ? `${opening.replace(/\s*\/%\}$/, " %}")}\n\n${body}\n{% /${node.tag} %}` : opening
|
|
116
|
+
}];
|
|
117
|
+
}
|
|
118
|
+
default: throw new ConversionError(`Unsupported Markdoc AST node: ${node.type}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const nodes = convert(tree);
|
|
122
|
+
const root = nodes[0]?.type === "root" ? nodes[0] : {
|
|
123
|
+
type: "root",
|
|
124
|
+
children: nodes
|
|
125
|
+
};
|
|
126
|
+
return processor.stringify(normalizeMarkdown(root));
|
|
127
|
+
};
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/markdoc.ts
|
|
130
|
+
const markTypes = {
|
|
131
|
+
bold: "strong",
|
|
132
|
+
italic: "em",
|
|
133
|
+
strike: "s",
|
|
134
|
+
code: "code",
|
|
135
|
+
link: "link"
|
|
136
|
+
};
|
|
137
|
+
/** Markdoc adapter for createConverter(), including its parser and node/mark mappings. */
|
|
138
|
+
const markdocAdapter = {
|
|
139
|
+
name: "Markdoc",
|
|
140
|
+
frontmatter: true,
|
|
141
|
+
type: (node) => node.type,
|
|
142
|
+
elementName: (node) => node.type === "tag" ? node.tag : void 0,
|
|
143
|
+
markName: (node) => Object.entries(markTypes).find(([, type]) => type === node.type)?.[0],
|
|
144
|
+
root: (children) => new Markdoc.Ast.Node("document", {}, children),
|
|
145
|
+
parse: (source) => Markdoc.parse(source),
|
|
146
|
+
stringify: serializeMarkdoc,
|
|
147
|
+
async encode(node, context) {
|
|
148
|
+
const attrs = node.attrs || {};
|
|
149
|
+
const children = await context.children(node);
|
|
150
|
+
const inline = () => [new Markdoc.Ast.Node("inline", {}, children)];
|
|
151
|
+
switch (node.type) {
|
|
152
|
+
case "text": return new Markdoc.Ast.Node("text", { content: node.text || "" });
|
|
153
|
+
case "paragraph": return new Markdoc.Ast.Node("paragraph", {}, inline());
|
|
154
|
+
case "heading": return new Markdoc.Ast.Node("heading", {
|
|
155
|
+
level: Number(attrs.level || 1),
|
|
156
|
+
...context.anchor ? { id: context.anchor } : {}
|
|
157
|
+
}, inline());
|
|
158
|
+
case "blockquote": return new Markdoc.Ast.Node("blockquote", {}, children);
|
|
159
|
+
case "bulletList":
|
|
160
|
+
case "orderedList": return new Markdoc.Ast.Node("list", {
|
|
161
|
+
ordered: node.type === "orderedList",
|
|
162
|
+
start: attrs.start || 1,
|
|
163
|
+
marker: node.type === "orderedList" ? "." : "-"
|
|
164
|
+
}, children);
|
|
165
|
+
case "listItem": return new Markdoc.Ast.Node("item", {}, children);
|
|
166
|
+
case "codeBlock": return new Markdoc.Ast.Node("fence", {
|
|
167
|
+
language: attrs.language || "",
|
|
168
|
+
content: textContent(node)
|
|
169
|
+
});
|
|
170
|
+
case "hardBreak": return new Markdoc.Ast.Node("hardbreak");
|
|
171
|
+
case "horizontalRule": return new Markdoc.Ast.Node("hr");
|
|
172
|
+
case "image": return new Markdoc.Ast.Node("paragraph", {}, [new Markdoc.Ast.Node("inline", {}, [new Markdoc.Ast.Node("image", {
|
|
173
|
+
src: await context.imageURL(node),
|
|
174
|
+
alt: String(attrs.alt || ""),
|
|
175
|
+
title: String(attrs.caption || "")
|
|
176
|
+
})])]);
|
|
177
|
+
case "element": {
|
|
178
|
+
const props = attrs.props || {};
|
|
179
|
+
if (!isJSONValue(props)) throw new ConversionError("Markdoc attributes must contain static JSON values", context.path);
|
|
180
|
+
return new Markdoc.Ast.Node("tag", props, children, String(attrs.name || "Element"));
|
|
181
|
+
}
|
|
182
|
+
case "table": return new Markdoc.Ast.Node("table", {}, children.length ? [new Markdoc.Ast.Node("thead", {}, children.slice(0, 1)), new Markdoc.Ast.Node("tbody", {}, children.slice(1))] : []);
|
|
183
|
+
case "tableRow": return new Markdoc.Ast.Node("tr", {}, children);
|
|
184
|
+
case "tableCell":
|
|
185
|
+
case "tableHeader":
|
|
186
|
+
if (Number(attrs.colspan || 1) !== 1 || Number(attrs.rowspan || 1) !== 1 || children.length > 1 || children.some((child) => child.type !== "paragraph")) throw new ConversionError("Markdoc tables require single-paragraph cells without spans", context.path);
|
|
187
|
+
return new Markdoc.Ast.Node(node.type === "tableHeader" ? "th" : "td", {}, children.flatMap((child) => child.children));
|
|
188
|
+
default: throw new ConversionError(`Unsupported Markdoc node: ${node.type}`, context.path);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
mark(mark, children, context) {
|
|
192
|
+
const type = lookup(markTypes, mark.type);
|
|
193
|
+
if (!type) throw new ConversionError(`Unsupported Markdoc mark: ${mark.type}`, context.path);
|
|
194
|
+
if (mark.type === "code") {
|
|
195
|
+
if (children.some((node) => node.type !== "text")) throw new ConversionError("Code marks must wrap plain text", context.path);
|
|
196
|
+
return new Markdoc.Ast.Node("code", { content: children.map((node) => node.attributes.content).join("") });
|
|
197
|
+
}
|
|
198
|
+
return new Markdoc.Ast.Node(type, mark.type === "link" ? { href: mark.attrs?.href || "" } : {}, children);
|
|
199
|
+
},
|
|
200
|
+
async decode(node, context) {
|
|
201
|
+
const attrs = node.attributes;
|
|
202
|
+
if (node.errors.length) throw new ConversionError(`Invalid Markdoc: ${node.errors[0].message}`, context.path);
|
|
203
|
+
if (!isJSONValue(attrs)) throw new ConversionError("Dynamic Markdoc attributes require a custom handler", context.path);
|
|
204
|
+
const children = await context.children(node.children);
|
|
205
|
+
const mark = Object.entries(markTypes).find(([, type]) => type === node.type)?.[0];
|
|
206
|
+
if (mark === "code") return withMark(textNode(String(attrs.content || "")), { type: "code" });
|
|
207
|
+
if (mark) return withMark(children, {
|
|
208
|
+
type: mark,
|
|
209
|
+
...mark === "link" ? { attrs: { href: attrs.href } } : {}
|
|
210
|
+
});
|
|
211
|
+
switch (node.type) {
|
|
212
|
+
case "document":
|
|
213
|
+
case "inline":
|
|
214
|
+
case "thead":
|
|
215
|
+
case "tbody": return children;
|
|
216
|
+
case "text": return textNode(String(attrs.content || ""));
|
|
217
|
+
case "paragraph": return paragraphContent(children);
|
|
218
|
+
case "heading": return {
|
|
219
|
+
type: "heading",
|
|
220
|
+
attrs: { level: attrs.level || 1 },
|
|
221
|
+
content: children
|
|
222
|
+
};
|
|
223
|
+
case "blockquote": return {
|
|
224
|
+
type: "blockquote",
|
|
225
|
+
content: children
|
|
226
|
+
};
|
|
227
|
+
case "list": return {
|
|
228
|
+
type: attrs.ordered ? "orderedList" : "bulletList",
|
|
229
|
+
...attrs.ordered ? { attrs: { start: attrs.start || 1 } } : {},
|
|
230
|
+
content: children
|
|
231
|
+
};
|
|
232
|
+
case "item": return {
|
|
233
|
+
type: "listItem",
|
|
234
|
+
content: paragraphContent(children)
|
|
235
|
+
};
|
|
236
|
+
case "fence": return {
|
|
237
|
+
type: "codeBlock",
|
|
238
|
+
attrs: { language: attrs.language || null },
|
|
239
|
+
content: textNode(String(attrs.content || "").replace(/\n$/, ""))
|
|
240
|
+
};
|
|
241
|
+
case "hardbreak": return { type: "hardBreak" };
|
|
242
|
+
case "softbreak": return textNode("\n");
|
|
243
|
+
case "hr": return { type: "horizontalRule" };
|
|
244
|
+
case "image": return context.image({
|
|
245
|
+
url: String(attrs.src || ""),
|
|
246
|
+
alt: String(attrs.alt || ""),
|
|
247
|
+
title: attrs.title
|
|
248
|
+
});
|
|
249
|
+
case "tag": return element(node.tag || "Element", attrs, children.length ? paragraphContent(children) : []);
|
|
250
|
+
case "table": return {
|
|
251
|
+
type: "table",
|
|
252
|
+
content: children
|
|
253
|
+
};
|
|
254
|
+
case "tr": return {
|
|
255
|
+
type: "tableRow",
|
|
256
|
+
content: children
|
|
257
|
+
};
|
|
258
|
+
case "th":
|
|
259
|
+
case "td": return {
|
|
260
|
+
type: node.type === "th" ? "tableHeader" : "tableCell",
|
|
261
|
+
content: paragraphContent(children)
|
|
262
|
+
};
|
|
263
|
+
default: throw new ConversionError(`Unsupported Markdoc syntax: ${node.type}`, context.path);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* Create a reusable async Markdoc converter with application-specific defaults.
|
|
269
|
+
* @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.
|
|
270
|
+
* @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.
|
|
271
|
+
* Custom elements use Markdoc tags with static properties.
|
|
272
|
+
*/
|
|
273
|
+
const createMarkdocConverter = (options) => createConverter(markdocAdapter, options);
|
|
274
|
+
const converter = createMarkdocConverter();
|
|
275
|
+
/**
|
|
276
|
+
* Export ProseMirror JSON as Markdoc.
|
|
277
|
+
* @param document - Entry or fragment document. Fragment wrappers are removed by default.
|
|
278
|
+
* @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.
|
|
279
|
+
* @returns Serialized Markdoc. Omitted metadata and unwrapped fragment boundaries are not recoverable.
|
|
280
|
+
* @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.
|
|
281
|
+
*/
|
|
282
|
+
const toMarkdoc = converter.encode;
|
|
283
|
+
/**
|
|
284
|
+
* Import Markdoc as ProseMirror JSON without saving content or uploading assets.
|
|
285
|
+
* @param source - Source text to parse. Custom elements use Markdoc tags with static properties.
|
|
286
|
+
* @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.
|
|
287
|
+
* @returns An entry document; use document: "fragment" to omit the title and retain the first H1 as body content.
|
|
288
|
+
* @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.
|
|
289
|
+
*/
|
|
290
|
+
const fromMarkdoc = converter.decode;
|
|
291
|
+
/**
|
|
292
|
+
* Export ProseMirror JSON as a Markdoc AST with separate frontmatter.
|
|
293
|
+
* @param document - Source entry or fragment document.
|
|
294
|
+
* @param options - Export mappings and async handlers, including imageURL for images.
|
|
295
|
+
* @returns The format tree and metadata without string serialization.
|
|
296
|
+
* @throws The same conversion errors as toMarkdoc(), including unsupported frontmatter mappings.
|
|
297
|
+
*/
|
|
298
|
+
const toMarkdocAST = converter.toAST;
|
|
299
|
+
/**
|
|
300
|
+
* Import a parsed Markdoc AST and its frontmatter as ProseMirror JSON.
|
|
301
|
+
* @param input - Tree and frontmatter object; use an empty object when metadata is absent.
|
|
302
|
+
* @param options - Import mappings and async handlers, including imageAssetID for images.
|
|
303
|
+
* @returns An entry document by default, or a fragment document when requested.
|
|
304
|
+
* @throws The same conversion errors as fromMarkdoc(), excluding string-parser errors.
|
|
305
|
+
*/
|
|
306
|
+
const fromMarkdocAST = converter.fromAST;
|
|
307
|
+
//#endregion
|
|
308
|
+
export { createMarkdocConverter, fromMarkdoc, fromMarkdocAST, markdocAdapter, toMarkdoc, toMarkdocAST };
|
|
309
|
+
|
|
310
|
+
//# sourceMappingURL=markdoc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdoc.js","names":[],"sources":["../src/markdoc/serialize.ts","../src/markdoc.ts"],"sourcesContent":["import Markdoc from \"@markdoc/markdoc\";\nimport { unified } from \"unified\";\nimport remarkStringify from \"remark-stringify\";\nimport remarkGFM from \"remark-gfm\";\nimport type {\n Root,\n RootContent,\n PhrasingContent,\n BlockContent,\n ListContent,\n TableContent,\n RowContent\n} from \"mdast\";\nimport { ConversionError } from \"../utils\";\nimport { normalizeMarkdown } from \"../markdown/normalize\";\nimport { markdownStringifyOptions } from \"../markdown/stringify\";\n\ntype MarkdocNode = InstanceType<typeof Markdoc.Ast.Node>;\ntype MarkdownNode = Root | RootContent;\n\n// Markdoc's formatter preserves source-like text. Use a Markdown serializer to\n// escape literal Markdown characters in newly created content.\nconst processor = unified()\n .use(remarkGFM)\n .use(remarkStringify, {\n ...markdownStringifyOptions,\n unsafe: [{ character: \"{\", after: \"%\" }]\n });\nconst serializeMarkdoc = (tree: MarkdocNode): string => {\n const convert = (node: MarkdocNode): MarkdownNode[] => {\n const attrs = node.attributes;\n const children = node.children.flatMap(convert);\n const inline = children as PhrasingContent[];\n\n switch (node.type) {\n case \"document\":\n return [{ type: \"root\", children: children as RootContent[] }];\n case \"inline\":\n case \"thead\":\n case \"tbody\":\n return children;\n case \"text\":\n return [{ type: \"text\", value: String(attrs.content || \"\") }];\n case \"paragraph\":\n return [{ type: \"paragraph\", children: inline }];\n case \"heading\":\n return [\n {\n type: \"heading\",\n depth: Number(attrs.level || 1) as 1 | 2 | 3 | 4 | 5 | 6,\n children: inline\n }\n ];\n case \"strong\":\n return [{ type: \"strong\", children: inline }];\n case \"em\":\n return [{ type: \"emphasis\", children: inline }];\n case \"s\":\n return [{ type: \"delete\", children: inline }];\n case \"code\":\n return [{ type: \"inlineCode\", value: String(attrs.content || \"\") }];\n case \"link\":\n return [{ type: \"link\", url: String(attrs.href || \"\"), children: inline }];\n case \"image\":\n return [\n {\n type: \"image\",\n url: String(attrs.src || \"\"),\n alt: String(attrs.alt || \"\"),\n title: attrs.title || null\n }\n ];\n case \"blockquote\":\n return [{ type: \"blockquote\", children: children as BlockContent[] }];\n case \"list\":\n return [\n {\n type: \"list\",\n ordered: Boolean(attrs.ordered),\n start: Number(attrs.start || 1),\n children: children as ListContent[]\n }\n ];\n case \"item\":\n return [{ type: \"listItem\", children: children as BlockContent[] }];\n case \"fence\":\n return [\n { type: \"code\", lang: String(attrs.language || \"\"), value: String(attrs.content || \"\") }\n ];\n case \"hardbreak\":\n return [{ type: \"break\" }];\n case \"softbreak\":\n return [{ type: \"text\", value: \"\\n\" }];\n case \"hr\":\n return [{ type: \"thematicBreak\" }];\n case \"table\":\n return [{ type: \"table\", children: children as TableContent[] }];\n case \"tr\":\n return [{ type: \"tableRow\", children: children as RowContent[] }];\n case \"td\":\n case \"th\":\n return [{ type: \"tableCell\", children: inline }];\n case \"tag\": {\n const opening = Markdoc.format(new Markdoc.Ast.Node(\"tag\", attrs, [], node.tag)).trim();\n const body = processor.stringify(\n normalizeMarkdown({ type: \"root\", children: children as RootContent[] })\n );\n const value = children.length\n ? `${opening.replace(/\\s*\\/%\\}$/, \" %}\")}\\n\\n${body}\\n{% /${node.tag} %}`\n : opening;\n\n return [{ type: \"html\", value }];\n }\n default:\n throw new ConversionError(`Unsupported Markdoc AST node: ${node.type}`);\n }\n };\n const nodes = convert(tree);\n const root: Root =\n nodes[0]?.type === \"root\" ? nodes[0] : { type: \"root\", children: nodes as RootContent[] };\n\n return processor.stringify(normalizeMarkdown(root));\n};\n\nexport { serializeMarkdoc };\n","import Markdoc from \"@markdoc/markdoc\";\nimport { serializeMarkdoc } from \"./markdoc/serialize\";\nimport { createConverter } from \"./core\";\nimport {\n ConversionError,\n lookup,\n element,\n isJSONValue,\n textContent,\n textNode,\n withMark\n} from \"./utils\";\nimport { paragraphContent } from \"./markdown/decode\";\nimport type { ConverterOptions, FormatAdapter } from \"./types\";\n\ntype MarkdocNode = InstanceType<typeof Markdoc.Ast.Node>;\ntype MarkdocOptions = ConverterOptions<MarkdocNode>;\n\nconst markTypes: Record<string, string> = {\n bold: \"strong\",\n italic: \"em\",\n strike: \"s\",\n code: \"code\",\n link: \"link\"\n};\n/** Markdoc adapter for createConverter(), including its parser and node/mark mappings. */\nconst markdocAdapter: FormatAdapter<MarkdocNode> = {\n name: \"Markdoc\",\n frontmatter: true,\n type: (node) => node.type,\n elementName: (node) => (node.type === \"tag\" ? node.tag : undefined),\n markName: (node) => Object.entries(markTypes).find(([, type]) => type === node.type)?.[0],\n root: (children) => new Markdoc.Ast.Node(\"document\", {}, children),\n parse: (source) => Markdoc.parse(source),\n stringify: serializeMarkdoc,\n async encode(node, context) {\n const attrs = node.attrs || {};\n const children = await context.children(node);\n const inline = () => [new Markdoc.Ast.Node(\"inline\", {}, children)];\n\n switch (node.type) {\n case \"text\":\n return new Markdoc.Ast.Node(\"text\", { content: node.text || \"\" });\n case \"paragraph\":\n return new Markdoc.Ast.Node(\"paragraph\", {}, inline());\n case \"heading\":\n return new Markdoc.Ast.Node(\n \"heading\",\n { level: Number(attrs.level || 1), ...(context.anchor ? { id: context.anchor } : {}) },\n inline()\n );\n case \"blockquote\":\n return new Markdoc.Ast.Node(\"blockquote\", {}, children);\n case \"bulletList\":\n case \"orderedList\":\n return new Markdoc.Ast.Node(\n \"list\",\n {\n ordered: node.type === \"orderedList\",\n start: attrs.start || 1,\n marker: node.type === \"orderedList\" ? \".\" : \"-\"\n },\n children\n );\n case \"listItem\":\n return new Markdoc.Ast.Node(\"item\", {}, children);\n case \"codeBlock\":\n return new Markdoc.Ast.Node(\"fence\", {\n language: attrs.language || \"\",\n content: textContent(node)\n });\n case \"hardBreak\":\n return new Markdoc.Ast.Node(\"hardbreak\");\n case \"horizontalRule\":\n return new Markdoc.Ast.Node(\"hr\");\n case \"image\":\n return new Markdoc.Ast.Node(\"paragraph\", {}, [\n new Markdoc.Ast.Node(\"inline\", {}, [\n new Markdoc.Ast.Node(\"image\", {\n src: await context.imageURL(node),\n alt: String(attrs.alt || \"\"),\n title: String(attrs.caption || \"\")\n })\n ])\n ]);\n case \"element\": {\n const props = (attrs.props || {}) as Record<string, unknown>;\n\n if (!isJSONValue(props))\n throw new ConversionError(\n \"Markdoc attributes must contain static JSON values\",\n context.path\n );\n\n return new Markdoc.Ast.Node(\"tag\", props, children, String(attrs.name || \"Element\"));\n }\n case \"table\":\n return new Markdoc.Ast.Node(\n \"table\",\n {},\n children.length\n ? [\n new Markdoc.Ast.Node(\"thead\", {}, children.slice(0, 1)),\n new Markdoc.Ast.Node(\"tbody\", {}, children.slice(1))\n ]\n : []\n );\n case \"tableRow\":\n return new Markdoc.Ast.Node(\"tr\", {}, children);\n case \"tableCell\":\n case \"tableHeader\": {\n if (\n Number(attrs.colspan || 1) !== 1 ||\n Number(attrs.rowspan || 1) !== 1 ||\n children.length > 1 ||\n children.some((child) => child.type !== \"paragraph\")\n ) {\n throw new ConversionError(\n \"Markdoc tables require single-paragraph cells without spans\",\n context.path\n );\n }\n return new Markdoc.Ast.Node(\n node.type === \"tableHeader\" ? \"th\" : \"td\",\n {},\n children.flatMap((child) => child.children)\n );\n }\n default:\n throw new ConversionError(`Unsupported Markdoc node: ${node.type}`, context.path);\n }\n },\n mark(mark, children, context) {\n const type = lookup(markTypes, mark.type);\n\n if (!type) throw new ConversionError(`Unsupported Markdoc mark: ${mark.type}`, context.path);\n if (mark.type === \"code\") {\n if (children.some((node) => node.type !== \"text\"))\n throw new ConversionError(\"Code marks must wrap plain text\", context.path);\n\n return new Markdoc.Ast.Node(\"code\", {\n content: children.map((node) => node.attributes.content).join(\"\")\n });\n }\n return new Markdoc.Ast.Node(\n type as MarkdocNode[\"type\"],\n mark.type === \"link\" ? { href: mark.attrs?.href || \"\" } : {},\n children\n );\n },\n async decode(node, context) {\n const attrs = node.attributes;\n\n if (node.errors.length)\n throw new ConversionError(`Invalid Markdoc: ${node.errors[0].message}`, context.path);\n if (!isJSONValue(attrs))\n throw new ConversionError(\n \"Dynamic Markdoc attributes require a custom handler\",\n context.path\n );\n\n const children = await context.children(node.children);\n const mark = Object.entries(markTypes).find(([, type]) => type === node.type)?.[0];\n\n if (mark === \"code\") return withMark(textNode(String(attrs.content || \"\")), { type: \"code\" });\n if (mark)\n return withMark(children, {\n type: mark,\n ...(mark === \"link\" ? { attrs: { href: attrs.href } } : {})\n });\n\n switch (node.type) {\n case \"document\":\n case \"inline\":\n case \"thead\":\n case \"tbody\":\n return children;\n case \"text\":\n return textNode(String(attrs.content || \"\"));\n case \"paragraph\":\n return paragraphContent(children);\n case \"heading\":\n return { type: \"heading\", attrs: { level: attrs.level || 1 }, content: children };\n case \"blockquote\":\n return { type: \"blockquote\", content: children };\n case \"list\":\n return {\n type: attrs.ordered ? \"orderedList\" : \"bulletList\",\n ...(attrs.ordered ? { attrs: { start: attrs.start || 1 } } : {}),\n content: children\n };\n case \"item\":\n return { type: \"listItem\", content: paragraphContent(children) };\n case \"fence\":\n return {\n type: \"codeBlock\",\n attrs: { language: attrs.language || null },\n content: textNode(String(attrs.content || \"\").replace(/\\n$/, \"\"))\n };\n case \"hardbreak\":\n return { type: \"hardBreak\" };\n case \"softbreak\":\n return textNode(\"\\n\");\n case \"hr\":\n return { type: \"horizontalRule\" };\n case \"image\":\n return context.image({\n url: String(attrs.src || \"\"),\n alt: String(attrs.alt || \"\"),\n title: attrs.title\n });\n case \"tag\":\n return element(\n node.tag || \"Element\",\n attrs,\n children.length ? paragraphContent(children) : []\n );\n case \"table\":\n return { type: \"table\", content: children };\n case \"tr\":\n return { type: \"tableRow\", content: children };\n case \"th\":\n case \"td\":\n return {\n type: node.type === \"th\" ? \"tableHeader\" : \"tableCell\",\n content: paragraphContent(children)\n };\n default:\n throw new ConversionError(`Unsupported Markdoc syntax: ${node.type}`, context.path);\n }\n }\n};\n/**\n * Create a reusable async Markdoc converter with application-specific defaults.\n * @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.\n * @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.\n * Custom elements use Markdoc tags with static properties.\n */\nconst createMarkdocConverter = (options?: MarkdocOptions) =>\n createConverter(markdocAdapter, options);\nconst converter = createMarkdocConverter();\n/**\n * Export ProseMirror JSON as Markdoc.\n * @param document - Entry or fragment document. Fragment wrappers are removed by default.\n * @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.\n * @returns Serialized Markdoc. Omitted metadata and unwrapped fragment boundaries are not recoverable.\n * @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.\n */\nconst toMarkdoc = converter.encode;\n/**\n * Import Markdoc as ProseMirror JSON without saving content or uploading assets.\n * @param source - Source text to parse. Custom elements use Markdoc tags with static properties.\n * @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.\n * @returns An entry document; use document: \"fragment\" to omit the title and retain the first H1 as body content.\n * @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.\n */\nconst fromMarkdoc = converter.decode;\n/**\n * Export ProseMirror JSON as a Markdoc AST with separate frontmatter.\n * @param document - Source entry or fragment document.\n * @param options - Export mappings and async handlers, including imageURL for images.\n * @returns The format tree and metadata without string serialization.\n * @throws The same conversion errors as toMarkdoc(), including unsupported frontmatter mappings.\n */\nconst toMarkdocAST = converter.toAST;\n/**\n * Import a parsed Markdoc AST and its frontmatter as ProseMirror JSON.\n * @param input - Tree and frontmatter object; use an empty object when metadata is absent.\n * @param options - Import mappings and async handlers, including imageAssetID for images.\n * @returns An entry document by default, or a fragment document when requested.\n * @throws The same conversion errors as fromMarkdoc(), excluding string-parser errors.\n */\nconst fromMarkdocAST = converter.fromAST;\n\nexport {\n createMarkdocConverter,\n markdocAdapter,\n toMarkdoc,\n fromMarkd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GAClC,KAAK,SACH,OAAO,QAAQ,MAAM;IACnB,KAAK,OAAO,MAAM,OAAO,EAAE;IAC3B,KAAK,OAAO,MAAM,OAAO,EAAE;IAC3B,OAAO,MAAM;GACf,CAAC;GACH,KAAK,OACH,OAAO,QACL,KAAK,OAAO,WACZ,OACA,SAAS,SAAS,iBAAiB,QAAQ,IAAI,CAAC,CAClD;GACF,KAAK,SACH,OAAO;IAAE,MAAM;IAAS,SAAS;GAAS;GAC5C,KAAK,MACH,OAAO;IAAE,MAAM;IAAY,SAAS;GAAS;GAC/C,KAAK;GACL,KAAK,MACH,OAAO;IACL,MAAM,KAAK,SAAS,OAAO,gBAAgB;IAC3C,SAAS,iBAAiB,QAAQ;GACpC;GACF,SACE,MAAM,IAAI,gBAAgB,+BAA+B,KAAK,QAAQ,QAAQ,IAAI;EACtF;CACF;AACF;;;;;;;AAOA,MAAM,0BAA0B,YAC9B,gBAAgB,gBAAgB,OAAO;AACzC,MAAM,YAAY,uBAAuB;;;;;;;;AAQzC,MAAM,YAAY,UAAU;;;;;;;;AAQ5B,MAAM,cAAc,UAAU;;;;;;;;AAQ9B,MAAM,eAAe,UAAU;;;;;;;;AAQ/B,MAAM,iBAAiB,UAAU"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { a as Converter, f as ExportConverterOptions, i as ConvertedAST, m as FormatAdapter, o as ConverterOptions, r as ContentNode, y as ImportConverterOptions } from "./chunks/types-SDFWRP3z.js";
|
|
2
|
+
import { t as MarkdownNode } from "./chunks/decode-BLP2Olia.js";
|
|
3
|
+
//#region src/markdown.d.ts
|
|
4
|
+
type MarkdownOptions = ConverterOptions<MarkdownNode>;
|
|
5
|
+
/** Markdown/GFM adapter for createConverter(), including its parser and node/mark mappings. */
|
|
6
|
+
declare const markdownAdapter: FormatAdapter<MarkdownNode>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a reusable async Markdown/GFM converter with application-specific defaults.
|
|
9
|
+
* @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.
|
|
10
|
+
* @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.
|
|
11
|
+
* Markdown cannot preserve custom elements without handlers.
|
|
12
|
+
*/
|
|
13
|
+
declare const createMarkdownConverter: (options?: MarkdownOptions) => Converter<MarkdownNode>;
|
|
14
|
+
/**
|
|
15
|
+
* Export ProseMirror JSON as Markdown/GFM.
|
|
16
|
+
* @param document - Entry or fragment document. Fragment wrappers are removed by default.
|
|
17
|
+
* @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.
|
|
18
|
+
* @returns Serialized Markdown/GFM. Omitted metadata and unwrapped fragment boundaries are not recoverable.
|
|
19
|
+
* @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.
|
|
20
|
+
*/
|
|
21
|
+
declare const toMarkdown: (document: ContentNode, options?: ExportConverterOptions<MarkdownNode> | undefined) => Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Import Markdown/GFM as ProseMirror JSON without saving content or uploading assets.
|
|
24
|
+
* @param source - Source text to parse. Markdown cannot preserve custom elements without handlers.
|
|
25
|
+
* @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.
|
|
26
|
+
* @returns An entry document; use document: "fragment" to omit the title and retain the first H1 as body content.
|
|
27
|
+
* @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.
|
|
28
|
+
*/
|
|
29
|
+
declare const fromMarkdown: (source: string, options?: ImportConverterOptions<MarkdownNode> | undefined) => Promise<ContentNode>;
|
|
30
|
+
/**
|
|
31
|
+
* Export ProseMirror JSON as a Markdown/GFM AST with separate frontmatter.
|
|
32
|
+
* @param document - Source entry or fragment document.
|
|
33
|
+
* @param options - Export mappings and async handlers, including imageURL for images.
|
|
34
|
+
* @returns The format tree and metadata without string serialization.
|
|
35
|
+
* @throws The same conversion errors as toMarkdown(), including unsupported frontmatter mappings.
|
|
36
|
+
*/
|
|
37
|
+
declare const toMarkdownAST: (document: ContentNode, options?: ExportConverterOptions<MarkdownNode> | undefined) => Promise<ConvertedAST<MarkdownNode>>;
|
|
38
|
+
/**
|
|
39
|
+
* Import a parsed Markdown/GFM AST and its frontmatter as ProseMirror JSON.
|
|
40
|
+
* @param input - Tree and frontmatter object; use an empty object when metadata is absent.
|
|
41
|
+
* @param options - Import mappings and async handlers, including imageAssetID for images.
|
|
42
|
+
* @returns An entry document by default, or a fragment document when requested.
|
|
43
|
+
* @throws The same conversion errors as fromMarkdown(), excluding string-parser errors.
|
|
44
|
+
*/
|
|
45
|
+
declare const fromMarkdownAST: (input: ConvertedAST<MarkdownNode>, options?: ImportConverterOptions<MarkdownNode> | undefined) => Promise<ContentNode>;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { type MarkdownNode, type MarkdownOptions, createMarkdownConverter, fromMarkdown, fromMarkdownAST, markdownAdapter, toMarkdown, toMarkdownAST };
|
|
48
|
+
//# sourceMappingURL=markdown.d.ts.map
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { t as createConverter } from "./chunks/core-DC64ddB7.js";
|
|
2
|
+
import { t as createMarkdownAdapter } from "./chunks/adapter-CeNgvE5W.js";
|
|
3
|
+
//#region src/markdown.ts
|
|
4
|
+
/** Markdown/GFM adapter for createConverter(), including its parser and node/mark mappings. */
|
|
5
|
+
const markdownAdapter = createMarkdownAdapter();
|
|
6
|
+
/**
|
|
7
|
+
* Create a reusable async Markdown/GFM converter with application-specific defaults.
|
|
8
|
+
* @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.
|
|
9
|
+
* @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.
|
|
10
|
+
* Markdown cannot preserve custom elements without handlers.
|
|
11
|
+
*/
|
|
12
|
+
const createMarkdownConverter = (options) => createConverter(markdownAdapter, options);
|
|
13
|
+
const converter = createMarkdownConverter();
|
|
14
|
+
/**
|
|
15
|
+
* Export ProseMirror JSON as Markdown/GFM.
|
|
16
|
+
* @param document - Entry or fragment document. Fragment wrappers are removed by default.
|
|
17
|
+
* @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.
|
|
18
|
+
* @returns Serialized Markdown/GFM. Omitted metadata and unwrapped fragment boundaries are not recoverable.
|
|
19
|
+
* @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.
|
|
20
|
+
*/
|
|
21
|
+
const toMarkdown = converter.encode;
|
|
22
|
+
/**
|
|
23
|
+
* Import Markdown/GFM as ProseMirror JSON without saving content or uploading assets.
|
|
24
|
+
* @param source - Source text to parse. Markdown cannot preserve custom elements without handlers.
|
|
25
|
+
* @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.
|
|
26
|
+
* @returns An entry document; use document: "fragment" to omit the title and retain the first H1 as body content.
|
|
27
|
+
* @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.
|
|
28
|
+
*/
|
|
29
|
+
const fromMarkdown = converter.decode;
|
|
30
|
+
/**
|
|
31
|
+
* Export ProseMirror JSON as a Markdown/GFM AST with separate frontmatter.
|
|
32
|
+
* @param document - Source entry or fragment document.
|
|
33
|
+
* @param options - Export mappings and async handlers, including imageURL for images.
|
|
34
|
+
* @returns The format tree and metadata without string serialization.
|
|
35
|
+
* @throws The same conversion errors as toMarkdown(), including unsupported frontmatter mappings.
|
|
36
|
+
*/
|
|
37
|
+
const toMarkdownAST = converter.toAST;
|
|
38
|
+
/**
|
|
39
|
+
* Import a parsed Markdown/GFM AST and its frontmatter as ProseMirror JSON.
|
|
40
|
+
* @param input - Tree and frontmatter object; use an empty object when metadata is absent.
|
|
41
|
+
* @param options - Import mappings and async handlers, including imageAssetID for images.
|
|
42
|
+
* @returns An entry document by default, or a fragment document when requested.
|
|
43
|
+
* @throws The same conversion errors as fromMarkdown(), excluding string-parser errors.
|
|
44
|
+
*/
|
|
45
|
+
const fromMarkdownAST = converter.fromAST;
|
|
46
|
+
//#endregion
|
|
47
|
+
export { createMarkdownConverter, fromMarkdown, fromMarkdownAST, markdownAdapter, toMarkdown, toMarkdownAST };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","names":[],"sources":["../src/markdown.ts"],"sourcesContent":["import { createConverter } from \"./core\";\nimport { createMarkdownAdapter } from \"./markdown/adapter\";\nimport type { ConverterOptions } from \"./types\";\nimport type { MarkdownNode } from \"./markdown/decode\";\n\ntype MarkdownOptions = ConverterOptions<MarkdownNode>;\n\n/** Markdown/GFM adapter for createConverter(), including its parser and node/mark mappings. */\nconst markdownAdapter = createMarkdownAdapter();\n/**\n * Create a reusable async Markdown/GFM converter with application-specific defaults.\n * @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.\n * @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.\n * Markdown cannot preserve custom elements without handlers.\n */\nconst createMarkdownConverter = (options?: MarkdownOptions) =>\n createConverter(markdownAdapter, options);\nconst converter = createMarkdownConverter();\n/**\n * Export ProseMirror JSON as Markdown/GFM.\n * @param document - Entry or fragment document. Fragment wrappers are removed by default.\n * @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.\n * @returns Serialized Markdown/GFM. Omitted metadata and unwrapped fragment boundaries are not recoverable.\n * @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.\n */\nconst toMarkdown = converter.encode;\n/**\n * Import Markdown/GFM as ProseMirror JSON without saving content or uploading assets.\n * @param source - Source text to parse. Markdown cannot preserve custom elements without handlers.\n * @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.\n * @returns An entry document; use document: \"fragment\" to omit the title and retain the first H1 as body content.\n * @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.\n */\nconst fromMarkdown = converter.decode;\n/**\n * Export ProseMirror JSON as a Markdown/GFM AST with separate frontmatter.\n * @param document - Source entry or fragment document.\n * @param options - Export mappings and async handlers, including imageURL for images.\n * @returns The format tree and metadata without string serialization.\n * @throws The same conversion errors as toMarkdown(), including unsupported frontmatter mappings.\n */\nconst toMarkdownAST = converter.toAST;\n/**\n * Import a parsed Markdown/GFM AST and its frontmatter as ProseMirror JSON.\n * @param input - Tree and frontmatter object; use an empty object when metadata is absent.\n * @param options - Import mappings and async handlers, including imageAssetID for images.\n * @returns An entry document by default, or a fragment document when requested.\n * @throws The same conversion errors as fromMarkdown(), excluding string-parser errors.\n */\nconst fromMarkdownAST = converter.fromAST;\n\nexport {\n createMarkdownConverter,\n markdownAdapter,\n toMarkdown,\n fromMarkdown,\n toMarkdownAST,\n fromMarkdownAST\n};\nexport type { MarkdownOptions, MarkdownNode };\n"],"mappings":";;;;AAQA,MAAM,kBAAkB,sBAAsB;;;;;;;AAO9C,MAAM,2BAA2B,YAC/B,gBAAgB,iBAAiB,OAAO;AAC1C,MAAM,YAAY,wBAAwB;;;;;;;;AAQ1C,MAAM,aAAa,UAAU;;;;;;;;AAQ7B,MAAM,eAAe,UAAU;;;;;;;;AAQ/B,MAAM,gBAAgB,UAAU;;;;;;;;AAQhC,MAAM,kBAAkB,UAAU"}
|
package/dist/mdx.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { a as Converter, f as ExportConverterOptions, i as ConvertedAST, m as FormatAdapter, o as ConverterOptions, r as ContentNode, y as ImportConverterOptions } from "./chunks/types-SDFWRP3z.js";
|
|
2
|
+
import { t as MarkdownNode } from "./chunks/decode-BLP2Olia.js";
|
|
3
|
+
import { MdxJsxFlowElement } from "mdast-util-mdx-jsx";
|
|
4
|
+
//#region src/mdx.d.ts
|
|
5
|
+
type MDXNode = MarkdownNode | MdxJsxFlowElement;
|
|
6
|
+
type MDXOptions = ConverterOptions<MDXNode>;
|
|
7
|
+
/** MDX adapter for createConverter(), including its parser and node/mark mappings. */
|
|
8
|
+
declare const mdxAdapter: FormatAdapter<MDXNode>;
|
|
9
|
+
/**
|
|
10
|
+
* Create a reusable async MDX converter with application-specific defaults.
|
|
11
|
+
* @param options - Default mappings and handlers; per-call maps merge by key and callbacks may be async.
|
|
12
|
+
* @returns String and AST import/export methods. Defaults use an H1 title, unwrap fragments, and omit properties.
|
|
13
|
+
* Custom elements use static JSON properties; executable expressions require custom handlers.
|
|
14
|
+
*/
|
|
15
|
+
declare const createMDXConverter: (options?: MDXOptions) => Converter<MDXNode>;
|
|
16
|
+
/**
|
|
17
|
+
* Export ProseMirror JSON as MDX.
|
|
18
|
+
* @param document - Entry or fragment document. Fragment wrappers are removed by default.
|
|
19
|
+
* @param options - Title/property/fragment mappings and async handlers; imageURL resolves images.
|
|
20
|
+
* @returns Serialized MDX. Omitted metadata and unwrapped fragment boundaries are not recoverable.
|
|
21
|
+
* @throws ConversionError for unsupported content, unresolved images, or invalid mappings; handler errors pass through.
|
|
22
|
+
*/
|
|
23
|
+
declare const toMDX: (document: ContentNode, options?: ExportConverterOptions<MDXNode> | undefined) => Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Import MDX as ProseMirror JSON without saving content or uploading assets.
|
|
26
|
+
* @param source - Source text to parse. Custom elements use static JSON properties; executable expressions require custom handlers.
|
|
27
|
+
* @param options - Import mappings and async handlers. imageAssetID must resolve image URLs.
|
|
28
|
+
* @returns An entry document; use document: "fragment" to omit the title and retain the first H1 as body content.
|
|
29
|
+
* @throws ConversionError for unsupported content/mappings; parser and handler errors pass through.
|
|
30
|
+
*/
|
|
31
|
+
declare const fromMDX: (source: string, options?: ImportConverterOptions<MDXNode> | undefined) => Promise<ContentNode>;
|
|
32
|
+
/**
|
|
33
|
+
* Export ProseMirror JSON as a MDX AST with separate frontmatter.
|
|
34
|
+
* @param document - Source entry or fragment document.
|
|
35
|
+
* @param options - Export mappings and async handlers, including imageURL for images.
|
|
36
|
+
* @returns The format tree and metadata without string serialization.
|
|
37
|
+
* @throws The same conversion errors as toMDX(), including unsupported frontmatter mappings.
|
|
38
|
+
*/
|
|
39
|
+
declare const toMDXAST: (document: ContentNode, options?: ExportConverterOptions<MDXNode> | undefined) => Promise<ConvertedAST<MDXNode>>;
|
|
40
|
+
/**
|
|
41
|
+
* Import a parsed MDX AST and its frontmatter as ProseMirror JSON.
|
|
42
|
+
* @param input - Tree and frontmatter object; use an empty object when metadata is absent.
|
|
43
|
+
* @param options - Import mappings and async handlers, including imageAssetID for images.
|
|
44
|
+
* @returns An entry document by default, or a fragment document when requested.
|
|
45
|
+
* @throws The same conversion errors as fromMDX(), excluding string-parser errors.
|
|
46
|
+
*/
|
|
47
|
+
declare const fromMDXAST: (input: ConvertedAST<MDXNode>, options?: ImportConverterOptions<MDXNode> | undefined) => Promise<ContentNode>;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { type MDXNode, type MDXOptions, createMDXConverter, fromMDX, fromMDXAST, mdxAdapter, toMDX, toMDXAST };
|
|
50
|
+
//# sourceMappingURL=mdx.d.ts.map
|