From a960e4f6589ffb05a024c72dd75aaa99952ea6e7 Mon Sep 17 00:00:00 2001 From: Michael McDermott Date: Tue, 10 Sep 2024 09:57:06 -0700 Subject: [PATCH] Make Excision Available for Markdown (#8498) * Updates to make Excision more friendly to Markdown users by adding Markdown as an option in the criteria to use excision and by making the excise operation reuse the type of the tiddler being excised. * Updated excise operation to use Markdown syntax for links. --- core/modules/editor/operations/text/excise.js | 11 +++++++++-- core/ui/EditorToolbar/excise.tid | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/modules/editor/operations/text/excise.js b/core/modules/editor/operations/text/excise.js index 8cb3a8486..bb5840c2e 100644 --- a/core/modules/editor/operations/text/excise.js +++ b/core/modules/editor/operations/text/excise.js @@ -12,9 +12,14 @@ Text editor operation to excise the selection to a new tiddler /*global $tw: false */ "use strict"; +function isMarkdown(mediaType) { + return mediaType === 'text/markdown' || mediatype === 'text/x-markdown'; +} + exports["excise"] = function(event,operation) { var editTiddler = this.wiki.getTiddler(this.editTitle), editTiddlerTitle = this.editTitle, + wikiLinks = !isMarkdown(editTiddler.fields.type), excisionBaseTitle = $tw.language.getString("Buttons/Excise/DefaultTitle"); if(editTiddler && editTiddler.fields["draft.of"]) { editTiddlerTitle = editTiddler.fields["draft.of"]; @@ -26,7 +31,8 @@ exports["excise"] = function(event,operation) { { title: excisionTitle, text: operation.selection, - tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : [] + tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : [], + type: editTiddler.fields.type } )); operation.replacement = excisionTitle; @@ -35,7 +41,8 @@ exports["excise"] = function(event,operation) { operation.replacement = "{{" + operation.replacement+ "}}"; break; case "link": - operation.replacement = "[[" + operation.replacement+ "]]"; + operation.replacement = wikiLinks ? "[[" + operation.replacement+ "]]" + : ("[" + operation.replacement + "](<#" + operation.replacement + ">)"); break; case "macro": operation.replacement = "<<" + (event.paramObject.macro || "translink") + " \"\"\"" + operation.replacement + "\"\"\">>"; diff --git a/core/ui/EditorToolbar/excise.tid b/core/ui/EditorToolbar/excise.tid index fe5c5288b..8bb17edd5 100644 --- a/core/ui/EditorToolbar/excise.tid +++ b/core/ui/EditorToolbar/excise.tid @@ -3,7 +3,7 @@ tags: $:/tags/EditorToolbar icon: $:/core/images/excise caption: {{$:/language/Buttons/Excise/Caption}} description: {{$:/language/Buttons/Excise/Hint}} -condition: [type[]] [get[type]prefix[text/vnd.tiddlywiki]] +[first[]] +condition: [type[]] [type[text/vnd.tiddlywiki]] [type[text/markdown]] [type[text/x-markdown]] +[first[]] shortcuts: ((excise)) dropdown: $:/core/ui/EditorToolbar/excise-dropdown