cudoc-eleventy 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 +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -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,38 @@
|
|
|
1
|
+
# cudoc-eleventy
|
|
2
|
+
|
|
3
|
+
Connect cudoc to Eleventy while retaining native heading IDs and TOC behavior.
|
|
4
|
+
|
|
5
|
+
ESM · Node.js 20+
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @cudoment/cudoc cudoc-markdown-it cudoc-eleventy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { createMarkdownRenderer } from "cudoc-eleventy"
|
|
13
|
+
import attrs from "markdown-it-attrs"
|
|
14
|
+
import anchor from "markdown-it-anchor"
|
|
15
|
+
|
|
16
|
+
export default function (eleventyConfig) {
|
|
17
|
+
eleventyConfig.setLibrary(
|
|
18
|
+
"md",
|
|
19
|
+
createMarkdownRenderer({ syntax: { headingAnchor: "both" } }, (md) => {
|
|
20
|
+
md.use(attrs, { allowedAttributes: ["id"] })
|
|
21
|
+
md.use(anchor, { permalink: anchor.permalink.linkInsideHeader() })
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
// cudoc reads source positions out of the token stream.
|
|
25
|
+
return { markdownTemplateEngine: false }
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Copy `@cudoment/cudoc/styles.css` into the output and link it from the layout. Eleventy accepts `.md`, not React `.mdx`. `createDocumentCompiler(md)` reuses the configured renderer for collection and replacements. Embedding requires a collected library and prepared data. Set `markdownTemplateEngine: false` so markdown-it receives the file's own text, and insert heading permalinks inside the heading rather than wrapping it. This adapter shares `cudoc-markdown-it` with `cudoc-vitepress` and does not use `cudoc-remark`.
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
- [Usage guide](https://github.com/cudoment/cudoc/tree/main/docs/eleventy.md) · [한국어 가이드](https://github.com/cudoment/cudoc/tree/main/docs/eleventy.ko.md)
|
|
34
|
+
- [Markdown syntax](https://github.com/cudoment/cudoc/tree/main/docs/syntax.md)
|
|
35
|
+
- [Embedding](https://github.com/cudoment/cudoc/tree/main/docs/embedding.md)
|
|
36
|
+
- [Standalone HTML alongside a host](https://github.com/cudoment/cudoc/tree/main/docs/html.md#export-alongside-an-existing-site)
|
|
37
|
+
- [API reference](https://github.com/cudoment/cudoc/tree/main/docs/api-reference/README.md)
|
|
38
|
+
- [Runnable examples](https://github.com/cudoment/cudoc/tree/main/examples/README.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eleventy adapter.
|
|
3
|
+
*
|
|
4
|
+
* The arrangement itself is `installHostPlugin`, shared with the VitePress
|
|
5
|
+
* adapter through `cudoc-markdown-it`, so the two markdown-it hosts cannot
|
|
6
|
+
* quietly diverge. What is specific to Eleventy is described in the host
|
|
7
|
+
* definition below: it passes the page data object as the markdown-it env, and
|
|
8
|
+
* it strips front matter with gray-matter before markdown-it ever sees the
|
|
9
|
+
* source, so collection has to strip it the same way.
|
|
10
|
+
*
|
|
11
|
+
* Eleventy runs Liquid over Markdown before markdown-it by default. cudoc reads
|
|
12
|
+
* source positions out of the token stream, so a site using cudoc must set
|
|
13
|
+
* `markdownTemplateEngine: false`; the plugin raises an error when it detects
|
|
14
|
+
* that the source it received is not the file's own text.
|
|
15
|
+
*/
|
|
16
|
+
import type MarkdownIt from "markdown-it";
|
|
17
|
+
import { type HostPluginOptions } from "cudoc-markdown-it";
|
|
18
|
+
import type { DocumentCompiler } from "@cudoment/cudoc/node/library";
|
|
19
|
+
export type EleventyOptions = HostPluginOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Install on the markdown-it instance handed to `eleventyConfig.setLibrary`.
|
|
22
|
+
*
|
|
23
|
+
* Register the site's own markdown-it plugins first so their tokens already
|
|
24
|
+
* exist when cudoc reads the stream.
|
|
25
|
+
*/
|
|
26
|
+
export default function cudocEleventy(md: MarkdownIt, options?: EleventyOptions): void;
|
|
27
|
+
/**
|
|
28
|
+
* One markdown-it construction for both the Eleventy build and the collector.
|
|
29
|
+
*
|
|
30
|
+
* Eleventy's own defaults are applied first: HTML enabled, and indented code
|
|
31
|
+
* blocks disabled, which is what Eleventy does to every renderer it is given.
|
|
32
|
+
* `configure` receives the instance before cudoc is installed, which is where
|
|
33
|
+
* `markdown-it-attrs` and `markdown-it-container` belong.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createMarkdownRenderer(options?: EleventyOptions, configure?: (md: MarkdownIt) => void): MarkdownIt;
|
|
36
|
+
/** Reuse the very same configured Eleventy renderer for collection and source replacements. */
|
|
37
|
+
export declare function createDocumentCompiler(md: MarkdownIt): DocumentCompiler;
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AAEzC,OAAO,EAGL,KAAK,iBAAiB,EAEvB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAEpE,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAA;AAqC/C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACnC,EAAE,EAAE,UAAU,EACd,OAAO,GAAE,eAAoB,GAC5B,IAAI,CASN;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,GAAE,eAAoB,EAC7B,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,UAAU,KAAK,IAAI,GACnC,UAAU,CAMZ;AAED,+FAA+F;AAC/F,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,UAAU,GAAG,gBAAgB,CAEvE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eleventy adapter.
|
|
3
|
+
*
|
|
4
|
+
* The arrangement itself is `installHostPlugin`, shared with the VitePress
|
|
5
|
+
* adapter through `cudoc-markdown-it`, so the two markdown-it hosts cannot
|
|
6
|
+
* quietly diverge. What is specific to Eleventy is described in the host
|
|
7
|
+
* definition below: it passes the page data object as the markdown-it env, and
|
|
8
|
+
* it strips front matter with gray-matter before markdown-it ever sees the
|
|
9
|
+
* source, so collection has to strip it the same way.
|
|
10
|
+
*
|
|
11
|
+
* Eleventy runs Liquid over Markdown before markdown-it by default. cudoc reads
|
|
12
|
+
* source positions out of the token stream, so a site using cudoc must set
|
|
13
|
+
* `markdownTemplateEngine: false`; the plugin raises an error when it detects
|
|
14
|
+
* that the source it received is not the file's own text.
|
|
15
|
+
*/
|
|
16
|
+
import markdownIt from "markdown-it";
|
|
17
|
+
import matter from "gray-matter";
|
|
18
|
+
import { installHostPlugin, createHostCompiler, } from "cudoc-markdown-it";
|
|
19
|
+
const readPage = (env) => {
|
|
20
|
+
const page = env.page;
|
|
21
|
+
if (typeof page !== "object" || page === null)
|
|
22
|
+
throw new Error('cudoc-eleventy: the markdown-it env carries no Eleventy page data; install the renderer with eleventyConfig.setLibrary("md", md)');
|
|
23
|
+
return page;
|
|
24
|
+
};
|
|
25
|
+
const eleventy = {
|
|
26
|
+
adapter: "cudoc-eleventy",
|
|
27
|
+
host: "eleventy",
|
|
28
|
+
documentId: (env) => {
|
|
29
|
+
const { filePathStem } = readPage(env);
|
|
30
|
+
if (typeof filePathStem !== "string")
|
|
31
|
+
throw new Error("cudoc-eleventy: page.filePathStem is required to identify the collected document");
|
|
32
|
+
return filePathStem.replace(/^\//, "");
|
|
33
|
+
},
|
|
34
|
+
compilerEnv: ({ id, filePath }) => ({
|
|
35
|
+
page: { inputPath: filePath, filePathStem: `/${id}` },
|
|
36
|
+
}),
|
|
37
|
+
frontmatter: (source) => {
|
|
38
|
+
const parsed = matter(source);
|
|
39
|
+
return { body: parsed.content, data: parsed.data };
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Install on the markdown-it instance handed to `eleventyConfig.setLibrary`.
|
|
44
|
+
*
|
|
45
|
+
* Register the site's own markdown-it plugins first so their tokens already
|
|
46
|
+
* exist when cudoc reads the stream.
|
|
47
|
+
*/
|
|
48
|
+
export default function cudocEleventy(md, options = {}) {
|
|
49
|
+
installHostPlugin(md, options, eleventy);
|
|
50
|
+
md.core.ruler.before("cudoc", "cudoc-eleventy-source", (state) => {
|
|
51
|
+
const raw = state.env.page?.rawInput;
|
|
52
|
+
if (typeof raw === "string" && raw !== state.src)
|
|
53
|
+
throw new Error("cudoc-eleventy: another template engine rewrote this Markdown before markdown-it; set markdownTemplateEngine: false");
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One markdown-it construction for both the Eleventy build and the collector.
|
|
58
|
+
*
|
|
59
|
+
* Eleventy's own defaults are applied first: HTML enabled, and indented code
|
|
60
|
+
* blocks disabled, which is what Eleventy does to every renderer it is given.
|
|
61
|
+
* `configure` receives the instance before cudoc is installed, which is where
|
|
62
|
+
* `markdown-it-attrs` and `markdown-it-container` belong.
|
|
63
|
+
*/
|
|
64
|
+
export function createMarkdownRenderer(options = {}, configure) {
|
|
65
|
+
const md = markdownIt({ html: true });
|
|
66
|
+
md.disable("code");
|
|
67
|
+
configure?.(md);
|
|
68
|
+
md.use(cudocEleventy, options);
|
|
69
|
+
return md;
|
|
70
|
+
}
|
|
71
|
+
/** Reuse the very same configured Eleventy renderer for collection and source replacements. */
|
|
72
|
+
export function createDocumentCompiler(md) {
|
|
73
|
+
return createHostCompiler(md, eleventy);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,UAAU,MAAM,aAAa,CAAA;AA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,CAAC,CAAA;IACxC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,uBAAuB,EAAE,CAAC,KAAK,EAAE,EAAE;QAC/D,MAAM,GAAG,GAAI,KAAK,CAAC,GAA+B,CAAC,IAAI,EAAE,QAAQ,CAAA;QACjE,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,KAAK,CAAC,GAAG;YAC9C,MAAM,IAAI,KAAK,CACb,qHAAqH,CACtH,CAAA;IACL,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAA2B,EAAE,EAC7B,SAAoC;IAEpC,MAAM,EAAE,GAAG,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;IACrC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAClB,SAAS,EAAE,CAAC,EAAE,CAAC,CAAA;IACf,EAAE,CAAC,GAAG,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAC9B,OAAO,EAAE,CAAA;AACX,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,sBAAsB,CAAC,EAAc;IACnD,OAAO,kBAAkB,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAA;AACzC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cudoc-eleventy",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Eleventy Markdown integration for cudoc",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/cudoment/cudoc.git",
|
|
9
|
+
"directory": "packages/cudoc-eleventy"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/cudoment/cudoc/tree/main/packages/cudoc-eleventy#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/cudoment/cudoc/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"cudoc",
|
|
17
|
+
"eleventy",
|
|
18
|
+
"11ty",
|
|
19
|
+
"markdown",
|
|
20
|
+
"documentation"
|
|
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
|
+
"cudoc-markdown-it": "0.3.0",
|
|
46
|
+
"gray-matter": "^4.0.3"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@11ty/eleventy": "^3.0.0",
|
|
50
|
+
"markdown-it": "^14.1.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/markdown-it": "^14.2.0"
|
|
54
|
+
},
|
|
55
|
+
"author": "cudoment",
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=20"
|
|
58
|
+
}
|
|
59
|
+
}
|