cudoc-docusaurus 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,31 @@
1
+ # cudoc-docusaurus
2
+
3
+ Connect cudoc to Docusaurus while retaining native heading IDs and TOC behavior.
4
+
5
+ ESM · Node.js 20+
6
+
7
+ ```sh
8
+ npm install @cudoment/cudoc cudoc-remark cudoc-docusaurus
9
+ ```
10
+
11
+ ```js
12
+ import { cudocRemarkPlugins } from "cudoc-docusaurus"
13
+
14
+ // In the Docusaurus docs plugin options:
15
+ const docs = {
16
+ beforeDefaultRemarkPlugins: cudocRemarkPlugins({
17
+ syntax: { headingAnchor: "both", callout: "both" },
18
+ }),
19
+ }
20
+ ```
21
+
22
+ Use `markdown.format: "detect"` for `.md` and `.mdx`. Import `@cudoment/cudoc/styles.css` from site CSS. The explicit `syntax` setup needs no cudoc theme plugin or component registration. For embedding, use the actual Docusaurus compiler during collection and add `cudoc-remark/embed` afterward in the rendering pipeline.
23
+
24
+ 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.
25
+
26
+ - [Usage guide](https://github.com/cudoment/cudoc/tree/main/docs/docusaurus.md) · [한국어 가이드](https://github.com/cudoment/cudoc/tree/main/docs/docusaurus.ko.md)
27
+ - [Markdown syntax](https://github.com/cudoment/cudoc/tree/main/docs/syntax.md)
28
+ - [Embedding](https://github.com/cudoment/cudoc/tree/main/docs/embedding.md)
29
+ - [Standalone HTML alongside a host](https://github.com/cudoment/cudoc/tree/main/docs/html.md#export-alongside-an-existing-site)
30
+ - [API reference](https://github.com/cudoment/cudoc/tree/main/docs/api-reference/README.md)
31
+ - [Runnable examples](https://github.com/cudoment/cudoc/tree/main/examples/README.md)
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copies the id from a cudoc anchor onto the heading itself.
3
+ *
4
+ * Docusaurus generates a heading id by slugifying the heading text, and builds
5
+ * its table of contents from those ids. Left alone it would produce a second id
6
+ * next to cudoc's anchor, and a deep link would resolve to whichever the
7
+ * browser found first. Its heading plugin honours an id that is already on
8
+ * `data.hProperties`, so writing the anchor id there makes the heading, the
9
+ * table of contents and the anchor agree on one value.
10
+ */
11
+ import type { Root } from "mdast";
12
+ import type { Plugin } from "unified";
13
+ export type PromoteAnchorIdsOptions = {
14
+ /** Element name the id is read from. Matches `headingMetadata.anchor.name`. */
15
+ anchorName?: string;
16
+ /** Attribute the id is read from. Matches `headingMetadata.anchor.idAttribute`. */
17
+ idAttribute?: string;
18
+ };
19
+ export declare const promoteAnchorIds: Plugin<[PromoteAnchorIdsOptions?], Root>;
20
+ export default promoteAnchorIds;
21
+ //# sourceMappingURL=heading-ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heading-ids.d.ts","sourceRoot":"","sources":["../src/heading-ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAQrC,MAAM,MAAM,uBAAuB,GAAG;IACpC,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAOD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,IAAI,CAoBrE,CAAA;AAED,eAAe,gBAAgB,CAAA"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copies the id from a cudoc anchor onto the heading itself.
3
+ *
4
+ * Docusaurus generates a heading id by slugifying the heading text, and builds
5
+ * its table of contents from those ids. Left alone it would produce a second id
6
+ * next to cudoc's anchor, and a deep link would resolve to whichever the
7
+ * browser found first. Its heading plugin honours an id that is already on
8
+ * `data.hProperties`, so writing the anchor id there makes the heading, the
9
+ * table of contents and the anchor agree on one value.
10
+ */
11
+ import { visit } from "unist-util-visit";
12
+ import { extractAnchorId, findAnchorNode, DEFAULT_ANCHOR_NAME, } from "cudoc-core";
13
+ export const promoteAnchorIds = (options = {}) => {
14
+ const anchorName = options.anchorName ?? DEFAULT_ANCHOR_NAME;
15
+ const idAttribute = options.idAttribute ?? "id";
16
+ return (tree) => {
17
+ visit(tree, "heading", (heading) => {
18
+ const id = extractAnchorId(findAnchorNode(heading.children, anchorName), idAttribute);
19
+ if (!id)
20
+ return;
21
+ const data = (heading.data ?? (heading.data = {}));
22
+ const properties = data.hProperties ?? (data.hProperties = {});
23
+ // An id the author put there another way wins: this only fills a gap.
24
+ if (properties.id === undefined)
25
+ properties.id = id;
26
+ });
27
+ };
28
+ };
29
+ export default promoteAnchorIds;
30
+ //# sourceMappingURL=heading-ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heading-ids.js","sourceRoot":"","sources":["../src/heading-ids.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EACL,eAAe,EACf,cAAc,EACd,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAcnB,MAAM,CAAC,MAAM,gBAAgB,GAA6C,CACxE,OAAO,GAAG,EAAE,EACZ,EAAE;IACF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,mBAAmB,CAAA;IAC5D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAA;IAE/C,OAAO,CAAC,IAAU,EAAE,EAAE;QACpB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,OAAgB,EAAE,EAAE;YAC1C,MAAM,EAAE,GAAG,eAAe,CACxB,cAAc,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,EAC5C,WAAW,CACZ,CAAA;YACD,IAAI,CAAC,EAAE;gBAAE,OAAM;YAEf,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,CAAgB,CAAA;YACjE,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC,CAAA;YAC9D,sEAAsE;YACtE,IAAI,UAAU,CAAC,EAAE,KAAK,SAAS;gBAAE,UAAU,CAAC,EAAE,GAAG,EAAE,CAAA;QACrD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,gBAAgB,CAAA"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Docusaurus adapter.
3
+ *
4
+ * The anchors have to exist before Docusaurus assigns its own heading ids.
5
+ *
6
+ * The arrangement itself is `createHostPlugins`, shared with the Nextra
7
+ * adapter. What is specific to Docusaurus is the theme below, because this is
8
+ * the host where components are contributed by a plugin rather than named in a
9
+ * config file.
10
+ */
11
+ import type { PluggableList } from "unified";
12
+ import { type HostPluginOptions } from "cudoc-remark";
13
+ export type CudocDocusaurusOptions = HostPluginOptions;
14
+ /**
15
+ * The remark plugins to hand to `beforeDefaultRemarkPlugins`.
16
+ *
17
+ * They must run before Docusaurus assigns heading ids in its default plugins.
18
+ */
19
+ export declare const cudocRemarkPlugins: (options?: CudocDocusaurusOptions) => PluggableList;
20
+ type DocusaurusPlugin = {
21
+ name: string;
22
+ getThemePath: () => string;
23
+ };
24
+ /**
25
+ * The Docusaurus plugin, which contributes nothing but the theme components.
26
+ *
27
+ * cudoc emits capitalized elements, and MDX throws at render time when one is
28
+ * missing. Adding this plugin layers a `MDXComponents` over the site's own so
29
+ * the names resolve without anyone swizzling anything.
30
+ */
31
+ declare const cudocDocusaurus: () => DocusaurusPlugin;
32
+ export default cudocDocusaurus;
33
+ export { promoteAnchorIds } from "cudoc-remark";
34
+ export type { HostPluginOptions, PromoteAnchorIdsOptions } from "cudoc-remark";
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAExE,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAA;AAEtD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,UAAS,sBAA2B,KACnC,aAA+D,CAAA;AAQlE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,MAAM,CAAA;CAC3B,CAAA;AAED;;;;;;GAMG;AACH,QAAA,MAAM,eAAe,QAAO,gBAG1B,CAAA;AAEF,eAAe,eAAe,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,YAAY,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Docusaurus adapter.
3
+ *
4
+ * The anchors have to exist before Docusaurus assigns its own heading ids.
5
+ *
6
+ * The arrangement itself is `createHostPlugins`, shared with the Nextra
7
+ * adapter. What is specific to Docusaurus is the theme below, because this is
8
+ * the host where components are contributed by a plugin rather than named in a
9
+ * config file.
10
+ */
11
+ import path from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import { createHostPlugins } from "cudoc-remark";
14
+ /**
15
+ * The remark plugins to hand to `beforeDefaultRemarkPlugins`.
16
+ *
17
+ * They must run before Docusaurus assigns heading ids in its default plugins.
18
+ */
19
+ export const cudocRemarkPlugins = (options = {}) => createHostPlugins(options, "cudoc-docusaurus");
20
+ const themePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "theme");
21
+ /**
22
+ * The Docusaurus plugin, which contributes nothing but the theme components.
23
+ *
24
+ * cudoc emits capitalized elements, and MDX throws at render time when one is
25
+ * missing. Adding this plugin layers a `MDXComponents` over the site's own so
26
+ * the names resolve without anyone swizzling anything.
27
+ */
28
+ const cudocDocusaurus = () => ({
29
+ name: "cudoc-docusaurus",
30
+ getThemePath: () => themePath,
31
+ });
32
+ export default cudocDocusaurus;
33
+ export { promoteAnchorIds } from "cudoc-remark";
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,iBAAiB,EAA0B,MAAM,cAAc,CAAA;AAIxE;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,UAAkC,EAAE,EACrB,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;AAElE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAC5B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAC5C,IAAI,EACJ,OAAO,CACR,CAAA;AAOD;;;;;;GAMG;AACH,MAAM,eAAe,GAAG,GAAqB,EAAE,CAAC,CAAC;IAC/C,IAAI,EAAE,kBAAkB;IACxB,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS;CAC9B,CAAC,CAAA;AAEF,eAAe,eAAe,CAAA;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "cudoc-docusaurus",
3
+ "version": "0.2.0",
4
+ "description": "Docusaurus adapter for cudoc: remark wiring, default components and a theme that provides them.",
5
+ "keywords": [
6
+ "cudoc",
7
+ "docusaurus",
8
+ "docusaurus-plugin",
9
+ "mdx",
10
+ "documentation"
11
+ ],
12
+ "homepage": "https://github.com/cudoment/cudoc/tree/main/packages/cudoc-docusaurus#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/cudoment/cudoc/issues"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/cudoment/cudoc.git",
19
+ "directory": "packages/cudoc-docusaurus"
20
+ },
21
+ "license": "MIT",
22
+ "author": "cudoment",
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "theme",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "engines": {
40
+ "node": ">=20"
41
+ },
42
+ "scripts": {
43
+ "build": "tsc --build",
44
+ "clean": "rm -rf dist *.tsbuildinfo"
45
+ },
46
+ "dependencies": {
47
+ "cudoc-remark": "0.2.0",
48
+ "unified": "^11.0.5"
49
+ },
50
+ "peerDependencies": {
51
+ "@docusaurus/core": "^3.0.0",
52
+ "react": "^18.0.0 || ^19.0.0"
53
+ }
54
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Layers cudoc's components over the ones the site theme already provides.
3
+ *
4
+ * `@theme-init` rather than `@theme-original`: Docusaurus points
5
+ * `@theme-original/X` at the topmost theme that provides `X`, which for a
6
+ * component contributed by a plugin is this file itself. `@theme-init/X` is the
7
+ * theme that first provided it — the classic theme here — so this is the alias
8
+ * a plugin has to use to wrap a component instead of replacing it.
9
+ *
10
+ * The implementations come from `cudoc-remark`, so all three supported hosts
11
+ * render the same markup. They arrive compiled, which matters here: Docusaurus
12
+ * does not transpile JSX inside `node_modules` unless the path contains
13
+ * "docusaurus".
14
+ */
15
+
16
+ import MDXComponents from "@theme-init/MDXComponents"
17
+ import { cudocComponents } from "cudoc-remark/components"
18
+
19
+ export default {
20
+ ...MDXComponents,
21
+ ...cudocComponents,
22
+ }