1
- # rehype-slug
1
+ # rehype-slug-custom-id
2
2
3
3
[ ![ Build] [ build-badge ]] [ build ]
4
4
[ ![ Coverage] [ coverage-badge ]] [ coverage ]
5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
6
[ ![ Size] [ size-badge ]] [ size ]
7
- [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8
- [ ![ Backers] [ backers-badge ]] [ collective ]
9
- [ ![ Chat] [ chat-badge ]] [ chat ]
10
7
11
- [ ** rehype** ] [ rehype ] plugin to add ` id ` s to headings.
8
+ [ ** rehype** ] [ rehype ] plugin to add ` id ` s to headings with the option for custom IDs .
12
9
13
10
## Install
14
11
@@ -18,7 +15,7 @@ Node 12+ is needed to use it and it must be `import`ed instead of `require`d.
18
15
[ npm] [ ] :
19
16
20
17
``` sh
21
- npm install rehype-slug
18
+ npm install rehype-slug-custom-id
22
19
```
23
20
24
21
## Use
@@ -31,6 +28,7 @@ Say we have the following file, `fragment.html`:
31
28
<h3 >consectetur & ; adipisicing</h3 >
32
29
<h4 >elit</h4 >
33
30
<h5 >elit</h5 >
31
+ <h6 >Custom ID Should Be Here {#custom-id}</h6 >
34
32
```
35
33
36
34
And our script, ` example.js ` , looks as follows:
@@ -59,18 +57,28 @@ Now, running `node example` yields:
59
57
<h3 id =" consectetur--adipisicing" >consectetur & ; adipisicing</h3 >
60
58
<h4 id =" elit" >elit</h4 >
61
59
<h5 id =" elit-1" >elit</h5 >
60
+ <h6 id =" custom-id" >Custom ID Should Be Here</h6 >
62
61
```
63
62
64
63
## API
65
64
66
- This package exports no identifiers.
67
65
The default export is ` rehypeSlug ` .
68
66
69
67
### ` unified().use(rehypeSlug) `
70
68
71
69
Add ` id ` properties to h1-h6 headings that don’t already have one.
72
70
73
- Uses [ ** github-slugger** ] [ ghslug ] to create GitHub style ` id ` s.
71
+ Uses [ ** github-slugger** ] [ ghslug ] to create GitHub style ` id ` s, or a custom ID if supplied like so:
72
+
73
+ ``` html
74
+ <h1 >ID {#custom-id-here}</h1 >
75
+ ```
76
+
77
+ We support the following options for the plugin:
78
+
79
+ - ` enableCustomId ` : ` Boolean ` . Enable custom header IDs with {#id} (optional)
80
+ - ` maintainCase ` : ` Boolean ` . Maintains the case for markdown header (optional)
81
+ - ` removeAccents ` : ` Boolean ` . Remove accents from generated headings IDs (optional)
74
82
75
83
## Security
76
84
@@ -84,65 +92,35 @@ Always be wary with user input and use [`rehype-sanitize`][sanitize].
84
92
85
93
## Related
86
94
87
- * [ ` remark-slug ` ] ( https://github.com/wooorm/remark-slug )
95
+ * [ ` rehype-slug ` ] ( https://github.com/rehypejs/rehype-slug )
96
+ — Add slugs to headings in html
97
+ * [ ` remark-slug ` ] ( https://github.com/wooorm/remark-slug )
88
98
— Add slugs to headings in markdown
89
-
90
- ## Contribute
91
-
92
- See [ ` contributing.md ` ] [ contributing ] in [ ` rehypejs/.github ` ] [ health ] for ways
93
- to get started.
94
- See [ ` support.md ` ] [ support ] for ways to get help.
95
-
96
- This project has a [ code of conduct] [ coc ] .
97
- By interacting with this repository, organization, or community you agree to
98
- abide by its terms.
99
-
100
- ## License
101
-
102
- [ MIT] [ license ] © [ Titus Wormer] [ author ]
99
+ * [ ` gatsby-remark-autolink-headers ` ] ( https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-autolink-headers )
100
+ — Add slugs to headings in markdown for Gatsby
103
101
104
102
<!-- Definitions -->
105
103
106
- [ build-badge ] : https://github.com/rehypejs /rehype-slug/workflows/main/badge.svg
104
+ [ build-badge ] : https://github.com/unicorn-utterances /rehype-slug-custom-id /workflows/main/badge.svg
107
105
108
- [ build ] : https://github.com/rehypejs /rehype-slug/actions
106
+ [ build ] : https://github.com/unicorn-utterances /rehype-slug-custom-id /actions
109
107
110
- [ coverage-badge ] : https://img.shields.io/codecov/c/github/rehypejs /rehype-slug.svg
108
+ [ coverage-badge ] : https://img.shields.io/codecov/c/github/unicorn-utterances /rehype-slug-custom-id .svg
111
109
112
- [ coverage ] : https://codecov.io/github/rehypejs /rehype-slug
110
+ [ coverage ] : https://codecov.io/github/unicorn-utterances /rehype-slug-custom-id
113
111
114
112
[ downloads-badge ] : https://img.shields.io/npm/dm/rehype-slug.svg
115
113
116
- [ downloads ] : https://www.npmjs.com/package/rehype-slug
114
+ [ downloads ] : https://www.npmjs.com/package/rehype-slug-custom-id
117
115
118
- [ size-badge ] : https://img.shields.io/bundlephobia/minzip/rehype-slug.svg
116
+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/rehype-slug-custom-id .svg
119
117
120
118
[ size ] : https://bundlephobia.com/result?p=rehype-slug
121
119
122
- [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
123
-
124
- [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
125
-
126
- [ collective ] : https://opencollective.com/unified
127
-
128
- [ chat-badge ] : https://img.shields.io/badge/chat-discussions-success.svg
129
-
130
- [ chat ] : https://github.com/rehypejs/rehype/discussions
131
-
132
120
[ npm ] : https://docs.npmjs.com/cli/install
133
121
134
- [ health ] : https://github.com/rehypejs/.github
135
-
136
- [ contributing ] : https://github.com/rehypejs/.github/blob/HEAD/contributing.md
137
-
138
- [ support ] : https://github.com/rehypejs/.github/blob/HEAD/support.md
139
-
140
- [ coc ] : https://github.com/rehypejs/.github/blob/HEAD/code-of-conduct.md
141
-
142
122
[ license ] : license
143
123
144
- [ author ] : https://wooorm.com
145
-
146
124
[ rehype ] : https://github.com/rehypejs/rehype
147
125
148
126
[ ghslug ] : https://github.com/Flet/github-slugger
0 commit comments