mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: export markdown
This commit is contained in:
@@ -40,6 +40,13 @@ pub fn download(_app: AppHandle, name: String, blob: Vec<u8>) {
|
|||||||
utils::open_file(path);
|
utils::open_file(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[command]
|
||||||
|
pub fn save_file(_app: AppHandle, name: String, content: String) {
|
||||||
|
let path = api::path::download_dir().unwrap().join(name);
|
||||||
|
fs::write(&path, content).unwrap();
|
||||||
|
utils::open_file(path);
|
||||||
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub fn open_link(app: AppHandle, url: String) {
|
pub fn open_link(app: AppHandle, url: String) {
|
||||||
api::shell::open(&app.shell_scope(), url, None).unwrap();
|
api::shell::open(&app.shell_scope(), url, None).unwrap();
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ async fn main() {
|
|||||||
cmd::drag_window,
|
cmd::drag_window,
|
||||||
cmd::fullscreen,
|
cmd::fullscreen,
|
||||||
cmd::download,
|
cmd::download,
|
||||||
|
cmd::save_file,
|
||||||
cmd::open_link,
|
cmd::open_link,
|
||||||
cmd::get_chat_conf,
|
cmd::get_chat_conf,
|
||||||
cmd::get_theme,
|
cmd::get_theme,
|
||||||
|
|||||||
31
src-tauri/src/scripts/export.js
vendored
31
src-tauri/src/scripts/export.js
vendored
@@ -124,9 +124,8 @@ function addActionsButtons(actionsArea, TryAgainButton) {
|
|||||||
exportMd.title = "Download Markdown";
|
exportMd.title = "Download Markdown";
|
||||||
exportMd.innerHTML = setIcon('md');
|
exportMd.innerHTML = setIcon('md');
|
||||||
exportMd.onclick = () => {
|
exportMd.onclick = () => {
|
||||||
const md = ExportMD.turndown(document.querySelector("main div>div>div").innerHTML);
|
const data = ExportMD.turndown(document.querySelector("main div>div>div").innerHTML);
|
||||||
console.log('«128» /src/scripts/export.js ~> ', md);
|
invoke('save_file', { name: `chatgpt-${Date.now()}.md`, content: data });
|
||||||
|
|
||||||
};
|
};
|
||||||
actionsArea.appendChild(exportMd);
|
actionsArea.appendChild(exportMd);
|
||||||
}
|
}
|
||||||
@@ -160,7 +159,7 @@ function handleImg(imgData) {
|
|||||||
for (let i = 0; i < binaryData.length; i++) {
|
for (let i = 0; i < binaryData.length; i++) {
|
||||||
data.push(binaryData.charCodeAt(i));
|
data.push(binaryData.charCodeAt(i));
|
||||||
}
|
}
|
||||||
invoke('download', { name: `chatgpt-${Date.now()}.png`, blob: Array.from(new Uint8Array(data)) });
|
invoke('download', { name: `chatgpt-${Date.now()}.png`, blob: data });
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePdf(imgData, canvas, pixelRatio) {
|
function handlePdf(imgData, canvas, pixelRatio) {
|
||||||
@@ -289,27 +288,3 @@ function setIcon(type) {
|
|||||||
md: `<svg class="chatappico md" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1380" width="200" height="200"><path d="M128 128h768a42.666667 42.666667 0 0 1 42.666667 42.666667v682.666666a42.666667 42.666667 0 0 1-42.666667 42.666667H128a42.666667 42.666667 0 0 1-42.666667-42.666667V170.666667a42.666667 42.666667 0 0 1 42.666667-42.666667z m170.666667 533.333333v-170.666666l85.333333 85.333333 85.333333-85.333333v170.666666h85.333334v-298.666666h-85.333334l-85.333333 85.333333-85.333333-85.333333H213.333333v298.666666h85.333334z m469.333333-128v-170.666666h-85.333333v170.666666h-85.333334l128 128 128-128h-85.333333z" p-id="1381" fill="currentColor"></path></svg>`
|
md: `<svg class="chatappico md" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1380" width="200" height="200"><path d="M128 128h768a42.666667 42.666667 0 0 1 42.666667 42.666667v682.666666a42.666667 42.666667 0 0 1-42.666667 42.666667H128a42.666667 42.666667 0 0 1-42.666667-42.666667V170.666667a42.666667 42.666667 0 0 1 42.666667-42.666667z m170.666667 533.333333v-170.666666l85.333333 85.333333 85.333333-85.333333v170.666666h85.333334v-298.666666h-85.333334l-85.333333 85.333333-85.333333-85.333333H213.333333v298.666666h85.333334z m469.333333-128v-170.666666h-85.333333v170.666666h-85.333334l128 128 128-128h-85.333333z" p-id="1381" fill="currentColor"></path></svg>`
|
||||||
}[type];
|
}[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function downloadMD() {
|
|
||||||
console.log("markdown");
|
|
||||||
const chatThread = document.querySelector('main div>div>div');
|
|
||||||
const chatBlocks = $(chatThread, '>div');
|
|
||||||
|
|
||||||
console.log('«296» /src/scripts/export.js ~> ', chatThread, chatThread.innerHTML);
|
|
||||||
|
|
||||||
|
|
||||||
const content = new TurndownService()
|
|
||||||
.use(turndownPluginGfm.gfm)
|
|
||||||
.addRule({
|
|
||||||
filter: function (node, options) {
|
|
||||||
return node.nodeName === 'code' && node.classList.includes('hljs')
|
|
||||||
},
|
|
||||||
replacement: function (content) {
|
|
||||||
return '```\n' + content + '\n```'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.turndown(chatThread.innerHTML);
|
|
||||||
|
|
||||||
console.log('«8» /src/scripts/markdown.export.js ~> ', content);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user