mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
TextSlicer: Fix external links
This commit is contained in:
parent
33453039fc
commit
f0b7c9a3d5
@ -311,18 +311,32 @@ 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;
|
||||||
|
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],
|
base = parts[0],
|
||||||
hash = parts[1] || "",
|
hash = parts[1] || "",
|
||||||
title = $tw.utils.resolvePath(base,this.baseTiddlerTitle) + "-anchor-" + hash;
|
title = $tw.utils.resolvePath(base,this.baseTiddlerTitle) + "-anchor-" + hash;
|
||||||
this.addTextToCurrentChunk("<$link to=\"" + title + "\">");
|
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) {
|
||||||
|
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>");
|
this.addTextToCurrentChunk("</$link>");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Slicer.prototype.onOpenImage = function(node) {
|
Slicer.prototype.onOpenImage = function(node) {
|
||||||
|
Loading…
Reference in New Issue
Block a user