@graph-artifact/core 0.1.6 → 0.1.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.
|
@@ -35,14 +35,39 @@ function stripMarkdown(input) {
|
|
|
35
35
|
.replace(/[_~#>|-]/g, '')
|
|
36
36
|
.trim();
|
|
37
37
|
}
|
|
38
|
+
function decodeHtmlEntities(src) {
|
|
39
|
+
return src
|
|
40
|
+
.replace(/ /gi, ' ')
|
|
41
|
+
.replace(/&/gi, '&')
|
|
42
|
+
.replace(/</gi, '<')
|
|
43
|
+
.replace(/>/gi, '>')
|
|
44
|
+
.replace(/"/gi, '"')
|
|
45
|
+
.replace(/'/g, "'");
|
|
46
|
+
}
|
|
47
|
+
function normalizeLabelText(label) {
|
|
48
|
+
// Sizing must mirror render-time transformations. In practice Mermaid labels
|
|
49
|
+
// often contain a small HTML subset (<br/>, <b>, <i>) which we render as
|
|
50
|
+
// markdown in the node components. Convert the key cases here so line/width
|
|
51
|
+
// estimation is correct.
|
|
52
|
+
let s = label;
|
|
53
|
+
s = s.replace(/<\s*br\s*\/?\s*>/gi, '\n');
|
|
54
|
+
// Strip common formatting tags (they don't affect width materially)
|
|
55
|
+
s = s.replace(/<\s*\/?\s*(strong|b|em|i|code)\s*>/gi, '');
|
|
56
|
+
// Strip any remaining tags defensively
|
|
57
|
+
s = s.replace(/<[^>]*>/g, '');
|
|
58
|
+
s = decodeHtmlEntities(s);
|
|
59
|
+
// Mermaid uses escaped "\n" inside labels
|
|
60
|
+
s = s.replace(/\\n/g, '\n');
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
38
63
|
function labelMetrics(label) {
|
|
39
|
-
const normalized = label
|
|
64
|
+
const normalized = normalizeLabelText(label);
|
|
40
65
|
const lines = normalized.split('\n');
|
|
41
66
|
const maxChars = Math.max(1, ...lines.map((line) => stripMarkdown(line).length || 1));
|
|
42
67
|
return { maxChars, lines: Math.max(1, lines.length) };
|
|
43
68
|
}
|
|
44
69
|
function estimatedWrappedLineCount(label, contentCharsPerLine) {
|
|
45
|
-
const normalized = label
|
|
70
|
+
const normalized = normalizeLabelText(label);
|
|
46
71
|
const lines = normalized.split('\n');
|
|
47
72
|
let total = 0;
|
|
48
73
|
const charsPerLine = Math.max(8, contentCharsPerLine);
|