cudoc-markdown-it 0.3.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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/compiler.d.ts +12 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +45 -0
- package/dist/compiler.js.map +1 -0
- package/dist/host.d.ts +60 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +8 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +28 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +38 -0
- package/dist/options.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +153 -0
- package/dist/plugin.js.map +1 -0
- package/dist/tokens.d.ts +20 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +215 -0
- package/dist/tokens.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cudoment
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# cudoc-markdown-it
|
|
2
|
+
|
|
3
|
+
Connect cudoc Markdown syntax, document collection and embedding to a markdown-it pipeline.
|
|
4
|
+
|
|
5
|
+
This separate package is a pipeline adapter, not a second implementation of cudoc's rules. Shared document semantics live in `@cudoment/cudoc`. It is the markdown-it counterpart of `cudoc-remark`: the VitePress and Eleventy adapters depend on it, so the two hosts share one token conversion, one embed expansion and one collection path. Use it directly only when writing an adapter for another markdown-it host.
|
|
6
|
+
|
|
7
|
+
ESM · Node.js 20+
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @cudoment/cudoc cudoc-markdown-it
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { installHostPlugin, createHostCompiler } from "cudoc-markdown-it"
|
|
15
|
+
|
|
16
|
+
const host = {
|
|
17
|
+
adapter: "cudoc-my-host",
|
|
18
|
+
host: "markdown",
|
|
19
|
+
documentId: (env) => String(env.documentId),
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function cudocMyHost(md, options = {}) {
|
|
23
|
+
installHostPlugin(md, options, host)
|
|
24
|
+
}
|
|
25
|
+
export const createDocumentCompiler = (md) => createHostCompiler(md, host)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The plugin converts the actual token stream and never parses the Markdown a second time. It reads the host's own anchor, link and container tokens, then copies the resolved heading ids and titles back onto the host tokens so native heading and TOC behavior is preserved. `MarkdownItHost` names everything a host does differently: its own tokens, the document id in its markdown-it env, whether it resolves links in renderer rules, and whether it strips front matter outside markdown-it.
|
|
29
|
+
|
|
30
|
+
Choose `host`, `cudoc` or `both` independently for `headingAnchor`, `badge`, `tableCellList`, `callout` and `link`. The representative callout is `> [!NOTE] Title`. Authors do not register cudoc React components in the recommended setup. Syntax-only rendering needs no stored JSON; cross-document embedding requires document collection.
|
|
31
|
+
|
|
32
|
+
- [VitePress guide](https://github.com/cudoment/cudoc/tree/main/docs/vitepress.md) · [Eleventy guide](https://github.com/cudoment/cudoc/tree/main/docs/eleventy.md)
|
|
33
|
+
- [Markdown syntax](https://github.com/cudoment/cudoc/tree/main/docs/syntax.md)
|
|
34
|
+
- [Embedding](https://github.com/cudoment/cudoc/tree/main/docs/embedding.md)
|
|
35
|
+
- [Standalone HTML alongside a host](https://github.com/cudoment/cudoc/tree/main/docs/html.md#export-alongside-an-existing-site)
|
|
36
|
+
- [API reference](https://github.com/cudoment/cudoc/tree/main/docs/api-reference/adapters.md#markdown-it)
|
|
37
|
+
- [Runnable examples](https://github.com/cudoment/cudoc/tree/main/examples/README.md)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection through the host's own configured markdown-it renderer.
|
|
3
|
+
*
|
|
4
|
+
* The same instance the site renders with is reused here, so a collected tree
|
|
5
|
+
* and a source replacement go through the actual host compiler rather than a
|
|
6
|
+
* second parser that could disagree with it.
|
|
7
|
+
*/
|
|
8
|
+
import type MarkdownIt from "markdown-it";
|
|
9
|
+
import type { DocumentCompiler } from "@cudoment/cudoc/node/library";
|
|
10
|
+
import type { MarkdownItHost } from "./host.js";
|
|
11
|
+
export declare function createHostCompiler(md: MarkdownIt, host: MarkdownItHost): DocumentCompiler;
|
|
12
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AAGzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAQ/C,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,UAAU,EACd,IAAI,EAAE,cAAc,GACnB,gBAAgB,CA0ClB"}
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection through the host's own configured markdown-it renderer.
|
|
3
|
+
*
|
|
4
|
+
* The same instance the site renders with is reused here, so a collected tree
|
|
5
|
+
* and a source replacement go through the actual host compiler rather than a
|
|
6
|
+
* second parser that could disagree with it.
|
|
7
|
+
*/
|
|
8
|
+
export function createHostCompiler(md, host) {
|
|
9
|
+
return (source, context) => {
|
|
10
|
+
if (context.options.format === "mdx")
|
|
11
|
+
throw new Error(`${host.adapter}: markdown-it hosts compile Markdown .md documents, not React .mdx`);
|
|
12
|
+
// A host that strips frontmatter outside markdown-it never shows it to the
|
|
13
|
+
// token stream, so the collector strips it the same way and keeps the data.
|
|
14
|
+
const split = host.frontmatter?.(source);
|
|
15
|
+
const env = {
|
|
16
|
+
...host.compilerEnv?.(context),
|
|
17
|
+
cudocCollect: true,
|
|
18
|
+
};
|
|
19
|
+
md.render(split?.body ?? source, env);
|
|
20
|
+
const captured = env.cudoc;
|
|
21
|
+
if (!captured)
|
|
22
|
+
throw new Error(`${host.adapter}: install the plugin on the supplied renderer`);
|
|
23
|
+
const tree = structuredClone(captured.tree);
|
|
24
|
+
const offset = source.indexOf(captured.source);
|
|
25
|
+
if (offset < 0)
|
|
26
|
+
throw new Error(`${host.adapter}: cannot map processed Markdown back to source`);
|
|
27
|
+
const lines = source.slice(0, offset).split("\n").length - 1;
|
|
28
|
+
const adjust = (node) => {
|
|
29
|
+
if (node.position)
|
|
30
|
+
for (const point of [node.position.start, node.position.end]) {
|
|
31
|
+
if (point.offset !== undefined)
|
|
32
|
+
point.offset += offset;
|
|
33
|
+
point.line += lines;
|
|
34
|
+
}
|
|
35
|
+
node.children?.forEach(adjust);
|
|
36
|
+
};
|
|
37
|
+
adjust(tree);
|
|
38
|
+
return {
|
|
39
|
+
tree,
|
|
40
|
+
frontmatter: split?.data ?? env.frontmatter ?? {},
|
|
41
|
+
diagnostics: captured.diagnostics,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,MAAM,UAAU,kBAAkB,CAChC,EAAc,EACd,IAAoB;IAEpB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QACzB,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,KAAK;YAClC,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,OAAO,oEAAoE,CACpF,CAAA;QACH,2EAA2E;QAC3E,4EAA4E;QAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAA;QACxC,MAAM,GAAG,GAA4B;YACnC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC;YAC9B,YAAY,EAAE,IAAI;SACnB,CAAA;QACD,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,GAAG,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAA6B,CAAA;QAClD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,OAAO,+CAA+C,CAC/D,CAAA;QACH,MAAM,IAAI,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAC9C,IAAI,MAAM,GAAG,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,OAAO,gDAAgD,CAChE,CAAA;QACH,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;QAC5D,MAAM,MAAM,GAAG,CAAC,IAAkB,EAAE,EAAE;YACpC,IAAI,IAAI,CAAC,QAAQ;gBACf,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC7D,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;wBAAE,KAAK,CAAC,MAAM,IAAI,MAAM,CAAA;oBACtD,KAAK,CAAC,IAAI,IAAI,KAAK,CAAA;gBACrB,CAAC;YACH,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;QAChC,CAAC,CAAA;QACD,MAAM,CAAC,IAA+B,CAAC,CAAA;QACvC,OAAO;YACL,IAAI;YACJ,WAAW,EACT,KAAK,EAAE,IAAI,IAAK,GAAG,CAAC,WAAuC,IAAI,EAAE;YACnE,WAAW,EAAE,QAAQ,CAAC,WAAW;SAClC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one markdown-it host contributes on top of the shared pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Everything a host generator does differently is named here, so the adapters
|
|
5
|
+
* stay as thin as `cudoc-docusaurus` and `cudoc-nextra` are over `cudoc-remark`.
|
|
6
|
+
*/
|
|
7
|
+
import type Token from "markdown-it/lib/token.mjs";
|
|
8
|
+
import type { Position } from "unist";
|
|
9
|
+
import type { DocumentNode, DocumentOptions, Host } from "@cudoment/cudoc/document";
|
|
10
|
+
export type TokenContext = {
|
|
11
|
+
/** The Markdown the token stream was produced from, frontmatter excluded. */
|
|
12
|
+
source: string;
|
|
13
|
+
/** The resolved plugin options, for reading the syntax modes. */
|
|
14
|
+
options: DocumentOptions;
|
|
15
|
+
/** The token's own attributes, already flattened into an object. */
|
|
16
|
+
attrs: Record<string, unknown>;
|
|
17
|
+
/** The token's source range, when markdown-it recorded one. */
|
|
18
|
+
position: Position | undefined;
|
|
19
|
+
};
|
|
20
|
+
/** Converts a token contributed by the host's own markdown-it plugins. */
|
|
21
|
+
export type TokenNode = (token: Token, context: TokenContext) => DocumentNode | undefined;
|
|
22
|
+
export type MarkdownItHost = {
|
|
23
|
+
/** Adapter package name; it prefixes every error this pipeline raises. */
|
|
24
|
+
adapter: string;
|
|
25
|
+
/** The value handed to `normalizeDocument`, which selects native syntax. */
|
|
26
|
+
host: Host;
|
|
27
|
+
/** Derives the collected document id from the host's markdown-it env. */
|
|
28
|
+
documentId: (env: Record<string, unknown>) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Builds the markdown-it env the host's template layer would have supplied.
|
|
31
|
+
*
|
|
32
|
+
* Collection calls the renderer directly, outside the host's own build, so
|
|
33
|
+
* whatever `documentId` reads has to be reconstructed here.
|
|
34
|
+
*/
|
|
35
|
+
compilerEnv?: (context: {
|
|
36
|
+
id: string;
|
|
37
|
+
filePath: string;
|
|
38
|
+
}) => Record<string, unknown>;
|
|
39
|
+
/** Converts the host's own tokens before the shared token mapping runs. */
|
|
40
|
+
token?: TokenNode;
|
|
41
|
+
/**
|
|
42
|
+
* Re-render inline tokens on a clone before conversion.
|
|
43
|
+
*
|
|
44
|
+
* Set it for a host that resolves link destinations in renderer rules, after
|
|
45
|
+
* its core token passes. Rendering the clone lets those final attributes
|
|
46
|
+
* reach the AST without applying base paths twice to the host's own tokens.
|
|
47
|
+
*/
|
|
48
|
+
resolveInlineAttributes?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Splits frontmatter that the host removes before markdown-it sees the source.
|
|
51
|
+
*
|
|
52
|
+
* Only needed by a host that strips frontmatter outside markdown-it, so the
|
|
53
|
+
* collector has to do the same to reach the same token stream.
|
|
54
|
+
*/
|
|
55
|
+
frontmatter?: (source: string) => {
|
|
56
|
+
body: string;
|
|
57
|
+
data: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,MAAM,2BAA2B,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,IAAI,EACL,MAAM,0BAA0B,CAAA;AAEjC,MAAM,MAAM,YAAY,GAAG;IACzB,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAA;IACd,iEAAiE;IACjE,OAAO,EAAE,eAAe,CAAA;IACxB,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,+DAA+D;IAC/D,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAA;CAC/B,CAAA;AAED,0EAA0E;AAC1E,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,YAAY,KAClB,YAAY,GAAG,SAAS,CAAA;AAE7B,MAAM,MAAM,cAAc,GAAG;IAC3B,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAA;IACf,4EAA4E;IAC5E,IAAI,EAAE,IAAI,CAAA;IACV,yEAAyE;IACzE,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAA;IACpD;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE;QACtB,EAAE,EAAE,MAAM,CAAA;QACV,QAAQ,EAAE,MAAM,CAAA;KACjB,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,2EAA2E;IAC3E,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK;QAChC,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC9B,CAAA;CACF,CAAA"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one markdown-it host contributes on top of the shared pipeline.
|
|
3
|
+
*
|
|
4
|
+
* Everything a host generator does differently is named here, so the adapters
|
|
5
|
+
* stay as thin as `cudoc-docusaurus` and `cudoc-nextra` are over `cudoc-remark`.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { tokensToAst } from "./tokens.js";
|
|
2
|
+
export type { TokenConversion } from "./tokens.js";
|
|
3
|
+
export { installHostPlugin } from "./plugin.js";
|
|
4
|
+
export { createHostCompiler } from "./compiler.js";
|
|
5
|
+
export { resolveHostOptions } from "./options.js";
|
|
6
|
+
export type { HostPluginOptions } from "./options.js";
|
|
7
|
+
export type { MarkdownItHost, TokenNode, TokenContext } from "./host.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The options a markdown-it host adapter accepts.
|
|
3
|
+
*
|
|
4
|
+
* The shape mirrors `HostPluginOptions` in `cudoc-remark` so the two lineages
|
|
5
|
+
* are configured the same way. Unknown keys are rejected while the site config
|
|
6
|
+
* loads rather than at the first document, because an error raised from inside
|
|
7
|
+
* a markdown-it core rule is much harder to place.
|
|
8
|
+
*/
|
|
9
|
+
import type { Root } from "mdast";
|
|
10
|
+
import { type DocumentOptions } from "@cudoment/cudoc/document";
|
|
11
|
+
import type { Library } from "@cudoment/cudoc/node/library";
|
|
12
|
+
export type HostPluginOptions = Omit<DocumentOptions, "host" | "format"> & {
|
|
13
|
+
/** Called with the document tree built from the actual host token stream. */
|
|
14
|
+
onDocument?: (tree: Root, source: string, env: Record<string, unknown>) => void;
|
|
15
|
+
/** Collected documents, required before any embed can be expanded. */
|
|
16
|
+
library?: Library;
|
|
17
|
+
/** Where `prepareEmbeds` wrote its results; defaults to `.cudoc/documents`. */
|
|
18
|
+
outDir?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Validates the options and resolves the syntax modes once.
|
|
22
|
+
*
|
|
23
|
+
* `headingIds` stays on `host` for every markdown-it host: the host's own
|
|
24
|
+
* slugger runs after cudoc, and the plugin copies the resolved ids back onto
|
|
25
|
+
* the host tokens instead of assigning its own.
|
|
26
|
+
*/
|
|
27
|
+
export declare const resolveHostOptions: (options: HostPluginOptions, adapter: string) => HostPluginOptions;
|
|
28
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAiB,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAE3D,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG;IACzE,6EAA6E;IAC7E,UAAU,CAAC,EAAE,CACX,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACzB,IAAI,CAAA;IACT,sEAAsE;IACtE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAaD;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,iBAAiB,EAC1B,SAAS,MAAM,KACd,iBAYF,CAAA"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The options a markdown-it host adapter accepts.
|
|
3
|
+
*
|
|
4
|
+
* The shape mirrors `HostPluginOptions` in `cudoc-remark` so the two lineages
|
|
5
|
+
* are configured the same way. Unknown keys are rejected while the site config
|
|
6
|
+
* loads rather than at the first document, because an error raised from inside
|
|
7
|
+
* a markdown-it core rule is much harder to place.
|
|
8
|
+
*/
|
|
9
|
+
import { resolveSyntax } from "@cudoment/cudoc/document";
|
|
10
|
+
const KNOWN_KEYS = new Set([
|
|
11
|
+
"syntax",
|
|
12
|
+
"calloutTypes",
|
|
13
|
+
"components",
|
|
14
|
+
"tableColumnLayout",
|
|
15
|
+
"headingIds",
|
|
16
|
+
"onDocument",
|
|
17
|
+
"library",
|
|
18
|
+
"outDir",
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* Validates the options and resolves the syntax modes once.
|
|
22
|
+
*
|
|
23
|
+
* `headingIds` stays on `host` for every markdown-it host: the host's own
|
|
24
|
+
* slugger runs after cudoc, and the plugin copies the resolved ids back onto
|
|
25
|
+
* the host tokens instead of assigning its own.
|
|
26
|
+
*/
|
|
27
|
+
export const resolveHostOptions = (options, adapter) => {
|
|
28
|
+
if (typeof options !== "object" || options === null)
|
|
29
|
+
throw new TypeError(`${adapter}: options must be an object`);
|
|
30
|
+
for (const key of Object.keys(options))
|
|
31
|
+
if (!KNOWN_KEYS.has(key))
|
|
32
|
+
throw new TypeError(`${adapter}: unknown option "${key}"`);
|
|
33
|
+
if (options.headingIds && options.headingIds !== "host")
|
|
34
|
+
throw new TypeError(`${adapter}: headingIds must be "host"; the host slugger assigns ids`);
|
|
35
|
+
resolveSyntax(options.syntax);
|
|
36
|
+
return options;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,aAAa,EAAwB,MAAM,0BAA0B,CAAA;AAgB9E,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS;IACjC,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,QAAQ;CAC6B,CAAC,CAAA;AAExC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAA0B,EAC1B,OAAe,EACI,EAAE;IACrB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI;QACjD,MAAM,IAAI,SAAS,CAAC,GAAG,OAAO,6BAA6B,CAAC,CAAA;IAC9D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;QACpC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;YACtB,MAAM,IAAI,SAAS,CAAC,GAAG,OAAO,qBAAqB,GAAG,GAAG,CAAC,CAAA;IAC9D,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,UAAU,KAAK,MAAM;QACrD,MAAM,IAAI,SAAS,CACjB,GAAG,OAAO,2DAA2D,CACtE,CAAA;IACH,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown-it plugin every host in this lineage installs.
|
|
3
|
+
*
|
|
4
|
+
* It is the counterpart of `createHostPlugins` in `cudoc-remark`: the shared
|
|
5
|
+
* arrangement lives here, and a host adapter contributes only its
|
|
6
|
+
* `MarkdownItHost` definition, so the hosts cannot quietly diverge.
|
|
7
|
+
*
|
|
8
|
+
* The rule runs in `md.core`, after the host's own core passes, so native
|
|
9
|
+
* anchors, links and containers are already tokens by the time cudoc reads
|
|
10
|
+
* them. cudoc then renders the document itself and hands the HTML back through
|
|
11
|
+
* the renderer, which is what keeps one document from being rendered twice.
|
|
12
|
+
*/
|
|
13
|
+
import type MarkdownIt from "markdown-it";
|
|
14
|
+
import { type HostPluginOptions } from "./options.js";
|
|
15
|
+
import type { MarkdownItHost } from "./host.js";
|
|
16
|
+
/**
|
|
17
|
+
* Installs the shared pipeline on a configured markdown-it instance.
|
|
18
|
+
*
|
|
19
|
+
* Call it from the adapter's default export, which is what a site hands to
|
|
20
|
+
* `md.use`. The options are validated here so a mistyped key fails while the
|
|
21
|
+
* site configuration loads.
|
|
22
|
+
*/
|
|
23
|
+
export declare function installHostPlugin(md: MarkdownIt, options: HostPluginOptions, host: MarkdownItHost): void;
|
|
24
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AAkBzC,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAS/C;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,cAAc,GACnB,IAAI,CA0IN"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown-it plugin every host in this lineage installs.
|
|
3
|
+
*
|
|
4
|
+
* It is the counterpart of `createHostPlugins` in `cudoc-remark`: the shared
|
|
5
|
+
* arrangement lives here, and a host adapter contributes only its
|
|
6
|
+
* `MarkdownItHost` definition, so the hosts cannot quietly diverge.
|
|
7
|
+
*
|
|
8
|
+
* The rule runs in `md.core`, after the host's own core passes, so native
|
|
9
|
+
* anchors, links and containers are already tokens by the time cudoc reads
|
|
10
|
+
* them. cudoc then renders the document itself and hands the HTML back through
|
|
11
|
+
* the renderer, which is what keeps one document from being rendered twice.
|
|
12
|
+
*/
|
|
13
|
+
import { normalizeDocument, nodeText, } from "@cudoment/cudoc/document";
|
|
14
|
+
import { renderDocument } from "@cudoment/cudoc/render";
|
|
15
|
+
import { resolveEmbed, parseEmbedSpec, } from "@cudoment/cudoc/node/resolve-embed";
|
|
16
|
+
import { readPreparedEmbeds, embedKey, } from "@cudoment/cudoc/node/prepare-embeds";
|
|
17
|
+
import { tokensToAst } from "./tokens.js";
|
|
18
|
+
import { resolveHostOptions } from "./options.js";
|
|
19
|
+
/** Clones a token deeply enough that rendering it cannot touch the original. */
|
|
20
|
+
const cloneToken = (token) => Object.assign(Object.create(Object.getPrototypeOf(token)), token, {
|
|
21
|
+
attrs: token.attrs?.map((pair) => [...pair]) ?? null,
|
|
22
|
+
children: token.children?.map(cloneToken) ?? null,
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Installs the shared pipeline on a configured markdown-it instance.
|
|
26
|
+
*
|
|
27
|
+
* Call it from the adapter's default export, which is what a site hands to
|
|
28
|
+
* `md.use`. The options are validated here so a mistyped key fails while the
|
|
29
|
+
* site configuration loads.
|
|
30
|
+
*/
|
|
31
|
+
export function installHostPlugin(md, options, host) {
|
|
32
|
+
resolveHostOptions(options, host.adapter);
|
|
33
|
+
const conversion = { adapter: host.adapter, token: host.token };
|
|
34
|
+
const nativeFence = md.renderer.rules.fence;
|
|
35
|
+
md.renderer.rules.fence = (tokens, index, renderOptions, env, self) => tokens[index].info.trim() === "cudoc-embed" &&
|
|
36
|
+
env.cudocRendered !== undefined
|
|
37
|
+
? ""
|
|
38
|
+
: nativeFence
|
|
39
|
+
? nativeFence(tokens, index, renderOptions, env, self)
|
|
40
|
+
: self.renderToken(tokens, index, renderOptions);
|
|
41
|
+
const nativeRender = md.renderer.render.bind(md.renderer);
|
|
42
|
+
md.renderer.render = (tokens, renderOptions, env) => {
|
|
43
|
+
const nativeHtml = nativeRender(tokens, renderOptions, env);
|
|
44
|
+
return env.cudocRendered ?? nativeHtml;
|
|
45
|
+
};
|
|
46
|
+
md.core.ruler.push("cudoc", (state) => {
|
|
47
|
+
let tokens = state.tokens;
|
|
48
|
+
if (host.resolveInlineAttributes) {
|
|
49
|
+
tokens = state.tokens.map(cloneToken);
|
|
50
|
+
for (const token of tokens)
|
|
51
|
+
if (token.type === "inline" && token.children)
|
|
52
|
+
md.renderer.renderInline(token.children, md.options, {
|
|
53
|
+
...state.env,
|
|
54
|
+
links: [],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const tree = tokensToAst(tokens, state.src, options, conversion);
|
|
58
|
+
const diagnostics = normalizeDocument(tree, state.src, { ...options, host: host.host, format: "md", headingIds: "host" }, (source) => {
|
|
59
|
+
const inline = [];
|
|
60
|
+
const env = { ...state.env, links: [] };
|
|
61
|
+
md.inline.parse(source, md, env, inline);
|
|
62
|
+
for (const token of inline)
|
|
63
|
+
if (token.type === "text_special")
|
|
64
|
+
token.type = "text";
|
|
65
|
+
if (host.resolveInlineAttributes)
|
|
66
|
+
md.renderer.renderInline(inline, md.options, env);
|
|
67
|
+
return tokensToAst(inline, source, options, conversion)
|
|
68
|
+
.children;
|
|
69
|
+
});
|
|
70
|
+
const updateHeading = (node) => {
|
|
71
|
+
if (node.type === "heading")
|
|
72
|
+
for (const child of node.children ?? []) {
|
|
73
|
+
if (child.data?.cudoc?.kind === "permalink") {
|
|
74
|
+
child.url = `#${node.data?.hProperties?.id}`;
|
|
75
|
+
if (child.data.hProperties)
|
|
76
|
+
child.data.hProperties.href = child.url;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
node.children?.forEach(updateHeading);
|
|
80
|
+
};
|
|
81
|
+
updateHeading(tree);
|
|
82
|
+
// The host slugs heading text after this rule, so the resolved ids and
|
|
83
|
+
// titles are copied back onto its own tokens; that is what keeps the
|
|
84
|
+
// host's heading anchors and its table of contents in agreement.
|
|
85
|
+
const headingMap = new Map();
|
|
86
|
+
const collectHeadings = (node) => {
|
|
87
|
+
if (node.type === "heading" && node.position)
|
|
88
|
+
headingMap.set(node.position.start.line, node);
|
|
89
|
+
node.children?.forEach(collectHeadings);
|
|
90
|
+
};
|
|
91
|
+
collectHeadings(tree);
|
|
92
|
+
state.tokens.forEach((token, index) => {
|
|
93
|
+
if (token.type !== "heading_open")
|
|
94
|
+
return;
|
|
95
|
+
const heading = headingMap.get((token.map?.[0] ?? -1) + 1);
|
|
96
|
+
if (!heading)
|
|
97
|
+
return;
|
|
98
|
+
token.attrSet("id", String(heading.data?.hProperties?.id));
|
|
99
|
+
const inline = state.tokens[index + 1];
|
|
100
|
+
const title = heading.children
|
|
101
|
+
?.filter((n) => !["badge", "permalink"].includes(n.data?.cudoc?.kind ?? ""))
|
|
102
|
+
.map(nodeText)
|
|
103
|
+
.join("")
|
|
104
|
+
.trim() ?? "";
|
|
105
|
+
inline.content = title;
|
|
106
|
+
const label = new state.Token("text", "", 0);
|
|
107
|
+
label.content = title;
|
|
108
|
+
inline.children = [label];
|
|
109
|
+
});
|
|
110
|
+
state.env.cudoc = {
|
|
111
|
+
tree: structuredClone(tree),
|
|
112
|
+
source: state.src,
|
|
113
|
+
diagnostics,
|
|
114
|
+
};
|
|
115
|
+
options.onDocument?.(structuredClone(tree), state.src, state.env);
|
|
116
|
+
let index = 0;
|
|
117
|
+
const expand = (node) => {
|
|
118
|
+
if (!node.children)
|
|
119
|
+
return;
|
|
120
|
+
node.children = node.children.flatMap((child) => {
|
|
121
|
+
if (child.type === "code" && child.lang === "cudoc-embed") {
|
|
122
|
+
if (!options.library)
|
|
123
|
+
throw new Error(`${host.adapter}: build documents and provide library before rendering embeds`);
|
|
124
|
+
const documentId = host.documentId(state.env);
|
|
125
|
+
const snapshot = options.library.documents.find((d) => d.id === documentId);
|
|
126
|
+
if (snapshot && !snapshot.source.text.endsWith(state.src))
|
|
127
|
+
throw new Error(`${host.adapter}: stale collected source ${documentId}; recollect documents`);
|
|
128
|
+
if (!options.library.compiler) {
|
|
129
|
+
const prepared = readPreparedEmbeds(options.outDir ?? ".cudoc/documents", documentId, snapshot?.source.text ?? state.src);
|
|
130
|
+
const result = prepared.blocks[embedKey(documentId, child.value, ++index)];
|
|
131
|
+
if (!result)
|
|
132
|
+
throw new Error(`${host.adapter}: missing prepared embed in ${documentId}`);
|
|
133
|
+
return structuredClone(result.children);
|
|
134
|
+
}
|
|
135
|
+
return resolveEmbed(options.library, parseEmbedSpec(child.value), {
|
|
136
|
+
documentId,
|
|
137
|
+
prefix: `embed-${++index}`,
|
|
138
|
+
}).children;
|
|
139
|
+
}
|
|
140
|
+
expand(child);
|
|
141
|
+
return [child];
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
if (!state.env.cudocCollect)
|
|
145
|
+
expand(tree);
|
|
146
|
+
state.env.cudocRendered = renderDocument(tree, {
|
|
147
|
+
highlight: (code, lang) => lang === "cudoc-embed"
|
|
148
|
+
? ""
|
|
149
|
+
: (md.options.highlight?.(code, lang ?? "", "") ?? ""),
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,EACL,iBAAiB,EACjB,QAAQ,GAET,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,YAAY,EACZ,cAAc,GACf,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACL,kBAAkB,EAClB,QAAQ,GACT,MAAM,qCAAqC,CAAA;AAC5C,OAAO,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AC,EAAE;gBACJ,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;SAC3D,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/tokens.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown-it token stream converted into cudoc's document AST.
|
|
3
|
+
*
|
|
4
|
+
* This is the shared half of the markdown-it lineage: it converts the tokens a
|
|
5
|
+
* host already produced, and never parses the Markdown a second time. Tokens
|
|
6
|
+
* contributed by a host's own plugins go through the host's `token` hook first.
|
|
7
|
+
*/
|
|
8
|
+
import type Token from "markdown-it/lib/token.mjs";
|
|
9
|
+
import type { Root } from "mdast";
|
|
10
|
+
import { type DocumentOptions } from "@cudoment/cudoc/document";
|
|
11
|
+
import type { TokenNode } from "./host.js";
|
|
12
|
+
export type TokenConversion = {
|
|
13
|
+
/** Adapter package name used when a token has no mapping. */
|
|
14
|
+
adapter?: string;
|
|
15
|
+
/** Converts a token contributed by the host's own markdown-it plugins. */
|
|
16
|
+
token?: TokenNode;
|
|
17
|
+
};
|
|
18
|
+
/** Converts the actual markdown-it tokens; it does not parse Markdown again. */
|
|
19
|
+
export declare function tokensToAst(tokens: Token[], source: string, options?: DocumentOptions, conversion?: TokenConversion): Root;
|
|
20
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,KAAK,MAAM,2BAA2B,CAAA;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,0BAA0B,CAAA;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,MAAM,eAAe,GAAG;IAC5B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAoBD,gFAAgF;AAChF,wBAAgB,WAAW,CACzB,MAAM,EAAE,KAAK,EAAE,EACf,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAoB,EAC7B,UAAU,GAAE,eAAoB,GAC/B,IAAI,CA6MN"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown-it token stream converted into cudoc's document AST.
|
|
3
|
+
*
|
|
4
|
+
* This is the shared half of the markdown-it lineage: it converts the tokens a
|
|
5
|
+
* host already produced, and never parses the Markdown a second time. Tokens
|
|
6
|
+
* contributed by a host's own plugins go through the host's `token` hook first.
|
|
7
|
+
*/
|
|
8
|
+
import { makeCallout, resolveSyntax, isHost, } from "@cudoment/cudoc/document";
|
|
9
|
+
/** The block and inline tokens every markdown-it host produces alike. */
|
|
10
|
+
const NESTING_TYPES = {
|
|
11
|
+
paragraph_open: "paragraph",
|
|
12
|
+
heading_open: "heading",
|
|
13
|
+
blockquote_open: "blockquote",
|
|
14
|
+
bullet_list_open: "list",
|
|
15
|
+
ordered_list_open: "list",
|
|
16
|
+
list_item_open: "listItem",
|
|
17
|
+
table_open: "table",
|
|
18
|
+
tr_open: "tableRow",
|
|
19
|
+
th_open: "tableCell",
|
|
20
|
+
td_open: "tableCell",
|
|
21
|
+
strong_open: "strong",
|
|
22
|
+
em_open: "emphasis",
|
|
23
|
+
s_open: "delete",
|
|
24
|
+
link_open: "link",
|
|
25
|
+
};
|
|
26
|
+
/** Converts the actual markdown-it tokens; it does not parse Markdown again. */
|
|
27
|
+
export function tokensToAst(tokens, source, options = {}, conversion = {}) {
|
|
28
|
+
const adapter = conversion.adapter ?? "cudoc-markdown-it";
|
|
29
|
+
const root = { type: "root", children: [] };
|
|
30
|
+
const stack = [root];
|
|
31
|
+
const offsets = [0];
|
|
32
|
+
for (let i = 0; i < source.length; i++)
|
|
33
|
+
if (source[i] === "\n")
|
|
34
|
+
offsets.push(i + 1);
|
|
35
|
+
const position = (token) => token.map
|
|
36
|
+
? {
|
|
37
|
+
start: {
|
|
38
|
+
line: token.map[0] + 1,
|
|
39
|
+
column: 1,
|
|
40
|
+
offset: offsets[token.map[0]],
|
|
41
|
+
},
|
|
42
|
+
end: {
|
|
43
|
+
line: token.map[1] + 1,
|
|
44
|
+
column: 1,
|
|
45
|
+
offset: offsets[token.map[1]] ?? source.length,
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
: undefined;
|
|
49
|
+
const parent = () => stack.at(-1);
|
|
50
|
+
const add = (node) => {
|
|
51
|
+
parent().children.push(node);
|
|
52
|
+
};
|
|
53
|
+
const consume = (token) => {
|
|
54
|
+
if (token.nesting === -1) {
|
|
55
|
+
stack.pop();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (token.type === "inline") {
|
|
59
|
+
if (parent().type === "tableCell") {
|
|
60
|
+
const row = [...stack].reverse().find((n) => n.type === "tableRow");
|
|
61
|
+
const start = source.indexOf(token.content, row?.position?.start.offset ?? 0);
|
|
62
|
+
if (start >= 0)
|
|
63
|
+
parent().position = {
|
|
64
|
+
start: {
|
|
65
|
+
line: row?.position?.start.line ?? 1,
|
|
66
|
+
column: 1,
|
|
67
|
+
offset: start,
|
|
68
|
+
},
|
|
69
|
+
end: {
|
|
70
|
+
line: row?.position?.start.line ?? 1,
|
|
71
|
+
column: 1,
|
|
72
|
+
offset: start + token.content.length,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
token.children?.forEach(consume);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const attrs = Object.fromEntries(token.attrs ?? []);
|
|
80
|
+
const common = {
|
|
81
|
+
position: position(token),
|
|
82
|
+
...(token.attrs?.length ? { data: { hProperties: attrs } } : {}),
|
|
83
|
+
};
|
|
84
|
+
const hosted = conversion.token?.(token, {
|
|
85
|
+
source,
|
|
86
|
+
options,
|
|
87
|
+
attrs,
|
|
88
|
+
position: position(token),
|
|
89
|
+
});
|
|
90
|
+
let node;
|
|
91
|
+
if (hosted)
|
|
92
|
+
node = hosted;
|
|
93
|
+
else if (["text", "text_special"].includes(token.type))
|
|
94
|
+
node = { type: "text", value: token.content };
|
|
95
|
+
else if (token.type === "softbreak")
|
|
96
|
+
node = { type: "text", value: "\n" };
|
|
97
|
+
else if (token.type === "hardbreak")
|
|
98
|
+
node = { type: "break" };
|
|
99
|
+
else if (token.type === "code_inline")
|
|
100
|
+
node = { type: "inlineCode", value: token.content };
|
|
101
|
+
else if (["fence", "code_block"].includes(token.type))
|
|
102
|
+
node = {
|
|
103
|
+
type: "code",
|
|
104
|
+
value: token.content.replace(/\n$/, ""),
|
|
105
|
+
lang: token.info.split(/\s+/)[0] || null,
|
|
106
|
+
meta: token.info.split(/\s+/).slice(1).join(" "),
|
|
107
|
+
...common,
|
|
108
|
+
};
|
|
109
|
+
else if (token.type === "image")
|
|
110
|
+
node = {
|
|
111
|
+
type: "image",
|
|
112
|
+
url: String(attrs.src ?? ""),
|
|
113
|
+
alt: token.content,
|
|
114
|
+
title: attrs.title ?? null,
|
|
115
|
+
...common,
|
|
116
|
+
};
|
|
117
|
+
else if (["html_inline", "html_block"].includes(token.type))
|
|
118
|
+
node = { type: "html", value: token.content, ...common };
|
|
119
|
+
else if (token.type === "hr")
|
|
120
|
+
node = { type: "thematicBreak", ...common };
|
|
121
|
+
else if (token.type === "github_alert_open") {
|
|
122
|
+
// A host may label an untitled alert with its own type name. Every other
|
|
123
|
+
// lineage leaves `> [!TIP]` untitled, so a title that only repeats the
|
|
124
|
+
// type is dropped and the same Markdown means the same thing everywhere.
|
|
125
|
+
const label = String(token.meta.title ?? "");
|
|
126
|
+
const repeatsType = label.toLowerCase() === String(token.meta.type ?? "").toLowerCase();
|
|
127
|
+
node = makeCallout(token.meta.type, label && !repeatsType ? [{ type: "text", value: label }] : [], [], position(token));
|
|
128
|
+
}
|
|
129
|
+
else if (token.type.startsWith("container_") && token.nesting === 1) {
|
|
130
|
+
const type = token.type.slice(10, -5);
|
|
131
|
+
const title = token.info.trim().slice(type.length).trim();
|
|
132
|
+
node =
|
|
133
|
+
type === "details"
|
|
134
|
+
? {
|
|
135
|
+
type: "blockquote",
|
|
136
|
+
data: { hName: "details" },
|
|
137
|
+
position: position(token),
|
|
138
|
+
children: [
|
|
139
|
+
{
|
|
140
|
+
type: "paragraph",
|
|
141
|
+
data: { hName: "summary" },
|
|
142
|
+
children: [{ type: "text", value: title || "Details" }],
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
}
|
|
146
|
+
: makeCallout(type, title ? [{ type: "text", value: title }] : [], [], position(token));
|
|
147
|
+
if (type !== "details" &&
|
|
148
|
+
!isHost(resolveSyntax(options.syntax).callout)) {
|
|
149
|
+
node.data = {
|
|
150
|
+
hName: "div",
|
|
151
|
+
hProperties: { className: ["custom-block", type] },
|
|
152
|
+
};
|
|
153
|
+
node.children[0].data = {
|
|
154
|
+
hProperties: { className: ["custom-block-title"] },
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (["thead_open", "tbody_open"].includes(token.type)) {
|
|
160
|
+
stack.push(parent());
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (!NESTING_TYPES[token.type])
|
|
164
|
+
throw new Error(`${adapter}: unsupported token ${token.type}; provide a token adapter before exporting`);
|
|
165
|
+
node = { type: NESTING_TYPES[token.type], children: [], ...common };
|
|
166
|
+
if (node.type === "heading") {
|
|
167
|
+
node.depth = Number(token.tag.slice(1));
|
|
168
|
+
node.data = {
|
|
169
|
+
...node.data,
|
|
170
|
+
cudoc: {
|
|
171
|
+
kind: "heading",
|
|
172
|
+
explicitId: /\{#[^}]+\}/.test(source.slice(node.position?.start.offset, node.position?.end.offset)),
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (node.type === "link") {
|
|
177
|
+
node.url = String(attrs.href ?? "");
|
|
178
|
+
// A host's heading permalink is marked here, before normalization, so
|
|
179
|
+
// every transform that reads a heading's own text can exclude it. Its
|
|
180
|
+
// href is corrected afterwards, once the heading id is resolved.
|
|
181
|
+
if (attrs.class === "header-anchor")
|
|
182
|
+
node.data = { ...node.data, cudoc: { kind: "permalink" } };
|
|
183
|
+
}
|
|
184
|
+
// markdown-it reports alignment as an inline style on each cell. The
|
|
185
|
+
// remark hosts put it on the table node, so it is collected there too and
|
|
186
|
+
// an exported tree means the same thing on both lineages.
|
|
187
|
+
if (["tableCell"].includes(node.type)) {
|
|
188
|
+
const align = /text-align:\s*(left|center|right)/.exec(String(attrs.style ?? ""))?.[1];
|
|
189
|
+
const table = [...stack].reverse().find((n) => n.type === "table");
|
|
190
|
+
if (table) {
|
|
191
|
+
const row = [...stack].reverse().find((n) => n.type === "tableRow");
|
|
192
|
+
const columns = table.align ?? [];
|
|
193
|
+
if (row === table.children?.[0] || !table.align)
|
|
194
|
+
columns.push(align ?? null);
|
|
195
|
+
table.align = columns;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (node.type === "list") {
|
|
199
|
+
node.ordered = token.type === "ordered_list_open";
|
|
200
|
+
node.start = node.ordered ? Number(attrs.start ?? 1) : null;
|
|
201
|
+
node.spread = false;
|
|
202
|
+
}
|
|
203
|
+
if (node.type === "listItem") {
|
|
204
|
+
node.spread = false;
|
|
205
|
+
node.checked = null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
add(node);
|
|
209
|
+
if (token.nesting === 1)
|
|
210
|
+
stack.push(node);
|
|
211
|
+
};
|
|
212
|
+
tokens.forEach(consume);
|
|
213
|
+
return root;
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=tokens.js.map
|
|
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MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACvB,OAAO,IAAuB,CAAA;AAChC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cudoc-markdown-it",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Shared markdown-it pipeline for cudoc host adapters",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/cudoment/cudoc.git",
|
|
9
|
+
"directory": "packages/cudoc-markdown-it"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/cudoment/cudoc/tree/main/packages/cudoc-markdown-it#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/cudoment/cudoc/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cudoc",
|
|
17
|
+
"markdown-it",
|
|
18
|
+
"markdown-it-plugin",
|
|
19
|
+
"markdown",
|
|
20
|
+
"mdast"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc --build",
|
|
41
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@cudoment/cudoc": "0.3.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"markdown-it": "^14.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/markdown-it": "^14.2.0"
|
|
51
|
+
},
|
|
52
|
+
"author": "cudoment",
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=20"
|
|
55
|
+
}
|
|
56
|
+
}
|