1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-22 21:33:14 +00:00

TextSlicer: Fix external links

This commit is contained in:
Jermolene 2018-05-17 18:30:21 +01:00
parent 33453039fc
commit f0b7c9a3d5

View File

@ -311,17 +311,31 @@ Slicer.prototype.onOpenTag = function(node) {
Slicer.prototype.onOpenAnchor = function(node) {
if(node.attributes.href) {
var parts = node.attributes.href.value.split("#"),
base = parts[0],
hash = parts[1] || "",
title = $tw.utils.resolvePath(base,this.baseTiddlerTitle) + "-anchor-" + hash;
this.addTextToCurrentChunk("<$link to=\"" + title + "\">");
var value = node.attributes.href.value;
if(value.indexOf("https://") === 0 || value.indexOf("http://") === 0) {
// External link
this.addTextToCurrentChunk("<a href=\"" + value + "\" target=\"_blank\" rel=\"noopener noreferrer\">");
} else {
// Internal link
var parts = value.split("#"),
base = parts[0],
hash = parts[1] || "",
title = $tw.utils.resolvePath(base,this.baseTiddlerTitle) + "-anchor-" + hash;
this.addTextToCurrentChunk("<$link to=\"" + title + "\">");
}
}
};
Slicer.prototype.onCloseAnchor = function(elementInfo) {
if(elementInfo.node.attributes.href) {
this.addTextToCurrentChunk("</$link>");
var value = elementInfo.node.attributes.href.value;
if(value.indexOf("https://") === 0 || value.indexOf("http://") === 0) {
// External link
this.addTextToCurrentChunk("</a>");
} else {
// Internal link
this.addTextToCurrentChunk("</$link>");
}
}
};