remark-flexible-toc 1.2.0 → 1.2.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 CHANGED
@@ -12,11 +12,11 @@ This package is a [**unified**][unified] ([**remark**][remark]) plugin **to expo
12
12
 
13
13
  [**unified**][unified] is a project that transforms content with abstract syntax trees (ASTs) using the new parser [**micromark**][micromark]. [**remark**][remark] adds support for markdown to unified. [**mdast**][mdast] is the Markdown Abstract Syntax Tree (AST) which is a specification for representing markdown in a syntax tree.
14
14
 
15
- **This plugin is a remark plugin that doesn't transform the mdast but gets info from the mdast.**
15
+ **This plugin is a remark plugin that doesn't transform the MDAST but gets info from the MDAST.**
16
16
 
17
17
  ## When should I use this?
18
18
 
19
- This plugin `remark-flexible-toc` is useful if you want to get the table of contents (TOC) from the markdown/MDX document. The `remark-flexible-toc` exposes the table of contents (TOC) in two ways:
19
+ **`remark-flexible-toc`** is useful if you want to get the table of contents (TOC) from the markdown/MDX document. It exposes the table of contents (TOC) in two ways:
20
20
  + by adding the `toc` into the `Vfile.data`
21
21
  + by mutating a reference array if provided in the options
22
22
 
@@ -48,6 +48,34 @@ Say we have the following file, `example.md`, which consists some headings.
48
48
  ### Subheading 2
49
49
  ```
50
50
 
51
+ #### the first way of getting TOC via file.data
52
+
53
+ And our module, `example.js`, looks as follows:
54
+
55
+ ```javascript
56
+ import { read } from "to-vfile";
57
+ import remark from "remark";
58
+ import gfm from "remark-gfm";
59
+ import remarkRehype from "remark-rehype";
60
+ import rehypeStringify from "rehype-stringify";
61
+ import remarkFlexibleToc from "remark-flexible-toc";
62
+
63
+ main();
64
+
65
+ async function main() {
66
+ const file = await remark()
67
+ .use(gfm)
68
+ .use(remarkFlexibleToc)
69
+ .use(remarkRehype)
70
+ .use(rehypeStringify)
71
+ .process(await read("example.md"));
72
+
73
+ console.log(file.data.toc);
74
+ }
75
+ ```
76
+
77
+ #### the second way of getting TOC via a reference array in the options
78
+
51
79
  And our module, `example.js`, looks as follows:
52
80
 
53
81
  ```javascript
@@ -70,15 +98,11 @@ async function main() {
70
98
  .use(rehypeStringify)
71
99
  .process(await read("example.md"));
72
100
 
73
- // the first way of getting TOC via file.data
74
- console.log(file.data.toc);
75
-
76
- // the second way of getting TOC, since we provided a reference array in the options
77
101
  console.log(toc);
78
102
  }
79
103
  ```
80
104
 
81
- Now, running `node example.js` you see that the same table of contents is logged in the console:
105
+ Now, running both `node example.js` you will see that the same table of contents (TOC) is logged in the console:
82
106
 
83
107
  ```javascript
84
108
  [
@@ -106,7 +130,7 @@ Now, running `node example.js` you see that the same table of contents is logged
106
130
  ]
107
131
  ```
108
132
 
109
- Without `remark-flexible-toc`, there wouldn't be any `toc` key in the `file.data`:
133
+ Without **`remark-flexible-toc`**, there wouldn't be any `toc` key in the `file.data`:
110
134
 
111
135
  ## Options
112
136
 
@@ -150,7 +174,7 @@ Now, the TOC is accessable via `vfile.data.headings`.
150
174
 
151
175
  #### `tocRef`
152
176
 
153
- It is an **array of reference** option for getting the table of contents (TOC), which is the second way of getting the TOC from the `remark-flexible-toc`.
177
+ It is an **array of reference** option for getting the table of contents (TOC), which is the second way of getting the TOC from **`remark-flexible-toc`**.
154
178
 
155
179
  The reference array should be an empty array, if not, it is emptied by the plugin.
156
180
 
@@ -262,9 +286,9 @@ type TocItem = {
262
286
  ```
263
287
 
264
288
  > [!NOTE]
265
- > If there is a remark plugin before the `remark-flexible-toc` in the plugin chain, which provides custom id for headings like `remark-heading-id`, that custom id takes precedence for `href`.
289
+ > If there is a remark plugin before **`remark-flexible-toc`** in the plugin chain, which provides custom id for headings like **`remark-heading-id`**, that custom id takes precedence for `href`.
266
290
 
