Skip to content

Commit

Permalink
feat: markdown export (lencx#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx authored and Somsak Meesangpetch committed Jul 24, 2023
1 parent 38e999c commit 1755573
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
11 changes: 11 additions & 0 deletions UPDATE_LOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src-tauri/src/scripts/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/scripts/markdown.export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 1755573

Please sign in to comment.