@raketa-builder/support 1.4.5 → 1.4.7
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 +93 -44
- package/package.json +1 -1
package/dist/toHTML.js
CHANGED
|
@@ -1,55 +1,104 @@
|
|
|
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
|
+
console.log("=== toHTML called ===");
|
|
8
|
+
console.log("Input string:", string);
|
|
9
|
+
console.log("Inline mode:", inline);
|
|
10
|
+
const markedInstance = new Marked();
|
|
11
|
+
const attributes = {
|
|
12
|
+
name: "attributes",
|
|
13
|
+
level: "inline",
|
|
14
|
+
start(src) {
|
|
15
|
+
const result = src[0] === "{" ? 0 : void 0;
|
|
16
|
+
console.log(
|
|
17
|
+
"attributes.start called with:",
|
|
18
|
+
src.substring(0, 50),
|
|
19
|
+
"result:",
|
|
20
|
+
result
|
|
21
|
+
);
|
|
22
|
+
return result;
|
|
23
|
+
},
|
|
24
|
+
tokenizer(src, tokens) {
|
|
25
|
+
console.log("=== tokenizer called ===");
|
|
26
|
+
console.log("src:", src.substring(0, 100));
|
|
27
|
+
console.log("tokens length:", tokens.length);
|
|
28
|
+
console.log(
|
|
29
|
+
"last 3 tokens:",
|
|
30
|
+
tokens.slice(-3).map((t) => ({ type: t.type, raw: t.raw }))
|
|
31
|
+
);
|
|
32
|
+
const match = /^\{([^}]*)\}/.exec(src);
|
|
33
|
+
console.log("regex match:", match);
|
|
34
|
+
if (match && tokens.length > 0) {
|
|
35
|
+
const last = tokens[tokens.length - 1];
|
|
36
|
+
console.log("last token:", {
|
|
37
|
+
type: last.type,
|
|
38
|
+
raw: last.raw,
|
|
39
|
+
href: last.href,
|
|
40
|
+
text: last.text
|
|
41
|
+
});
|
|
42
|
+
if (last.type === "link" && last.raw && src.startsWith("{", 0)) {
|
|
43
|
+
console.log("Processing attributes for link:", last.raw);
|
|
44
|
+
try {
|
|
45
|
+
last.attributes = parseAttrs(match[1]);
|
|
46
|
+
console.log("Parsed attributes:", last.attributes);
|
|
47
|
+
return {
|
|
48
|
+
type: "attributes",
|
|
49
|
+
raw: match[0]
|
|
50
|
+
};
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Error parsing attributes:", error);
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
21
56
|
}
|
|
57
|
+
console.log("tokenizer returning false");
|
|
58
|
+
console.log("========================");
|
|
59
|
+
return false;
|
|
60
|
+
},
|
|
61
|
+
renderer(token) {
|
|
62
|
+
console.log("attributes.renderer called with:", token);
|
|
63
|
+
return "";
|
|
22
64
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
65
|
+
};
|
|
66
|
+
const renderer = {
|
|
67
|
+
link(token) {
|
|
68
|
+
console.log("=== link renderer ===");
|
|
69
|
+
console.log("token:", token);
|
|
70
|
+
let attributeString = "";
|
|
71
|
+
if (token.attributes) {
|
|
72
|
+
attributeString = Object.entries(token.attributes).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
73
|
+
console.log("attributeString:", attributeString);
|
|
74
|
+
}
|
|
75
|
+
const result = `<a href="${token.href}"${attributeString}>${token.text}</a>`;
|
|
76
|
+
console.log("link result:", result);
|
|
77
|
+
return result;
|
|
34
78
|
}
|
|
35
|
-
|
|
79
|
+
};
|
|
80
|
+
markedInstance.use({
|
|
81
|
+
extensions: [attributes],
|
|
82
|
+
renderer,
|
|
83
|
+
useNewRenderer: true
|
|
84
|
+
});
|
|
85
|
+
markedInstance.setOptions({
|
|
86
|
+
breaks: true,
|
|
87
|
+
gfm: true,
|
|
88
|
+
headerIds: false,
|
|
89
|
+
mangle: false
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
const result = inline ? markedInstance.parseInline(string) : markedInstance.parse(string);
|
|
93
|
+
console.log("Final result:", result);
|
|
94
|
+
console.log("======================");
|
|
95
|
+
return result;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error("Parse error:", error);
|
|
98
|
+
console.log("======================");
|
|
99
|
+
throw error;
|
|
36
100
|
}
|
|
37
101
|
};
|
|
38
|
-
marked.use({
|
|
39
|
-
extensions: [attributes],
|
|
40
|
-
renderer,
|
|
41
|
-
useNewRenderer: true
|
|
42
|
-
});
|
|
43
|
-
marked.setOptions({
|
|
44
|
-
breaks: true,
|
|
45
|
-
gfm: true,
|
|
46
|
-
headerIds: false,
|
|
47
|
-
mangle: false
|
|
48
|
-
});
|
|
49
|
-
const toHTML = (string, inline = false) => {
|
|
50
|
-
if (!string) return;
|
|
51
|
-
return inline ? marked.parseInline(string) : marked.parse(string);
|
|
52
|
-
};
|
|
53
102
|
var toHTML_default = toHTML;
|
|
54
103
|
|
|
55
104
|
export { toHTML_default as default };
|