mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-10 20:09:57 +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:
parent
40138beac4
commit
a960e4f658
@ -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 + "\"\"\">>";
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user