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