From 70aac07f8ea9504fc6f740bcdb561f4fd18736c9 Mon Sep 17 00:00:00 2001 From: lencx Date: Fri, 3 Feb 2023 12:22:15 +0800 Subject: [PATCH] feat: markdown export (#233) --- UPDATE_LOG.md | 11 +++++++++++ src-tauri/src/scripts/export.js | 9 ++++++++- src-tauri/src/scripts/markdown.export.js | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/UPDATE_LOG.md b/UPDATE_LOG.md index ccc4cc920..3e58e5026 100644 --- a/UPDATE_LOG.md +++ b/UPDATE_LOG.md @@ -1,5 +1,16 @@ # UPDATE LOG +## v0.10.3 + +Fix: + +- Incompatible configuration data causes program crashes (https://github.com/lencx/ChatGPT/issues/295) +- Silent copy text + +Feat: + +- markdown export support distinguishes between users and bots (https://github.com/lencx/ChatGPT/issues/233) + ## v0.10.2 Fix: diff --git a/src-tauri/src/scripts/export.js b/src-tauri/src/scripts/export.js index 5a0b7273c..6924bf6bc 100644 --- a/src-tauri/src/scripts/export.js +++ b/src-tauri/src/scripts/export.js @@ -137,7 +137,14 @@ function addActionsButtons(actionsArea, TryAgainButton) { } async function exportMarkdown() { - const data = ExportMD.turndown(document.querySelector("main div>div>div").innerHTML); + const content = Array.from(document.querySelectorAll("main >div>div>div>div")).map(i => { + let j = i.cloneNode(true); + if (/dark\:bg-gray-800/.test(i.getAttribute('class'))) { + j.innerHTML = `
${i.innerHTML}
`; + } + return j.innerHTML; + }).join('
'); + const data = ExportMD.turndown(content); const { id, filename } = getName(); await invoke('save_file', { name: `notes/${id}.md`, content: data }); await invoke('download_list', { pathname: 'chat.notes.json', filename, id, dir: 'notes' }); diff --git a/src-tauri/src/scripts/markdown.export.js b/src-tauri/src/scripts/markdown.export.js index 651eebcfe..4c9d5fb3f 100644 --- a/src-tauri/src/scripts/markdown.export.js +++ b/src-tauri/src/scripts/markdown.export.js @@ -2,7 +2,9 @@ var ExportMD = (function () { if (!TurndownService || !turndownPluginGfm) return; const hljsREG = /^.*(hljs).*(language-[a-z0-9]+).*$/i; const gfm = turndownPluginGfm.gfm - const turndownService = new TurndownService() + const turndownService = new TurndownService({ + hr: '---' + }) .use(gfm) .addRule('code', { filter: (node) => {