@md-plugins/md-plugin-headers 0.1.0-alpha.1 → 0.1.0-alpha.5
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/LICENSE.md +1 -1
- package/README.md +8 -10
- package/package.json +9 -4
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024-present,
|
|
3
|
+
Copyright (c) 2024-present, MD-PLUGINS
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -109,17 +109,15 @@ With the `toc` property in `env`, you can build a ToC dynamically:
|
|
|
109
109
|
function generateToC(toc) {
|
|
110
110
|
const list = toc
|
|
111
111
|
.map((item) => {
|
|
112
|
-
const children = item.children
|
|
113
|
-
|
|
114
|
-
: '';
|
|
115
|
-
return `<li><a href="${item.link}">${item.title}</a>${children}</li>`;
|
|
112
|
+
const children = item.children ? `<ul>${generateToC(item.children)}</ul>` : ''
|
|
113
|
+
return `<li><a href="${item.link}">${item.title}</a>${children}</li>`
|
|
116
114
|
})
|
|
117
|
-
.join('')
|
|
118
|
-
return `<ul>${list}</ul
|
|
115
|
+
.join('')
|
|
116
|
+
return `<ul>${list}</ul>`
|
|
119
117
|
}
|
|
120
118
|
|
|
121
|
-
const tocHtml = generateToC(env.toc)
|
|
122
|
-
console.log('Generated ToC:', tocHtml)
|
|
119
|
+
const tocHtml = generateToC(env.toc)
|
|
120
|
+
console.log('Generated ToC:', tocHtml)
|
|
123
121
|
```
|
|
124
122
|
|
|
125
123
|
### Custom Slugify Function
|
|
@@ -129,7 +127,7 @@ You can use your own slugification logic for header IDs:
|
|
|
129
127
|
```js
|
|
130
128
|
md.use(headersPlugin, {
|
|
131
129
|
slugify: (str) => encodeURIComponent(str.replace(/\s+/g, '_')),
|
|
132
|
-
})
|
|
130
|
+
})
|
|
133
131
|
```
|
|
134
132
|
|
|
135
133
|
Whatever you use on the backend, should be the same logic on the frontend for slugification so that they match when using hash links.
|
|
@@ -141,7 +139,7 @@ Enable nested headers to include headers inside blockquotes or lists:
|
|
|
141
139
|
```js
|
|
142
140
|
md.use(headersPlugin, {
|
|
143
141
|
shouldAllowNested: true,
|
|
144
|
-
})
|
|
142
|
+
})
|
|
145
143
|
```
|
|
146
144
|
|
|
147
145
|
## Testing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/md-plugin-headers",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
4
|
"description": "A markdown-it plugin for handling headers (H1-H6).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -33,16 +33,21 @@
|
|
|
33
33
|
"./dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@types/markdown-it": "^14.1.2",
|
|
37
36
|
"markdown-it": "^14.1.0",
|
|
38
|
-
"@md-plugins/shared": "0.1.0-alpha.
|
|
37
|
+
"@md-plugins/shared": "0.1.0-alpha.5"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/markdown-it": "^14.1.2"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"markdown-it": "^14.1.0"
|
|
39
44
|
},
|
|
40
45
|
"publishConfig": {
|
|
41
46
|
"access": "public"
|
|
42
47
|
},
|
|
43
48
|
"scripts": {
|
|
44
49
|
"build": "unbuild",
|
|
45
|
-
"clean": "rm -rf dist",
|
|
50
|
+
"clean": "rm -rf dist/ node_modules/",
|
|
46
51
|
"test": "vitest"
|
|
47
52
|
}
|
|
48
53
|
}
|