267
- The `remark-flexible-toc` uses the `github-slugger` internally for producing unique links. Then, it is possible you to use [**rehype-slug**][rehype-slug] (forIDs on headings) and [**rehype-autolink-headings**][rehype-autolink-headings] (for anchors that link-to-self) because they use the same `github-slugger`.
291
+ **`remark-flexible-toc`** uses the **`github-slugger`** internally for producing unique links. Then, it is possible you to use [**rehype-slug**][rehype-slug] (forIDs on headings) and [**rehype-autolink-headings**][rehype-autolink-headings] (for anchors that link-to-self) because they use the same **`github-slugger`**.
268
292
 
269
293
  As an example for the unique heading links (notice the same heading texts).
270
294
 
@@ -317,7 +341,7 @@ The `github-slugger` produces unique links with using a counter mechanism intern
317
341
 
318
342
  ## Numbering for Ordered Table of Contents (TOC)
319
343
 
320
- The `remark-flexible-toc` produces always the `numbering` for TOC items in case you show the ordered TOC.
344
+ **`remark-flexible-toc`** produces always the `numbering` for TOC items in case you show the ordered TOC.
321
345
 
322
346
  The **numbering** of a TOC item is an array of number. The numbers in the `numbering` corresponds the **level of the headers**. With that structure, you know which header is under which header.
323
347
 
@@ -360,7 +384,7 @@ This plugin works with `unified` version 6+ and `remark` version 7+. It is compa
360
384
 
361
385
  ## Security
362
386
 
363
- Use of `remark-flexible-toc` does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.
387
+ Use of **`remark-flexible-toc`** does not involve rehype (hast) or user content so there are no openings for cross-site scripting (XSS) attacks.
364
388
 
365
389
  ## My Plugins
366
390
 
@@ -1 +1 @@
1
- {"root":["../../src/index.ts"],"version":"5.8.3"}
1
+ {"root":["../../src/index.ts"],"version":"5.9.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-flexible-toc",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Remark plugin to expose the table of contents via Vfile.data or via an option reference",
5
5
  "type": "module",
6
6
  "exports": "./dist/esm/index.js",
@@ -48,29 +48,29 @@
48
48
  "url": "https://github.com/ipikuka/remark-flexible-toc/issues"
49
49
  },
50
50
  "devDependencies": {
51
- "@eslint/js": "^9.28.0",
52
- "@types/node": "^22.15.29",
51
+ "@eslint/js": "^9.35.0",
52
+ "@types/node": "^24.3.1",
53
53
  "@types/remark-heading-id": "^1.0.0",
54
- "@vitest/coverage-v8": "^3.2.1",
55
- "@vitest/eslint-plugin": "^1.2.1",
56
- "dedent": "^1.6.0",
57
- "eslint": "^9.28.0",
58
- "eslint-config-prettier": "^10.1.5",
59
- "eslint-plugin-prettier": "^5.4.1",
60
- "globals": "^16.2.0",
61
- "prettier": "^3.5.3",
54
+ "@vitest/coverage-v8": "^3.2.4",
55
+ "@vitest/eslint-plugin": "^1.3.9",
56
+ "dedent": "^1.7.0",
57
+ "eslint": "^9.35.0",
58
+ "eslint-config-prettier": "^10.1.8",
59
+ "eslint-plugin-prettier": "^5.5.4",
60
+ "globals": "^16.3.0",
61
+ "prettier": "^3.6.2",
62
62
  "rehype-format": "^5.0.1",
63
63
  "rehype-stringify": "^10.0.1",
64
64
  "remark-gfm": "^4.0.1",
65
65
  "remark-heading-id": "^1.0.1",
66
66
  "remark-parse": "^11.0.0",
67
67
  "remark-rehype": "^11.1.2",
68
- "rimraf": "^5.0.10",
68
+ "rimraf": "^6.0.1",
69
69
  "type-coverage": "^2.29.7",
70
- "typescript": "^5.8.3",
71
- "typescript-eslint": "^8.33.1",
70
+ "typescript": "^5.9.2",
71
+ "typescript-eslint": "^8.43.0",
72
72
  "unified": "^11.0.5",
73
- "vitest": "^3.2.1"
73
+ "vitest": "^3.2.4"
74
74
  },
75
75
  "dependencies": {
76
76
  "@types/mdast": "^4.0.4",