chore(prettier): fix all files

This commit is contained in:
Elian Doran
2025-01-09 18:07:02 +02:00
parent 19ee861699
commit 4cbb529fd4
571 changed files with 23226 additions and 23940 deletions

View File

@@ -4,10 +4,10 @@ import { getContentDisposition, stripTags } from "../utils.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 exportToOpml(taskContext: TaskContext, branch: BBranch, version: string, res: Response) {
if (!['1.0', '2.0'].includes(version)) {
if (!["1.0", "2.0"].includes(version)) {
throw new Error(`Unrecognized OPML version ${version}`);
}
@@ -17,30 +17,32 @@ function exportToOpml(taskContext: TaskContext, branch: BBranch, version: string
function exportNoteInner(branchId: string) {
const branch = becca.getBranch(branchId);
if (!branch) { throw new Error("Unable to find branch."); }
if (!branch) {
throw new Error("Unable to find branch.");
}
const note = branch.getNote();
if (!note) { throw new Error("Unable to find note."); }
if (!note) {
throw new Error("Unable to find note.");
}
if (note.hasOwnedLabel('excludeFromExport')) {
if (note.hasOwnedLabel("excludeFromExport")) {
return;
}
const title = `${branch.prefix ? (`${branch.prefix} - `) : ''}${note.title}`;
const title = `${branch.prefix ? `${branch.prefix} - ` : ""}${note.title}`;
if (opmlVersion === 1) {
const preparedTitle = escapeXmlAttribute(title);
const preparedContent = note.hasStringContent() ? prepareText(note.getContent() as string) : '';
const preparedContent = note.hasStringContent() ? prepareText(note.getContent() as string) : "";
res.write(`<outline title="${preparedTitle}" text="${preparedContent}">\n`);
}
else if (opmlVersion === 2) {
} else if (opmlVersion === 2) {
const preparedTitle = escapeXmlAttribute(title);
const preparedContent = note.hasStringContent() ? escapeXmlAttribute(note.getContent() as string) : '';
const preparedContent = note.hasStringContent() ? escapeXmlAttribute(note.getContent() as string) : "";
res.write(`<outline text="${preparedTitle}" _note="${preparedContent}">\n`);
}
else {
} else {
throw new Error(`Unrecognized OPML version ${opmlVersion}`);
}
@@ -52,14 +54,13 @@ function exportToOpml(taskContext: TaskContext, branch: BBranch, version: string
}
}
res.write('</outline>');
res.write("</outline>");
}
const filename = `${branch.prefix ? `${branch.prefix} - ` : ""}${note.title}.opml`;
const filename = `${branch.prefix ? (`${branch.prefix} - `) : ''}${note.title}.opml`;
res.setHeader('Content-Disposition', getContentDisposition(filename));
res.setHeader('Content-Type', 'text/x-opml');
res.setHeader("Content-Disposition", getContentDisposition(filename));
res.setHeader("Content-Type", "text/x-opml");
res.write(`<?xml version="1.0" encoding="UTF-8"?>
<opml version="${version}">
@@ -80,22 +81,17 @@ function exportToOpml(taskContext: TaskContext, branch: BBranch, version: string
}
function prepareText(text: string) {
const newLines = text.replace(/(<p[^>]*>|<br\s*\/?>)/g, '\n')
.replace(/&nbsp;/g, ' '); // nbsp isn't in XML standard (only HTML)
const newLines = text.replace(/(<p[^>]*>|<br\s*\/?>)/g, "\n").replace(/&nbsp;/g, " "); // nbsp isn't in XML standard (only HTML)
const stripped = stripTags(newLines);
const escaped = escapeXmlAttribute(stripped);
return escaped.replace(/\n/g, '&#10;');
return escaped.replace(/\n/g, "&#10;");
}
function escapeXmlAttribute(text: string) {
return text.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
}
export default {