From bc4943fd57639de2f672c55d4faef53776f9a016 Mon Sep 17 00:00:00 2001 From: xiangyu <3170102889@zju.edu.cn> Date: Mon, 10 Oct 2022 23:55:20 +0800 Subject: [PATCH] fix: #176 export md with highlight bug --- src/note/noteExportWindow.ts | 1 + src/note/noteParse.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/note/noteExportWindow.ts b/src/note/noteExportWindow.ts index 94c7e8d..7a1b95e 100644 --- a/src/note/noteExportWindow.ts +++ b/src/note/noteExportWindow.ts @@ -220,6 +220,7 @@ class NoteExportWindow extends AddonBase { exportFile: exportFile, exportSingleFile: exportSingleFile, exportAutoSync: exportAutoSync, + exportHighlight: exportHighlight, embedLink: embedLink, exportNote: exportNote, exportCopy: exportCopy, diff --git a/src/note/noteParse.ts b/src/note/noteParse.ts index 86afaef..981b52d 100644 --- a/src/note/noteParse.ts +++ b/src/note/noteParse.ts @@ -708,6 +708,21 @@ class NoteParse extends AddonBase { return "[" + content + "](" + href + title + ")"; }, }); + + if (Zotero.Prefs.get("Knowledge4Zotero.exportHighlight")) { + turndownService.addRule("backgroundColor", { + filter: function (node, options) { + return node.nodeName === "SPAN" && node.style["background-color"]; + }, + + replacement: function (content, node) { + return `${content}`; + }, + }); + } + const parsedMD = turndownService.turndown(doc.body); console.log(parsedMD); return parsedMD;