@raketa-builder/support 1.4.7 → 1.4.8
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 +1 -38
- package/package.json +1 -1
package/dist/toHTML.js
CHANGED
|
@@ -3,77 +3,43 @@ import { Marked } from 'marked';
|
|
|
3
3
|
import parseAttrs from 'attributes-parser';
|
|
4
4
|
|
|
5
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
6
|
const markedInstance = new Marked();
|
|
11
7
|
const attributes = {
|
|
12
8
|
name: "attributes",
|
|
13
9
|
level: "inline",
|
|
14
10
|
start(src) {
|
|
15
11
|
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
12
|
return result;
|
|
23
13
|
},
|
|
24
14
|
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
15
|
const match = /^\{([^}]*)\}/.exec(src);
|
|
33
|
-
console.log("regex match:", match);
|
|
34
16
|
if (match && tokens.length > 0) {
|
|
35
17
|
const last = tokens[tokens.length - 1];
|
|
36
|
-
|
|
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);
|
|
18
|
+
if (last.type === "link" && last.raw) {
|
|
44
19
|
try {
|
|
45
20
|
last.attributes = parseAttrs(match[1]);
|
|
46
|
-
console.log("Parsed attributes:", last.attributes);
|
|
47
21
|
return {
|
|
48
22
|
type: "attributes",
|
|
49
23
|
raw: match[0]
|
|
50
24
|
};
|
|
51
25
|
} catch (error) {
|
|
52
|
-
console.error("Error parsing attributes:", error);
|
|
53
26
|
return false;
|
|
54
27
|
}
|
|
55
28
|
}
|
|
56
29
|
}
|
|
57
|
-
console.log("tokenizer returning false");
|
|
58
|
-
console.log("========================");
|
|
59
30
|
return false;
|
|
60
31
|
},
|
|
61
32
|
renderer(token) {
|
|
62
|
-
console.log("attributes.renderer called with:", token);
|
|
63
33
|
return "";
|
|
64
34
|
}
|
|
65
35
|
};
|
|
66
36
|
const renderer = {
|
|
67
37
|
link(token) {
|
|
68
|
-
console.log("=== link renderer ===");
|
|
69
|
-
console.log("token:", token);
|
|
70
38
|
let attributeString = "";
|
|
71
39
|
if (token.attributes) {
|
|
72
40
|
attributeString = Object.entries(token.attributes).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
73
|
-
console.log("attributeString:", attributeString);
|
|
74
41
|
}
|
|
75
42
|
const result = `<a href="${token.href}"${attributeString}>${token.text}</a>`;
|
|
76
|
-
console.log("link result:", result);
|
|
77
43
|
return result;
|
|
78
44
|
}
|
|
79
45
|
};
|
|
@@ -90,12 +56,9 @@ const toHTML = (string, inline = false) => {
|
|
|
90
56
|
});
|
|
91
57
|
try {
|
|
92
58
|
const result = inline ? markedInstance.parseInline(string) : markedInstance.parse(string);
|
|
93
|
-
console.log("Final result:", result);
|
|
94
|
-
console.log("======================");
|
|
95
59
|
return result;
|
|
96
60
|
} catch (error) {
|
|
97
61
|
console.error("Parse error:", error);
|
|
98
|
-
console.log("======================");
|
|
99
62
|
throw error;
|
|
100
63
|
}
|
|
101
64
|
};
|