fix: export to freemind html unescape

fix: #1000
This commit is contained in:
windingwind 2024-06-26 11:44:32 +08:00
parent b994651baa
commit 054c8fa6c2

View File

@ -1,6 +1,7 @@
import TreeModel = require("tree-model");
import { showHintWithLink } from "../../utils/hint";
import { getNoteTree, parseHTMLLines, renderNoteHTML } from "../../utils/note";
import { htmlEscape, htmlUnescape } from "../../utils/str";
export async function saveFreeMind(filename: string, noteId: number) {
const noteItem = Zotero.Items.get(noteId);
@ -22,20 +23,17 @@ async function note2mm(
}
e.childNodes.forEach((_e) => textNodeForEach(_e, callbackfn));
};
const html2Escape = (sHtml: string) => {
return sHtml.replace(/[<>&"]/g, function (c) {
return { "<": "&lt;", ">": "&gt;", "&": "&amp;", '"': "&quot;" }[c]!;
});
};
let lines: string[] = [];
if (options.withContent) {
const doc = ztoolkit
.getDOMParser()
.parseFromString(await renderNoteHTML(noteItem), "text/html");
textNodeForEach(doc.body, (e: Text) => {
e.data = html2Escape(e.data);
e.data = htmlEscape(doc, e.data);
});
lines = parseHTMLLines(doc.body.innerHTML);
lines = parseHTMLLines(doc.body.innerHTML).map((line) =>
htmlUnescape(line),
);
}
const convertClosingTags = (htmlStr: string) => {
const regConfs = [
@ -56,7 +54,8 @@ async function note2mm(
return htmlStr;
};
const convertNode = (node: TreeModel.Node<NoteNodeData>) => {
mmXML += `<node ID="${node.model.id}" TEXT="${html2Escape(
mmXML += `<node ID="${node.model.id}" TEXT="${htmlEscape(
Zotero.getMainWindow().document,
node.model.name || noteItem.getNoteTitle(),
)}"><hook NAME="AlwaysUnfoldedNode" />`;
if (