1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +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) { Slicer.prototype.onOpenAnchor = function(node) {
if(node.attributes.href) { if(node.attributes.href) {
var parts = node.attributes.href.value.split("#"), var value = node.attributes.href.value;
base = parts[0], if(value.indexOf("https://") === 0 || value.indexOf("http://") === 0) {
hash = parts[1] || "", // External link
title = $tw.utils.resolvePath(base,this.baseTiddlerTitle) + "-anchor-" + hash; this.addTextToCurrentChunk("<a href=\"" + value + "\" target=\"_blank\" rel=\"noopener noreferrer\">");
this.addTextToCurrentChunk("<$link to=\"" + title + "\">"); } 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) { Slicer.prototype.onCloseAnchor = function(elementInfo) {
if(elementInfo.node.attributes.href) { 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>");
}
} }
}; };