feat(attachments): add pretty formatting to JSON

This commit is contained in:
Elian Doran 2025-06-25 17:45:11 +03:00
parent 9c137a1c48
commit 9e57c14130
No known key found for this signature in database

View File

@ -118,8 +118,17 @@ async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HT
async function renderCode(note: FNote | FAttachment, $renderedContent: JQuery<HTMLElement>) { async function renderCode(note: FNote | FAttachment, $renderedContent: JQuery<HTMLElement>) {
const blob = await note.getBlob(); const blob = await note.getBlob();
let content = blob?.content || "";
if (note.mime === "application/json") {
try {
content = JSON.stringify(JSON.parse(content), null, 4);
} catch (e) {
// Ignore JSON parsing errors.
}
}
const $codeBlock = $("<code>"); const $codeBlock = $("<code>");
$codeBlock.text(blob?.content || ""); $codeBlock.text(content);
$renderedContent.append($("<pre>").append($codeBlock)); $renderedContent.append($("<pre>").append($codeBlock));
await applySingleBlockSyntaxHighlight($codeBlock, normalizeMimeTypeForCKEditor(note.mime)); await applySingleBlockSyntaxHighlight($codeBlock, normalizeMimeTypeForCKEditor(note.mime));
} }