feat: markdown export (#233)

This commit is contained in:
lencx 2023-02-03 12:22:15 +08:00
parent 4847bb6fac
commit 70aac07f8e
3 changed files with 22 additions and 2 deletions

View File

@ -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:

View File

@ -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 = `<blockquote>${i.innerHTML}</blockquote>`;
}
return j.innerHTML;
}).join('<hr />');
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' });

View File

@ -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) => {