@altano/remark-mdx-toc-with-slugs 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -5
- package/dist/index.js +5 -10
- package/dist/index.js.map +1 -1
- package/package.json +21 -18
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RemarkMdxTocOptions, TocEntry } from "@altano/remark-mdx-toc";
|
|
2
2
|
import { Plugin } from "unified";
|
|
3
|
-
|
|
4
3
|
//#region src/index.d.ts
|
|
5
4
|
type TableOfContentsEntry = TocEntry & {
|
|
6
5
|
slug: string;
|
|
@@ -8,10 +7,10 @@ type TableOfContentsEntry = TocEntry & {
|
|
|
8
7
|
};
|
|
9
8
|
type RemarkMdxTocWithSlugsOptions = RemarkMdxTocOptions;
|
|
10
9
|
/**
|
|
11
|
-
* Remark plugin that, given a tree that has had remark-mdx-toc run over it
|
|
12
|
-
* already, the toc data will be enhanced to have auto-generated slugs for every
|
|
13
|
-
* heading. This uses github-slugger
|
|
14
|
-
*/
|
|
10
|
+
* Remark plugin that, given a tree that has had remark-mdx-toc run over it
|
|
11
|
+
* already, the toc data will be enhanced to have auto-generated slugs for every
|
|
12
|
+
* heading. This uses github-slugger
|
|
13
|
+
*/
|
|
15
14
|
declare const remarkMdxTocWithSlugs: Plugin<[RemarkMdxTocWithSlugsOptions?]>;
|
|
16
15
|
//#endregion
|
|
17
16
|
export { RemarkMdxTocWithSlugsOptions, TableOfContentsEntry, remarkMdxTocWithSlugs as default };
|
package/dist/index.js
CHANGED
|
@@ -28,28 +28,23 @@ const remarkMdxTocWithSlugs = function(options = {}) {
|
|
|
28
28
|
const mdxTocTransformer = remarkMdxToc.call(this, options);
|
|
29
29
|
const name = options.name ?? "toc";
|
|
30
30
|
return function mdxTocWithSlugsTransformer(ast, ...args) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const mdast = ast;
|
|
34
|
-
visit$1(mdast, ["mdxjsEsm"], (mdxNode) => {
|
|
31
|
+
if (mdxTocTransformer(ast, ...args) instanceof Promise) throw new Error(`Wasn't expected remark-mdx-toc to be an async plugin`);
|
|
32
|
+
visit$1(ast, ["mdxjsEsm"], (mdxNode) => {
|
|
35
33
|
assertMdxjsEsmNode(mdxNode);
|
|
36
34
|
const estree = mdxNode.data?.estree;
|
|
37
35
|
if (estree) visit(estree, (esNode) => {
|
|
38
36
|
if (esNode.type === "VariableDeclarator" && esNode.id.type === "Identifier" && esNode.id.name === name && esNode.init) {
|
|
39
37
|
const tocExportString = generate(esNode.init);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const newTree = valueToEstree(tocWithSlugs);
|
|
38
|
+
const newTree = valueToEstree(sluggifyTocEntries(JSON.parse(tocExportString)));
|
|
39
|
+
/* v8 ignore if */
|
|
43
40
|
if (newTree.type === "ArrayExpression") esNode.init = newTree;
|
|
44
41
|
return EXIT;
|
|
45
42
|
}
|
|
46
|
-
return;
|
|
47
43
|
});
|
|
48
44
|
});
|
|
49
45
|
};
|
|
50
46
|
};
|
|
51
|
-
var src_default = remarkMdxTocWithSlugs;
|
|
52
47
|
|
|
53
48
|
//#endregion
|
|
54
|
-
export {
|
|
49
|
+
export { remarkMdxTocWithSlugs as default };
|
|
55
50
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["mdast"],"sources":["../src/index.ts"],"sourcesContent":["import { generate } from \"astring\";\nimport { valueToEstree } from \"estree-util-value-to-estree\";\nimport { EXIT, visit as estreeVisit } from \"estree-util-visit\";\nimport GithubSlugger from \"github-slugger\";\nimport remarkMdxToc from \"@altano/remark-mdx-toc\";\nimport { visit } from \"unist-util-visit\";\n\nimport type { RemarkMdxTocOptions, TocEntry } from \"@altano/remark-mdx-toc\";\nimport type { Plugin, Processor } from \"unified\";\nimport type { MdxjsEsm } from \"mdast-util-mdxjs-esm\";\nimport type { Node } from \"unist\";\n\nexport type TableOfContentsEntry = TocEntry & {\n slug: string;\n children: TableOfContentsEntry[];\n};\n\nfunction sluggifyTocEntries(\n entries: TocEntry[],\n headingSlugger = new GithubSlugger(),\n): TableOfContentsEntry[] {\n return entries.map((entry) => sluggifyTocEntry(entry, headingSlugger));\n}\n\nfunction sluggifyTocEntry(\n entry: TocEntry,\n headingSlugger: GithubSlugger,\n): TableOfContentsEntry {\n return {\n ...entry,\n slug: headingSlugger.slug(entry.value),\n children: sluggifyTocEntries(entry.children, headingSlugger),\n };\n}\n\nexport type RemarkMdxTocWithSlugsOptions = RemarkMdxTocOptions;\n\nfunction assertMdxjsEsmNode(node: Node): asserts node is MdxjsEsm {\n if (node.type !== \"mdxjsEsm\") {\n throw new Error(`Node was unexpected type: ${node.type}`);\n }\n}\n\n/**\n * Remark plugin that, given a tree that has had remark-mdx-toc run over it\n * already, the toc data will be enhanced to have auto-generated slugs for every\n * heading. This uses github-slugger\n */\nconst remarkMdxTocWithSlugs: Plugin<[RemarkMdxTocWithSlugsOptions?]> =\n function (this: Processor, options = {}) {\n const mdxTocTransformer = remarkMdxToc.call(this, options);\n\n const name = options.name ?? \"toc\"; // mirrors remark-mdx-toc\n\n return function mdxTocWithSlugsTransformer(ast, ...args): void {\n // Delegate to remark-mdx-toc to create the table of contents\n const result = mdxTocTransformer(ast, ...args);\n if (result instanceof Promise) {\n throw new Error(`Wasn't expected remark-mdx-toc to be an async plugin`);\n }\n\n const mdast = ast;\n\n // visit all esm nodes in the mdx\n visit(mdast, [\"mdxjsEsm\"], (mdxNode) => {\n assertMdxjsEsmNode(mdxNode);\n // visit all nodes in the estree\n const estree = mdxNode.data?.estree;\n if (estree) {\n estreeVisit(estree, (esNode) => {\n if (\n esNode.type === \"VariableDeclarator\" &&\n esNode.id.type === \"Identifier\" &&\n esNode.id.name === name &&\n esNode.init\n ) {\n // we found the \"toc\" variable declarator\n\n // It's easier to be wasteful and do our transformations in JS,\n // instead of directly on the tree, and then convert it back to a\n // tree.\n const tocExportString = generate(esNode.init);\n const toc = JSON.parse(tocExportString) as TocEntry[];\n\n // Add slugs to the toc\n const tocWithSlugs = sluggifyTocEntries(toc);\n\n // Overwrite the existing toc export with ours\n const newTree = valueToEstree(tocWithSlugs);\n\n /* v8 ignore if */\n if (newTree.type === \"ArrayExpression\") {\n esNode.init = newTree;\n }\n\n // We out\n return EXIT;\n }\n\n return;\n });\n }\n });\n };\n };\n\nexport default remarkMdxTocWithSlugs;\n"],"mappings":";;;;;;;;AAiBA,SAAS,mBACP,SACA,iBAAiB,IAAI,cAAc,GACX;CACxB,OAAO,QAAQ,KAAK,UAAU,iBAAiB,OAAO,cAAc,CAAC;AACvE;AAEA,SAAS,iBACP,OACA,gBACsB;CACtB,OAAO;EACL,GAAG;EACH,MAAM,eAAe,KAAK,MAAM,KAAK;EACrC,UAAU,mBAAmB,MAAM,UAAU,cAAc;CAC7D;AACF;AAIA,SAAS,mBAAmB,MAAsC;CAChE,IAAI,KAAK,SAAS,YAChB,MAAM,IAAI,MAAM,6BAA6B,KAAK,MAAM;AAE5D;;;;;;AAOA,MAAM,wBACJ,SAA2B,UAAU,CAAC,GAAG;CACvC,MAAM,oBAAoB,aAAa,KAAK,MAAM,OAAO;CAEzD,MAAM,OAAO,QAAQ,QAAQ;CAE7B,OAAO,SAAS,2BAA2B,KAAK,GAAG,MAAY;EAG7D,IADe,kBAAkB,KAAK,GAAG,IAChC,aAAa,SACpB,MAAM,IAAI,MAAM,sDAAsD;EAMxE,QAAMA,KAAO,CAAC,UAAU,IAAI,YAAY;GACtC,mBAAmB,OAAO;GAE1B,MAAM,SAAS,QAAQ,MAAM;GAC7B,IAAI,QACF,MAAY,SAAS,WAAW;IAC9B,IACE,OAAO,SAAS,wBAChB,OAAO,GAAG,SAAS,gBACnB,OAAO,GAAG,SAAS,QACnB,OAAO,MACP;KAMA,MAAM,kBAAkB,SAAS,OAAO,IAAI;KAO5C,MAAM,UAAU,cAHK,mBAHT,KAAK,MAAM,eAGmB,CAGD,CAAC;;KAG1C,IAAI,QAAQ,SAAS,mBACnB,OAAO,OAAO;KAIhB,OAAO;IACT;GAGF,CAAC;EAEL,CAAC;CACH;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/remark-mdx-toc-with-slugs",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "A remark plugin to generate a table of contents (including slugs) and convert it into MDX export",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mdx",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Alan Norbauer",
|
|
21
|
-
"email": "
|
|
21
|
+
"email": "alan@norbauer.com",
|
|
22
22
|
"url": "https://alan.norbauer.com"
|
|
23
23
|
},
|
|
24
24
|
"sideEffects": false,
|
|
@@ -32,43 +32,46 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"astring": "^1.9.0",
|
|
35
|
-
"estree-util-value-to-estree": "^3.
|
|
35
|
+
"estree-util-value-to-estree": "^3.5.0",
|
|
36
36
|
"estree-util-visit": "^2.0.0",
|
|
37
37
|
"github-slugger": "^2.0.0",
|
|
38
38
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
39
39
|
"unified": "^11.0.5",
|
|
40
|
-
"unist-util-visit": "^5.
|
|
41
|
-
"@altano/remark-mdx-toc": "1.0.
|
|
40
|
+
"unist-util-visit": "^5.1.0",
|
|
41
|
+
"@altano/remark-mdx-toc": "1.0.3"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@arethetypeswrong/cli": "^0.
|
|
45
|
-
"@types/node": "^
|
|
44
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
45
|
+
"@types/node": "^26.1.1",
|
|
46
46
|
"@types/unist": "^3.0.3",
|
|
47
|
-
"@vitest/coverage-v8": "^
|
|
47
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
48
48
|
"depcheck": "^1.4.7",
|
|
49
|
-
"prettier": "
|
|
50
|
-
"tsdown": "^0.
|
|
51
|
-
"typescript": "^
|
|
52
|
-
"vite": "^
|
|
53
|
-
"vitest": "^
|
|
49
|
+
"prettier": "3.9.6",
|
|
50
|
+
"tsdown": "^0.22.13",
|
|
51
|
+
"typescript": "^6.0.3",
|
|
52
|
+
"vite": "^8.1.5",
|
|
53
|
+
"vitest": "^4.1.10",
|
|
54
54
|
"@altano/build-config": "0.0.1",
|
|
55
55
|
"@altano/remark-plugin-test-util": "0.0.1",
|
|
56
|
-
"@altano/
|
|
57
|
-
"@altano/
|
|
56
|
+
"@altano/tsconfig": "0.0.1",
|
|
57
|
+
"@altano/testing": "0.0.1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"@types/unist": "3.x.x"
|
|
58
61
|
},
|
|
59
62
|
"publishConfig": {
|
|
60
63
|
"access": "public"
|
|
61
64
|
},
|
|
62
65
|
"scripts": {
|
|
63
|
-
"build": "tsdown
|
|
66
|
+
"build": "tsdown",
|
|
64
67
|
"check:exports": "attw --pack . --profile esm-only --quiet",
|
|
65
68
|
"check:types:src": "tsc --noEmit",
|
|
66
69
|
"check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
|
|
67
70
|
"check:unused-dependencies": "depcheck",
|
|
68
71
|
"clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
|
|
69
72
|
"dev": "pnpm run build --watch",
|
|
70
|
-
"format": "prettier --check
|
|
71
|
-
"format:fix": "prettier --write
|
|
73
|
+
"format": "prettier --check .",
|
|
74
|
+
"format:fix": "prettier --write .",
|
|
72
75
|
"lint": "eslint",
|
|
73
76
|
"lint:fix": "TIMING=1 pnpm lint --fix",
|
|
74
77
|
"lint:timing": "TIMING=1 pnpm lint",
|