mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-19 08:14:50 +00:00
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
|
/*\
|
||
|
title: $:/plugins/tiddlywiki/markdown-legacy/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.indexOf("://") !== -1) {
|
||
|
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.indexOf("://") !== -1) {
|
||
|
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;
|
||
|
};
|
||
|
|
||
|
})();
|