1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-21 03:39:43 +00:00

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.
This commit is contained in:
Michael McDermott 2024-09-10 09:57:06 -07:00 committed by GitHub
parent 40138beac4
commit a960e4f658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 3 deletions

View File

@ -12,9 +12,14 @@ Text editor operation to excise the selection to a new tiddler
/*global $tw: false */ /*global $tw: false */
"use strict"; "use strict";
function isMarkdown(mediaType) {
return mediaType === 'text/markdown' || mediatype === 'text/x-markdown';
}
exports["excise"] = function(event,operation) { exports["excise"] = function(event,operation) {
var editTiddler = this.wiki.getTiddler(this.editTitle), var editTiddler = this.wiki.getTiddler(this.editTitle),
editTiddlerTitle = this.editTitle, editTiddlerTitle = this.editTitle,
wikiLinks = !isMarkdown(editTiddler.fields.type),
excisionBaseTitle = $tw.language.getString("Buttons/Excise/DefaultTitle"); excisionBaseTitle = $tw.language.getString("Buttons/Excise/DefaultTitle");
if(editTiddler && editTiddler.fields["draft.of"]) { if(editTiddler && editTiddler.fields["draft.of"]) {
editTiddlerTitle = editTiddler.fields["draft.of"]; editTiddlerTitle = editTiddler.fields["draft.of"];
@ -26,7 +31,8 @@ exports["excise"] = function(event,operation) {
{ {
title: excisionTitle, title: excisionTitle,
text: operation.selection, text: operation.selection,
tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : [] tags: event.paramObject.tagnew === "yes" ? [editTiddlerTitle] : [],
type: editTiddler.fields.type
} }
)); ));
operation.replacement = excisionTitle; operation.replacement = excisionTitle;
@ -35,7 +41,8 @@ exports["excise"] = function(event,operation) {
operation.replacement = "{{" + operation.replacement+ "}}"; operation.replacement = "{{" + operation.replacement+ "}}";
break; break;
case "link": case "link":
operation.replacement = "[[" + operation.replacement+ "]]"; operation.replacement = wikiLinks ? "[[" + operation.replacement+ "]]"
: ("[" + operation.replacement + "](<#" + operation.replacement + ">)");
break; break;
case "macro": case "macro":
operation.replacement = "<<" + (event.paramObject.macro || "translink") + " \"\"\"" + operation.replacement + "\"\"\">>"; operation.replacement = "<<" + (event.paramObject.macro || "translink") + " \"\"\"" + operation.replacement + "\"\"\">>";

View File

@ -3,7 +3,7 @@ tags: $:/tags/EditorToolbar
icon: $:/core/images/excise icon: $:/core/images/excise
caption: {{$:/language/Buttons/Excise/Caption}} caption: {{$:/language/Buttons/Excise/Caption}}
description: {{$:/language/Buttons/Excise/Hint}} description: {{$:/language/Buttons/Excise/Hint}}
condition: [<targetTiddler>type[]] [<targetTiddler>get[type]prefix[text/vnd.tiddlywiki]] +[first[]] condition: [<targetTiddler>type[]] [<targetTiddler>type[text/vnd.tiddlywiki]] [<targetTiddler>type[text/markdown]] [<targetTiddler>type[text/x-markdown]] +[first[]]
shortcuts: ((excise)) shortcuts: ((excise))
dropdown: $:/core/ui/EditorToolbar/excise-dropdown dropdown: $:/core/ui/EditorToolbar/excise-dropdown