@altano/remark-mdx-toc-with-slugs 3.0.1 → 4.0.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/dist/index.d.ts +15 -11
- package/dist/index.js +42 -42
- package/package.json +16 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { RemarkMdxTocOptions, TocEntry } from "@altano/remark-mdx-toc";
|
|
2
|
+
import { Plugin } from "unified";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
type TableOfContentsEntry = TocEntry & {
|
|
6
|
+
slug: string;
|
|
7
|
+
children: TableOfContentsEntry[];
|
|
6
8
|
};
|
|
7
|
-
|
|
9
|
+
type RemarkMdxTocWithSlugsOptions = RemarkMdxTocOptions;
|
|
8
10
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
*/
|
|
13
15
|
declare const remarkMdxTocWithSlugs: Plugin<[RemarkMdxTocWithSlugsOptions?]>;
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { RemarkMdxTocWithSlugsOptions, TableOfContentsEntry, remarkMdxTocWithSlugs as default };
|
|
15
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { generate } from "astring";
|
|
2
2
|
import { valueToEstree } from "estree-util-value-to-estree";
|
|
3
|
-
import { EXIT, visit
|
|
3
|
+
import { EXIT, visit } from "estree-util-visit";
|
|
4
4
|
import GithubSlugger from "github-slugger";
|
|
5
5
|
import remarkMdxToc from "@altano/remark-mdx-toc";
|
|
6
|
-
import { visit } from "unist-util-visit";
|
|
6
|
+
import { visit as visit$1 } from "unist-util-visit";
|
|
7
|
+
|
|
8
|
+
//#region src/index.ts
|
|
7
9
|
function sluggifyTocEntries(entries, headingSlugger = new GithubSlugger()) {
|
|
8
|
-
|
|
10
|
+
return entries.map((entry) => sluggifyTocEntry(entry, headingSlugger));
|
|
9
11
|
}
|
|
10
12
|
function sluggifyTocEntry(entry, headingSlugger) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
return {
|
|
14
|
+
...entry,
|
|
15
|
+
slug: headingSlugger.slug(entry.value),
|
|
16
|
+
children: sluggifyTocEntries(entry.children, headingSlugger)
|
|
17
|
+
};
|
|
16
18
|
}
|
|
17
19
|
function assertMdxjsEsmNode(node) {
|
|
18
|
-
|
|
19
|
-
throw new Error(`Node was unexpected type: ${node.type}`);
|
|
20
|
-
}
|
|
20
|
+
if (node.type !== "mdxjsEsm") throw new Error(`Node was unexpected type: ${node.type}`);
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Remark plugin that, given a tree that has had remark-mdx-toc run over it
|
|
24
|
+
* already, the toc data will be enhanced to have auto-generated slugs for every
|
|
25
|
+
* heading. This uses github-slugger
|
|
26
|
+
*/
|
|
22
27
|
const remarkMdxTocWithSlugs = function(options = {}) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
};
|
|
28
|
+
const mdxTocTransformer = remarkMdxToc.call(this, options);
|
|
29
|
+
const name = options.name ?? "toc";
|
|
30
|
+
return function mdxTocWithSlugsTransformer(ast, ...args) {
|
|
31
|
+
const result = mdxTocTransformer(ast, ...args);
|
|
32
|
+
if (result instanceof Promise) throw new Error(`Wasn't expected remark-mdx-toc to be an async plugin`);
|
|
33
|
+
const mdast = ast;
|
|
34
|
+
visit$1(mdast, ["mdxjsEsm"], (mdxNode) => {
|
|
35
|
+
assertMdxjsEsmNode(mdxNode);
|
|
36
|
+
const estree = mdxNode.data?.estree;
|
|
37
|
+
if (estree) visit(estree, (esNode) => {
|
|
38
|
+
if (esNode.type === "VariableDeclarator" && esNode.id.type === "Identifier" && esNode.id.name === name && esNode.init) {
|
|
39
|
+
const tocExportString = generate(esNode.init);
|
|
40
|
+
const toc = JSON.parse(tocExportString);
|
|
41
|
+
const tocWithSlugs = sluggifyTocEntries(toc);
|
|
42
|
+
const newTree = valueToEstree(tocWithSlugs);
|
|
43
|
+
if (newTree.type === "ArrayExpression") esNode.init = newTree;
|
|
44
|
+
return EXIT;
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
};
|
|
51
50
|
};
|
|
52
51
|
var src_default = remarkMdxTocWithSlugs;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { src_default as default };
|
|
55
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/remark-mdx-toc-with-slugs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
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",
|
|
@@ -31,37 +31,36 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"astring": "^1.9.0",
|
|
34
|
-
"estree-util-value-to-estree": "^3.
|
|
34
|
+
"estree-util-value-to-estree": "^3.3.3",
|
|
35
35
|
"estree-util-visit": "^2.0.0",
|
|
36
36
|
"github-slugger": "^2.0.0",
|
|
37
37
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
38
38
|
"unified": "^11.0.5",
|
|
39
39
|
"unist-util-visit": "^5.0.0",
|
|
40
|
-
"@altano/remark-mdx-toc": "0.0
|
|
40
|
+
"@altano/remark-mdx-toc": "1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@arethetypeswrong/cli": "^0.
|
|
43
|
+
"@arethetypeswrong/cli": "^0.17.4",
|
|
44
44
|
"@types/node": "^22.13.10",
|
|
45
|
-
"@types/unist": "^3.0.
|
|
46
|
-
"@vitest/coverage-v8": "^3.
|
|
45
|
+
"@types/unist": "^3.0.3",
|
|
46
|
+
"@vitest/coverage-v8": "^3.1.4",
|
|
47
47
|
"depcheck": "^1.4.7",
|
|
48
|
-
"prettier": "^3.
|
|
48
|
+
"prettier": "^3.5.3",
|
|
49
|
+
"tsdown": "^0.12.3",
|
|
49
50
|
"typescript": "^5.8.2",
|
|
50
|
-
"vite": "^6.2.
|
|
51
|
-
"vitest": "^3.
|
|
52
|
-
"@altano/build-config": "0.0.
|
|
53
|
-
"@altano/remark-plugin-test-util": "0.0.
|
|
54
|
-
"@altano/testing": "0.0.
|
|
55
|
-
"@altano/tsconfig": "0.0.
|
|
56
|
-
"@altano/vitest-plugins": "1.0.0"
|
|
51
|
+
"vite": "^6.2.6",
|
|
52
|
+
"vitest": "^3.1.4",
|
|
53
|
+
"@altano/build-config": "0.0.1",
|
|
54
|
+
"@altano/remark-plugin-test-util": "0.0.1",
|
|
55
|
+
"@altano/testing": "0.0.1",
|
|
56
|
+
"@altano/tsconfig": "0.0.1"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
|
-
"build": "
|
|
63
|
-
"
|
|
64
|
-
"check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
62
|
+
"build": "tsdown --config ../build-config/tsdown.config.browser.ts",
|
|
63
|
+
"check:exports": "attw --pack . --profile esm-only --quiet",
|
|
65
64
|
"check:types:src": "tsc --noEmit",
|
|
66
65
|
"check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
|
|
67
66
|
"check:unused-dependencies": "depcheck",
|