Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/icewind1991/files_markdown.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-01-23 13:26:18 +0300
committerRobin Appelman <robin@icewind.nl>2017-01-23 13:26:18 +0300
commit1d47754b86fe0ede2b653f4c816d136ba3853dec (patch)
tree32dc99658cbbd0d789c63d3f780db548b00c9b19 /js
parenta64fa41f3b613bbd66aae32f9513b907d8341af2 (diff)
open links to different domains in a new tab
Fixes #19 Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'js')
-rw-r--r--js/editor.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/js/editor.js b/js/editor.js
index cd88fce..b8e44eb 100644
--- a/js/editor.js
+++ b/js/editor.js
@@ -22,6 +22,7 @@ OCA.Files_Markdown.Preview.prototype.init = function () {
OCA.Files_Markdown.Preview.loadKaTeX()
).then(function () {
this.renderer = new marked.Renderer();
+ var linkRenderer = this.renderer.link.bind(this.renderer);
this.renderer.image = function (href, title, text) {
var out = '<img src="' + getUrl(href) + '" alt="' + text + '"';
if (title) {
@@ -30,6 +31,17 @@ OCA.Files_Markdown.Preview.prototype.init = function () {
out += this.options.xhtml ? '/>' : '>';
return out;
};
+ this.renderer.link = function(href, title, text) {
+ var rendered = linkRenderer(href, title, text);
+ var parser = document.createElement('a');
+ parser.href = href;
+ console.log(parser.hostname);
+ if (parser.hostname !== window.location.hostname) {
+ return rendered.replace("href=","target='_blank' rel='noopener' href=");
+ } else {
+ return rendered;
+ }
+ };
this.renderer.code = function (code, language) {
// Check whether the given language is valid for highlight.js.