Skip to content

Commit d14ccb7

Browse files
committed
feat: add export to several formats
1 parent 4b1e40e commit d14ccb7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/components/Sidebar.vue

+13
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@
5252
<q-item-label>{{ $t("Save as") }}</q-item-label>
5353
</q-item-section>
5454
</q-item>
55+
<q-item
56+
clickable
57+
v-ripple
58+
:title="$t('Export to several formats')"
59+
@click="$emit('exportFile')"
60+
>
61+
<q-item-section avatar>
62+
<q-icon name="o_file_download" />
63+
</q-item-section>
64+
<q-item-section>
65+
<q-item-label>{{ $t("Export as") }}</q-item-label>
66+
</q-item-section>
67+
</q-item>
5568
<q-item
5669
clickable
5770
v-ripple

src/layouts/MainLayout.vue

+32
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@openFile="onOpenFile"
1616
@saveFile="onSaveFile"
1717
@saveFileAs="onSaveFileAs"
18+
@exportFile="onExportFile"
1819
@printFile="onPrintFile"
1920
@settings="onSettings"
2021
@exit="onExit"
@@ -127,6 +128,36 @@ export default defineComponent({
127128
await writable.close();
128129
}
129130
131+
async function onExportFile() {
132+
$q.dialog({
133+
title: i18n.t("Export file"),
134+
message: i18n.t("Select the format to export"),
135+
options: {
136+
type: "radio",
137+
model: "md",
138+
items: [
139+
{ label: "Markdown", value: "md" },
140+
{ label: "HTML", value: "html" },
141+
{ label: "Plain Text", value: "txt" },
142+
],
143+
},
144+
cancel: true,
145+
persistent: true,
146+
}).onOk(async (format) => {
147+
const basename = store.state.editor.filename.replace(/\.[^/.]+$/, "");
148+
const fileHandle = await window.showSaveFilePicker({
149+
suggestedName: `${basename}.${format}`,
150+
});
151+
const writable = await fileHandle.createWritable();
152+
const content = serializeContent(
153+
store.state.editor.content,
154+
fileHandle.name
155+
);
156+
await writable.write(content);
157+
await writable.close();
158+
});
159+
}
160+
130161
function onPrintFile() {
131162
store.dispatch("editor/printFile");
132163
}
@@ -210,6 +241,7 @@ export default defineComponent({
210241
onOpenFile,
211242
onSaveFile,
212243
onSaveFileAs,
244+
onExportFile,
213245
onPrintFile,
214246
onSettings,
215247
onAbout,

0 commit comments

Comments
 (0)