Skip to content

Commit b91fd2f

Browse files
committed
Add value dictionary tooltips to interactive output
1 parent 4a92b03 commit b91fd2f

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

docs/js/app.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,48 @@ function createInteractiveOutput(compressed) {
293293
const lines = compressed.split("\n");
294294
const container = document.createElement("div");
295295

296+
// Parse value dictionary from $def section
297+
const valueDictionary = new Map();
298+
let inDefSection = false;
299+
300+
lines.forEach((line) => {
301+
if (line.trim() === "$def:") {
302+
inDefSection = true;
303+
} else if (line.trim() === "$data:") {
304+
inDefSection = false;
305+
} else if (inDefSection && line.match(/^\s+(#\d+):(.+)$/)) {
306+
const match = line.match(/^\s+(#\d+):(.+)$/);
307+
const ref = match[1];
308+
let value = match[2];
309+
// Remove quotes if present
310+
if (value.startsWith('"') && value.endsWith('"')) {
311+
value = value.slice(1, -1);
312+
}
313+
valueDictionary.set(ref, value);
314+
}
315+
});
316+
317+
// Also parse inline dictionary (first occurrence with value #N)
318+
lines.forEach((line) => {
319+
// Match patterns like: value #0 or "value" #0
320+
const inlineMatch = line.match(/[:\s]([^#\s]+|"[^"]+")(\s+)(#\d+)/g);
321+
if (inlineMatch) {
322+
inlineMatch.forEach((match) => {
323+
const parts = match.match(/[:\s]([^#\s]+|"[^"]+")(\s+)(#\d+)/);
324+
if (parts) {
325+
let value = parts[1].trim();
326+
const ref = parts[3];
327+
if (value.startsWith('"') && value.endsWith('"')) {
328+
value = value.slice(1, -1);
329+
}
330+
if (!valueDictionary.has(ref)) {
331+
valueDictionary.set(ref, value);
332+
}
333+
}
334+
});
335+
}
336+
});
337+
296338
lines.forEach((line, idx) => {
297339
const lineDiv = document.createElement("div");
298340
let processed = false;
@@ -347,7 +389,10 @@ function createInteractiveOutput(compressed) {
347389
if (value.includes("#")) {
348390
value = value.replace(
349391
/(#\d+)/g,
350-
`<span class="hover-part text-green-600" data-tooltip="Value dictionary reference">$1</span>`,
392+
(match) => {
393+
const dictValue = valueDictionary.get(match) || "Unknown value";
394+
return `<span class="hover-part text-green-600" data-tooltip="Value: ${dictValue}">${match}</span>`;
395+
}
351396
);
352397
}
353398
if (value.match(/\[(\d+)\]@/)) {
@@ -366,6 +411,18 @@ function createInteractiveOutput(compressed) {
366411
// Process inline patterns in any line
367412
let html = line;
368413

414+
// Value dictionary references #N
415+
if (html.includes("#")) {
416+
html = html.replace(
417+
/(#\d+)/g,
418+
(match) => {
419+
const dictValue = valueDictionary.get(match) || "Unknown value";
420+
return `<span class="hover-part text-green-600" data-tooltip="Value: ${dictValue}">${match}</span>`;
421+
}
422+
);
423+
processed = true;
424+
}
425+
369426
// Object reference &obj0
370427
if (html.includes("&obj")) {
371428
html = html.replace(

0 commit comments

Comments
 (0)