Skip to content

Commit 702bef8

Browse files
author
Vishal Kadam
committed
Added option to wrap link a link tag
1 parent 8097dee commit 702bef8

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

extension/pages/options.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ <h2>Add-ons</h2>
4848
<li>
4949
<strong>"clickableUrls"</strong> - <span class="hint">Make URLs clickable (boolean). Default true</span>
5050
</li>
51+
<li>
52+
<strong>"wrapLinkWithAnchorTag"</strong> - <span class="hint">Add URLs as anchor tag (boolean). Default false</span>
53+
</li>
5154
<li>
5255
<strong>"openLinksInNewWindow"</strong> - <span class="hint">Open URLs in the same window/tab (boolean). Default true</span>
5356
</li>

extension/src/json-viewer/highlighter.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ Highlighter.prototype = {
9191
elements.forEach(function(node) {
9292
node.classList.add("cm-string-link");
9393
node.setAttribute("data-url", decodedText);
94+
if (self.wrapLinkWithAnchorTag()) {
95+
var linkTag = document.createElement("a");
96+
linkTag.href = decodedText;
97+
linkTag.setAttribute('target', '_blank')
98+
linkTag.innerHTML = decodedText;
99+
node.innerHTML = "";
100+
node.appendChild(linkTag);
101+
}
94102
});
95103
}
96104
});
@@ -200,6 +208,10 @@ Highlighter.prototype = {
200208
return this.options.addons.clickableUrls;
201209
},
202210

211+
wrapLinkWithAnchorTag: function() {
212+
return this.options.addons.wrapLinkWithAnchorTag;
213+
},
214+
203215
openLinksInNewWindow: function() {
204216
return this.options.addons.openLinksInNewWindow;
205217
},

extension/src/json-viewer/options/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
alwaysRenderAllContent: false,
88
sortKeys: false,
99
clickableUrls: true,
10+
wrapLinkWithAnchorTag: false,
1011
openLinksInNewWindow: true,
1112
autoHighlight: true
1213
},

0 commit comments

Comments
 (0)