@md-plugins/md-plugin-title 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +4 -0
- package/dist/index.mjs +28 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -80,6 +80,10 @@ Run the tests to ensure the plugin behaves as expected:
|
|
|
80
80
|
pnpm test
|
|
81
81
|
```
|
|
82
82
|
|
|
83
|
+
## Documentation
|
|
84
|
+
|
|
85
|
+
In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/md-plugins/title/overview) for the latest information.
|
|
86
|
+
|
|
83
87
|
## License
|
|
84
88
|
|
|
85
89
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
const htmlEscapeMap = {
|
|
2
|
+
"&": "&",
|
|
3
|
+
"<": "<",
|
|
4
|
+
">": ">",
|
|
5
|
+
"'": "'",
|
|
6
|
+
'"': """
|
|
7
|
+
};
|
|
8
|
+
const htmlEscapeRegexp = /[&<>'"]/g;
|
|
9
|
+
const htmlEscape = (str) => str.replace(htmlEscapeRegexp, (char) => htmlEscapeMap[char]);
|
|
10
|
+
const resolveTitleFromToken = (token, { shouldAllowHtml, shouldEscapeText }) => {
|
|
11
|
+
const children = token.children ?? [];
|
|
12
|
+
const titleTokenTypes = ["text", "emoji", "code_inline"];
|
|
13
|
+
if (shouldAllowHtml) {
|
|
14
|
+
titleTokenTypes.push("html_inline");
|
|
15
|
+
}
|
|
16
|
+
const titleTokens = children.filter(
|
|
17
|
+
(item) => titleTokenTypes.includes(item.type) && // filter permalink symbol that generated by markdown-it-anchor
|
|
18
|
+
!item.meta?.isPermalinkSymbol
|
|
19
|
+
);
|
|
20
|
+
return titleTokens.reduce((result, item) => {
|
|
21
|
+
if (shouldEscapeText) {
|
|
22
|
+
if (item.type === "code_inline" || item.type === "text") {
|
|
23
|
+
return `${result}${htmlEscape(item.content)}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return `${result}${item.content}`;
|
|
27
|
+
}, "").trim();
|
|
28
|
+
};
|
|
2
29
|
|
|
3
30
|
const titlePlugin = (md) => {
|
|
4
31
|
const render = md.renderer.render.bind(md.renderer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/md-plugin-title",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.21",
|
|
4
4
|
"description": "A markdown-it plugin for getting Title information.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -32,10 +32,13 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"./dist"
|
|
34
34
|
],
|
|
35
|
-
"
|
|
36
|
-
"@types/markdown-it": "^14.1.2",
|
|
35
|
+
"devDependencies": {
|
|
37
36
|
"markdown-it": "^14.1.0",
|
|
38
|
-
"@
|
|
37
|
+
"@types/markdown-it": "^14.1.2",
|
|
38
|
+
"@md-plugins/shared": "0.1.0-alpha.21"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"markdown-it": "^14.1.0"
|
|
39
42
|
},
|
|
40
43
|
"publishConfig": {
|
|
41
44
|
"access": "public"
|