mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 15:55:52 +01:00
chore(prettier): fix all files
This commit is contained in:
@@ -7,16 +7,16 @@ import mdService from "./md.js";
|
||||
import becca from "../../becca/becca.js";
|
||||
import TaskContext from "../task_context.js";
|
||||
import BBranch from "../../becca/entities/bbranch.js";
|
||||
import { Response } from 'express';
|
||||
import { Response } from "express";
|
||||
|
||||
function exportSingleNote(taskContext: TaskContext, branch: BBranch, format: "html" | "markdown", res: Response) {
|
||||
const note = branch.getNote();
|
||||
|
||||
if (note.type === 'image' || note.type === 'file') {
|
||||
if (note.type === "image" || note.type === "file") {
|
||||
return [400, `Note type '${note.type}' cannot be exported as single file.`];
|
||||
}
|
||||
|
||||
if (format !== 'html' && format !== 'markdown') {
|
||||
if (format !== "html" && format !== "markdown") {
|
||||
return [400, `Unrecognized format '${format}'`];
|
||||
}
|
||||
|
||||
@@ -27,42 +27,37 @@ function exportSingleNote(taskContext: TaskContext, branch: BBranch, format: "ht
|
||||
throw new Error("Unsupported content type for export.");
|
||||
}
|
||||
|
||||
if (note.type === 'text') {
|
||||
if (format === 'html') {
|
||||
if (note.type === "text") {
|
||||
if (format === "html") {
|
||||
content = inlineAttachments(content);
|
||||
|
||||
if (!content.toLowerCase().includes("<html")) {
|
||||
content = `<html><head><meta charset="utf-8"></head><body>${content}</body></html>`;
|
||||
}
|
||||
|
||||
payload = content.length < 100_000
|
||||
? html.prettyPrint(content, {indent_size: 2})
|
||||
: content;
|
||||
payload = content.length < 100_000 ? html.prettyPrint(content, { indent_size: 2 }) : content;
|
||||
|
||||
extension = 'html';
|
||||
mime = 'text/html';
|
||||
}
|
||||
else if (format === 'markdown') {
|
||||
extension = "html";
|
||||
mime = "text/html";
|
||||
} else if (format === "markdown") {
|
||||
payload = mdService.toMarkdown(content);
|
||||
extension = 'md';
|
||||
mime = 'text/x-markdown'
|
||||
extension = "md";
|
||||
mime = "text/x-markdown";
|
||||
}
|
||||
}
|
||||
else if (note.type === 'code') {
|
||||
} else if (note.type === "code") {
|
||||
payload = content;
|
||||
extension = mimeTypes.extension(note.mime) || 'code';
|
||||
extension = mimeTypes.extension(note.mime) || "code";
|
||||
mime = note.mime;
|
||||
}
|
||||
else if (note.type === 'relationMap' || note.type === 'canvas' || note.type === 'search') {
|
||||
} else if (note.type === "relationMap" || note.type === "canvas" || note.type === "search") {
|
||||
payload = content;
|
||||
extension = 'json';
|
||||
mime = 'application/json';
|
||||
extension = "json";
|
||||
mime = "application/json";
|
||||
}
|
||||
|
||||
const fileName = `${note.title}.${extension}`;
|
||||
|
||||
res.setHeader('Content-Disposition', getContentDisposition(fileName));
|
||||
res.setHeader('Content-Type', `${mime}; charset=UTF-8`);
|
||||
res.setHeader("Content-Disposition", getContentDisposition(fileName));
|
||||
res.setHeader("Content-Type", `${mime}; charset=UTF-8`);
|
||||
|
||||
res.send(payload);
|
||||
|
||||
@@ -73,7 +68,7 @@ function exportSingleNote(taskContext: TaskContext, branch: BBranch, format: "ht
|
||||
function inlineAttachments(content: string) {
|
||||
content = content.replace(/src="[^"]*api\/images\/([a-zA-Z0-9_]+)\/?[^"]+"/g, (match, noteId) => {
|
||||
const note = becca.getNote(noteId);
|
||||
if (!note || !note.mime.startsWith('image/')) {
|
||||
if (!note || !note.mime.startsWith("image/")) {
|
||||
return match;
|
||||
}
|
||||
|
||||
@@ -82,7 +77,7 @@ function inlineAttachments(content: string) {
|
||||
return match;
|
||||
}
|
||||
|
||||
const base64Content = imageContent.toString('base64');
|
||||
const base64Content = imageContent.toString("base64");
|
||||
const srcValue = `data:${note.mime};base64,${base64Content}`;
|
||||
|
||||
return `src="${srcValue}"`;
|
||||
@@ -90,7 +85,7 @@ function inlineAttachments(content: string) {
|
||||
|
||||
content = content.replace(/src="[^"]*api\/attachments\/([a-zA-Z0-9_]+)\/image\/?[^"]+"/g, (match, attachmentId) => {
|
||||
const attachment = becca.getAttachment(attachmentId);
|
||||
if (!attachment || !attachment.mime.startsWith('image/')) {
|
||||
if (!attachment || !attachment.mime.startsWith("image/")) {
|
||||
return match;
|
||||
}
|
||||
|
||||
@@ -99,7 +94,7 @@ function inlineAttachments(content: string) {
|
||||
return match;
|
||||
}
|
||||
|
||||
const base64Content = attachmentContent.toString('base64');
|
||||
const base64Content = attachmentContent.toString("base64");
|
||||
const srcValue = `data:${attachment.mime};base64,${base64Content}`;
|
||||
|
||||
return `src="${srcValue}"`;
|
||||
@@ -116,7 +111,7 @@ function inlineAttachments(content: string) {
|
||||
return match;
|
||||
}
|
||||
|
||||
const base64Content = attachmentContent.toString('base64');
|
||||
const base64Content = attachmentContent.toString("base64");
|
||||
const hrefValue = `data:${attachment.mime};base64,${base64Content}`;
|
||||
|
||||
return `href="${hrefValue}" download="${escapeHtml(attachment.title)}"`;
|
||||
|
||||
Reference in New Issue
Block a user