1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 05:19:57 +00:00

Make markdown wikitext links readable (#8402)

This commit is contained in:
Leilei332 2024-07-19 15:52:57 +08:00 committed by GitHub
parent b48be91ec5
commit bfb9c38c42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,15 +13,15 @@ Text editor operation to make a markdown link
"use strict";
exports["make-markdown-link"] = function(event,operation) {
var rx = /[()\\]/g, rs = '\\$&';
var rx = /[()<>\\]/g, rs = '\\$&';
if(operation.selection) {
var desc = operation.selection.replace(/[\[\]\\]/g, rs);
if(event.paramObject.text.indexOf("://") !== -1) {
operation.replacement = "[" + desc + "](" + event.paramObject.text.replace(rx, rs) + ")";
operation.replacement = "[" + desc + "](" + event.paramObject.text.replace(/[()\\]/g, rs) + ")";
} else {
operation.replacement = "[" + desc + "](#" + encodeURIComponent(event.paramObject.text).replace(rx, rs) + ")";
operation.replacement = "[" + desc + "](<#" + event.paramObject.text.replace(rx, rs) + ">)";
}
operation.cutStart = operation.selStart;
operation.cutEnd = operation.selEnd;
@ -31,7 +31,7 @@ exports["make-markdown-link"] = function(event,operation) {
return encodeURI(m);
}) + ">";
} else {
operation.replacement = "[](#" + encodeURIComponent(event.paramObject.text).replace(rx, rs) + ")";
operation.replacement = "[](<#" + event.paramObject.text.replace(rx, rs) + ">)";
}
operation.cutStart = operation.selStart;
operation.cutEnd = operation.selEnd;