Skip to content

Commit

Permalink
Use note title as default file name on markdown file export (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Apr 26, 2018
1 parent fdb8bbd commit 5e97c10
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion browser.js
Expand Up @@ -417,13 +417,22 @@ ipc.on('export', exportAsPDF);
async function exportAsMarkdown() {
// Get frame of selected note
const selectedNoteFrame = await getNoteFrame();
// Convert note to markdown

// Get note title
const getTitle = () => {
const title = document.querySelector('#gwt-debug-NoteTitleView-label').innerHTML;
return title.length ? title.trim().replace(/ /g, ' ') : 'note';
};

// Covert note to markdown
const toMarkdown = noteFrame => {
const turndownUtil = new Turndown();
return turndownUtil.turndown(noteFrame.contentDocument.body);
};

// Saving options
const options = {
defaultPath: getTitle(),
filters: [{
name: 'Markdown File',
extensions: ['md']
Expand All @@ -432,6 +441,7 @@ async function exportAsMarkdown() {
extensions: ['*']
}]
};

// Initialize saving dialog
dialog.showSaveDialog(options, fileName => {
if (fileName === undefined) {
Expand Down

0 comments on commit 5e97c10

Please sign in to comment.