mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
possibility to export single code note as markdown. UI fix of disabled buttons
This commit is contained in:
parent
d6b5cd6ead
commit
568c2c997f
8
src/public/javascripts/services/bootstrap.js
vendored
8
src/public/javascripts/services/bootstrap.js
vendored
@ -103,7 +103,13 @@ if (utils.isElectron()) {
|
||||
});
|
||||
}
|
||||
|
||||
$("#export-note-to-markdown-button").click(() => exportService.exportSubtree(noteDetailService.getCurrentNoteId(), 'markdown-single'));
|
||||
$("#export-note-to-markdown-button").click(function () {
|
||||
if ($(this).hasClass("disabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
exportService.exportSubtree(noteDetailService.getCurrentNoteId(), 'markdown-single')
|
||||
});
|
||||
|
||||
treeService.showTree();
|
||||
|
||||
|
@ -25,9 +25,21 @@ function registerEntrypoints() {
|
||||
$("#jump-to-note-dialog-button").click(jumpToNoteDialog.showDialog);
|
||||
utils.bindShortcut('ctrl+j', jumpToNoteDialog.showDialog);
|
||||
|
||||
$("#show-note-revisions-button").click(noteRevisionsDialog.showCurrentNoteRevisions);
|
||||
$("#show-note-revisions-button").click(function() {
|
||||
if ($(this).hasClass("disabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
$("#show-source-button").click(noteSourceDialog.showDialog);
|
||||
noteRevisionsDialog.showCurrentNoteRevisions();
|
||||
});
|
||||
|
||||
$("#show-source-button").click(function() {
|
||||
if ($(this).hasClass("disabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
noteSourceDialog.showDialog();
|
||||
});
|
||||
|
||||
$("#recent-changes-button").click(recentChangesDialog.showDialog);
|
||||
|
||||
|
@ -4,8 +4,20 @@ const sanitize = require("sanitize-filename");
|
||||
const TurndownService = require('turndown');
|
||||
|
||||
async function exportSingleMarkdown(note, res) {
|
||||
const turndownService = new TurndownService();
|
||||
const markdown = turndownService.turndown(note.content);
|
||||
if (note.type !== 'text' && note.type !== 'code') {
|
||||
return [400, `Note type ${note.type} cannot be exported as single markdown file.`];
|
||||
}
|
||||
|
||||
let markdown;
|
||||
|
||||
if (note.type === 'code') {
|
||||
markdown = '```\n' + note.content + "\n```";
|
||||
}
|
||||
else if (note.type === 'text') {
|
||||
const turndownService = new TurndownService();
|
||||
markdown = turndownService.turndown(note.content);
|
||||
}
|
||||
|
||||
const name = sanitize(note.title);
|
||||
|
||||
res.setHeader('Content-Disposition', 'file; filename="' + name + '.md"');
|
||||
|
@ -159,7 +159,7 @@
|
||||
<a class="dropdown-item show-attributes-button"><kbd>Alt+A</kbd> Attributes</a>
|
||||
<a class="dropdown-item" id="show-source-button" data-bind="css: { disabled: type() != 'text' }">HTML source</a>
|
||||
<a class="dropdown-item" id="upload-file-button">Upload file</a>
|
||||
<a class="dropdown-item" id="export-note-to-markdown-button" data-bind="css: { disabled: type() != 'text' }">Export as markdown</a>
|
||||
<a class="dropdown-item" id="export-note-to-markdown-button" data-bind="css: { disabled: type() != 'text' && type() != 'code' }">Export as markdown</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user