@graph-artifact/core 0.1.5 → 0.1.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.
|
@@ -12,11 +12,34 @@ const invisibleHandle = {
|
|
|
12
12
|
background: 'transparent',
|
|
13
13
|
pointerEvents: 'none',
|
|
14
14
|
};
|
|
15
|
+
function decodeHtmlEntities(src) {
|
|
16
|
+
// Keep this intentionally small; labels should be plain text.
|
|
17
|
+
return src
|
|
18
|
+
.replace(/ /gi, ' ')
|
|
19
|
+
.replace(/&/gi, '&')
|
|
20
|
+
.replace(/</gi, '<')
|
|
21
|
+
.replace(/>/gi, '>')
|
|
22
|
+
.replace(/"/gi, '"')
|
|
23
|
+
.replace(/'/g, "'");
|
|
24
|
+
}
|
|
25
|
+
function htmlSubsetToMarkdown(src) {
|
|
26
|
+
// Mermaid labels often contain a tiny HTML subset: <br/>, <b>, <i>, etc.
|
|
27
|
+
// Convert the common cases to markdown so react-markdown renders them,
|
|
28
|
+
// and strip any remaining tags (avoid raw HTML rendering).
|
|
29
|
+
let s = src;
|
|
30
|
+
s = s.replace(/<\s*br\s*\/?\s*>/gi, '\n');
|
|
31
|
+
s = s.replace(/<\s*\/?\s*(strong|b)\s*>/gi, '**');
|
|
32
|
+
s = s.replace(/<\s*\/?\s*(em|i)\s*>/gi, '*');
|
|
33
|
+
s = s.replace(/<\s*\/?\s*code\s*>/gi, '`');
|
|
34
|
+
// Strip any remaining tags defensively
|
|
35
|
+
s = s.replace(/<[^>]*>/g, '');
|
|
36
|
+
return decodeHtmlEntities(s);
|
|
37
|
+
}
|
|
15
38
|
function normalizeLabelMarkdown(label) {
|
|
16
39
|
// Mermaid treats "\n" inside labels as a hard line break.
|
|
17
40
|
// react-markdown doesn't always preserve raw newlines, so force
|
|
18
41
|
// CommonMark hard-breaks by adding two trailing spaces.
|
|
19
|
-
return label
|
|
42
|
+
return htmlSubsetToMarkdown(label)
|
|
20
43
|
.replace(/\\n/g, '\n')
|
|
21
44
|
.trim()
|
|
22
45
|
.replace(/\n/g, ' \n');
|