1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-17 15:57:14 +00:00

Markdown: Add separate link and linkify buttons (#6693)

* Markdown: Add separate link and linkify buttons

* Add Markdown linkify icon (created by Jeremy); cleanup
This commit is contained in:
Max Schillinger
2022-05-15 18:47:21 +02:00
committed by GitHub
parent 91cfb217d8
commit 855b6719d6
5 changed files with 139 additions and 12 deletions

View File

@@ -0,0 +1,37 @@
/*\
title: $:/plugins/tiddlywiki/markdown/editor-operations/make-markdown-link.js
type: application/javascript
module-type: texteditoroperation
Text editor operation to make a markdown link
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
exports["make-markdown-link"] = function(event,operation) {
if(operation.selection) {
if(event.paramObject.text.includes("://")) {
operation.replacement = "[" + operation.selection + "](" + event.paramObject.text + ")";
} else {
operation.replacement = "[" + operation.selection + "](#" + event.paramObject.text.replaceAll(" ", "%20") + ")";
}
operation.cutStart = operation.selStart;
operation.cutEnd = operation.selEnd;
} else {
if(event.paramObject.text.includes("://")) {
operation.replacement = "<" + event.paramObject.text + ">";
} else {
operation.replacement = "[](#" + event.paramObject.text.replaceAll(" ", "%20") + ")";
}
operation.cutStart = operation.selStart;
operation.cutEnd = operation.selEnd;
}
operation.newSelStart = operation.selStart + operation.replacement.length;
operation.newSelEnd = operation.newSelStart;
};
})();