Skip to content

Commit 3e2bdd2

Browse files
committed
Formatted JSON columns
Signed-off-by: worksofliam <[email protected]>
1 parent 1bbc180 commit 3e2bdd2

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/views/results/html.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,28 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
184184
// Insert a cell at the end of the row
185185
var newCell = newRow.insertCell();
186186
187-
// Append a text node to the cell
188-
189-
//TODO: handle cell formatting here
190187
var newDiv = document.createElement("div");
191188
newDiv.className = "hoverable";
192-
newDiv.appendChild(document.createTextNode(cell === undefined ? 'null' : cell));
189+
190+
// Append a formatted JSON object to the cell
191+
const contentMightBeJson = typeof cell === 'string' && (cell.startsWith('{') || cell.startsWith('[')) && (cell.endsWith('}') || cell.endsWith(']'));
192+
let isJson = false;
193+
if (contentMightBeJson) {
194+
try {
195+
const cellJson = JSON.stringify(JSON.parse(cell), null, 2);
196+
newDiv.style.whiteSpace = "pre";
197+
newDiv.style["font-family"] = "monospace";
198+
newDiv.innerText = cellJson;
199+
isJson = true;
200+
} catch (e) {}
201+
}
202+
203+
if (!isJson) {
204+
// Append a text node to the cell
205+
newDiv.appendChild(document.createTextNode(cell === undefined ? 'null' : cell));
206+
}
207+
208+
console.log({isJson, contentMightBeJson})
193209
194210
newCell.appendChild(newDiv);
195211
}

0 commit comments

Comments
 (0)