@raketa-builder/support 1.4.5 → 1.4.6
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/toHTML.js +46 -45
- package/package.json +1 -1
package/dist/toHTML.js
CHANGED
|
@@ -1,54 +1,55 @@
|
|
|
1
1
|
import './chunk-ORMEWXMH.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Marked } from 'marked';
|
|
3
3
|
import parseAttrs from 'attributes-parser';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
const toHTML = (string, inline = false) => {
|
|
6
|
+
if (!string) return "";
|
|
7
|
+
const markedInstance = new Marked();
|
|
8
|
+
const attributes = {
|
|
9
|
+
name: "attributes",
|
|
10
|
+
level: "inline",
|
|
11
|
+
start(src) {
|
|
12
|
+
return src[0] === "{" ? 0 : void 0;
|
|
13
|
+
},
|
|
14
|
+
tokenizer(src, tokens) {
|
|
15
|
+
const match = /^\{([^}]*)\}/.exec(src);
|
|
16
|
+
if (match && tokens.length > 0) {
|
|
17
|
+
const last = tokens[tokens.length - 1];
|
|
18
|
+
if (last.type === "link" && last.raw && src.startsWith("{", 0)) {
|
|
19
|
+
last.attributes = parseAttrs(match[1]);
|
|
20
|
+
return {
|
|
21
|
+
type: "attributes",
|
|
22
|
+
raw: match[0]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
21
25
|
}
|
|
26
|
+
return false;
|
|
27
|
+
},
|
|
28
|
+
renderer(token) {
|
|
29
|
+
return "";
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let attributeString = "";
|
|
32
|
-
if (token.attributes) {
|
|
33
|
-
attributeString = Object.entries(token.attributes).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
31
|
+
};
|
|
32
|
+
const renderer = {
|
|
33
|
+
link(token) {
|
|
34
|
+
let attributeString = "";
|
|
35
|
+
if (token.attributes) {
|
|
36
|
+
attributeString = Object.entries(token.attributes).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
37
|
+
}
|
|
38
|
+
return `<a href="${token.href}"${attributeString}>${token.text}</a>`;
|
|
34
39
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
const toHTML = (string, inline = false) => {
|
|
50
|
-
if (!string) return;
|
|
51
|
-
return inline ? marked.parseInline(string) : marked.parse(string);
|
|
40
|
+
};
|
|
41
|
+
markedInstance.use({
|
|
42
|
+
extensions: [attributes],
|
|
43
|
+
renderer,
|
|
44
|
+
useNewRenderer: true
|
|
45
|
+
});
|
|
46
|
+
markedInstance.setOptions({
|
|
47
|
+
breaks: true,
|
|
48
|
+
gfm: true,
|
|
49
|
+
headerIds: false,
|
|
50
|
+
mangle: false
|
|
51
|
+
});
|
|
52
|
+
return inline ? markedInstance.parseInline(string) : markedInstance.parse(string);
|
|
52
53
|
};
|
|
53
54
|
var toHTML_default = toHTML;
|
|
54
55
|
|