@altano/remark-mdx-toc-with-slugs 1.0.0 → 1.0.2
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/README.md +22 -29
- package/dist/index.d.ts +12 -6
- package/dist/index.js +11 -6
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -1,40 +1,29 @@
|
|
|
1
1
|
# remark-mdx-toc-with-slugs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Summary
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This is a [remark](https://remark.js.org/) plugin that exports a table of contents. It is similar to the [remark-mdx-toc](https://github.com/DCsunset/remark-mdx-toc) plugin but has an additional `slug` property.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
attributes: {},
|
|
18
|
-
children: [],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
depth: 3,
|
|
22
|
-
value: "C++ Classes",
|
|
23
|
-
attributes: {},
|
|
24
|
-
children: [],
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
];
|
|
7
|
+
Given this mdx:
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## Resource Acquisition Is Initialization (RAII)
|
|
11
|
+
|
|
12
|
+
### Is There a Problem?
|
|
13
|
+
|
|
14
|
+
### C++ Classes
|
|
15
|
+
|
|
16
|
+
### The Solution
|
|
29
17
|
```
|
|
30
18
|
|
|
31
|
-
|
|
19
|
+
`remark-mdx-toc-with-slugs` exports this object on the `toc` field:
|
|
32
20
|
|
|
33
21
|
```javascript
|
|
34
|
-
[
|
|
22
|
+
export const toc = [
|
|
35
23
|
{
|
|
36
24
|
depth: 2,
|
|
37
25
|
value: "Resource Acquisition Is Initialization (RAII)",
|
|
26
|
+
slug: "resource-acquisition-is-initialization-raii",
|
|
38
27
|
attributes: {},
|
|
39
28
|
children: [
|
|
40
29
|
{
|
|
@@ -59,11 +48,15 @@ And `remark-mdx-toc-with-slugs` modifies it to export this instead:
|
|
|
59
48
|
slug: "the-solution",
|
|
60
49
|
},
|
|
61
50
|
],
|
|
62
|
-
slug: "resource-acquisition-is-initialization-raii",
|
|
63
51
|
},
|
|
64
52
|
];
|
|
65
53
|
```
|
|
66
54
|
|
|
67
|
-
|
|
55
|
+
## Options
|
|
56
|
+
|
|
57
|
+
- `name`: The exported variable name of the table of contents. By default, it's `toc`.
|
|
58
|
+
|
|
59
|
+
## Misc
|
|
68
60
|
|
|
69
|
-
|
|
61
|
+
- If you don't need the slug, consider using [remark-mdx-toc](https://github.com/DCsunset/remark-mdx-toc).
|
|
62
|
+
- Slugs are generated using [`github-slugger`](https://www.npmjs.com/package/github-slugger) and should therefore match the [`rehype-slug`](https://www.npmjs.com/package/rehype-slug) package
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RemarkMdxTocOptions } from 'remark-mdx-toc';
|
|
1
|
+
import { TocEntry, RemarkMdxTocOptions } from 'remark-mdx-toc';
|
|
3
2
|
import { Plugin } from 'unified';
|
|
4
3
|
|
|
5
|
-
declare type
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
declare type TableOfContentsEntry = TocEntry & {
|
|
5
|
+
slug: string;
|
|
6
|
+
children: TableOfContentsEntry[];
|
|
8
7
|
};
|
|
8
|
+
declare type RemarkMdxTocWithSlugsOptions = RemarkMdxTocOptions;
|
|
9
|
+
/**
|
|
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
|
+
*/
|
|
14
|
+
declare const remarkMdxTocWithSlugs: Plugin<[RemarkMdxTocWithSlugsOptions?]>;
|
|
9
15
|
|
|
10
|
-
export { RemarkMdxTocWithSlugsOptions,
|
|
16
|
+
export { RemarkMdxTocWithSlugsOptions, TableOfContentsEntry, remarkMdxTocWithSlugs as default };
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,17 @@ function assertMdxjsEsmNode(node) {
|
|
|
20
20
|
throw new Error(`Node was unexpected type: ${node.type}`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
var remarkMdxTocWithSlugs = (options = {})
|
|
23
|
+
var remarkMdxTocWithSlugs = function(options = {}) {
|
|
24
|
+
const mdxTocTransformer = remarkMdxToc.call(this, options);
|
|
25
|
+
if (mdxTocTransformer == null) {
|
|
26
|
+
throw new Error(`Couldn't create mdxTocTransformer function`);
|
|
27
|
+
}
|
|
24
28
|
const name = options.name ?? "toc";
|
|
25
|
-
return function mdxTocWithSlugsTransformer(ast) {
|
|
29
|
+
return function mdxTocWithSlugsTransformer(ast, ...args) {
|
|
30
|
+
const result = mdxTocTransformer(ast, ...args);
|
|
31
|
+
if (result instanceof Promise) {
|
|
32
|
+
throw new Error(`Wasn't expected remark-mdx-toc to be an async plugin`);
|
|
33
|
+
}
|
|
26
34
|
const mdast = ast;
|
|
27
35
|
visit(mdast, ["mdxjsEsm"], (mdxNode) => {
|
|
28
36
|
assertMdxjsEsmNode(mdxNode);
|
|
@@ -45,10 +53,7 @@ var remarkMdxTocWithSlugs = (options = {}) => {
|
|
|
45
53
|
});
|
|
46
54
|
};
|
|
47
55
|
};
|
|
48
|
-
var
|
|
49
|
-
plugins: [remarkMdxToc, remarkMdxTocWithSlugs]
|
|
50
|
-
};
|
|
51
|
-
var src_default = preset;
|
|
56
|
+
var src_default = remarkMdxTocWithSlugs;
|
|
52
57
|
export {
|
|
53
58
|
src_default as default
|
|
54
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/remark-mdx-toc-with-slugs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A remark plugin to generate a table of contents (including slugs) and convert it into MDX export",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"dev": "tsup src/index.ts --watch --format esm --dts",
|
|
12
12
|
"lint": "TIMING=1 eslint src/**/*.ts* --fix",
|
|
13
13
|
"format": "prettier --write src",
|
|
14
|
-
"clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist"
|
|
14
|
+
"clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
|
|
15
|
+
"test": "vitest --run",
|
|
16
|
+
"test:watch": "vitest"
|
|
15
17
|
},
|
|
16
18
|
"author": {
|
|
17
19
|
"name": "Alan Norbauer",
|
|
@@ -30,6 +32,7 @@
|
|
|
30
32
|
],
|
|
31
33
|
"keywords": [
|
|
32
34
|
"remark",
|
|
35
|
+
"remark-plugin",
|
|
33
36
|
"mdx"
|
|
34
37
|
],
|
|
35
38
|
"dependencies": {
|
|
@@ -42,8 +45,10 @@
|
|
|
42
45
|
"unist-util-visit": "^4.1.2"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
48
|
+
"@altano/remark-plugin-test-util": "*",
|
|
45
49
|
"@altano/tsconfig": "*",
|
|
46
|
-
"@types/node": "^18.15.13"
|
|
50
|
+
"@types/node": "^18.15.13",
|
|
51
|
+
"vitest": "^0.30.1"
|
|
47
52
|
},
|
|
48
53
|
"publishConfig": {
|
|
49
54
|
"access": "public"
|