@md-plugins/md-plugin-title 0.1.0-alpha.12 → 0.1.0-alpha.13
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/dist/index.mjs +28 -1
- package/package.json +4 -6
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.13",
|
|
4
4
|
"description": "A markdown-it plugin for getting Title information.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -32,12 +32,10 @@
|
|
|
32
32
|
"files": [
|
|
33
33
|
"./dist"
|
|
34
34
|
],
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"markdown-it": "^14.1.0",
|
|
37
|
-
"@md-plugins/shared": "0.1.0-alpha.12"
|
|
38
|
-
},
|
|
39
35
|
"devDependencies": {
|
|
40
|
-
"
|
|
36
|
+
"markdown-it": "^14.1.0",
|
|
37
|
+
"@types/markdown-it": "^14.1.2",
|
|
38
|
+
"@md-plugins/shared": "0.1.0-alpha.13"
|
|
41
39
|
},
|
|
42
40
|
"peerDependencies": {
|
|
43
41
|
"markdown-it": "^14.1.0"
|