Skip to content

Commit

Permalink
markedjs#333 open links in a new tab and add 'basePath' support for r…
Browse files Browse the repository at this point in the history
…elative links in markdown content dev
  • Loading branch information
nalinchhibber committed Mar 21, 2016
1 parent 88ce4df commit 670395f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,11 @@ Renderer.prototype.link = function(href, title, text) {
return '';
}
}
var out = '<a href="' + href + '"';
/*******************************************
* comproDLS Changes
* open links in a new tab.
*********************************************/
var out = '<a target="_blank" href="' + href + '"';
if (title) {
out += ' title="' + title + '"';
}
Expand All @@ -888,6 +892,15 @@ Renderer.prototype.link = function(href, title, text) {
};

Renderer.prototype.image = function(href, title, text) {
/*******************************************
* comproDLS Changes
* Check if href is relative or absolute URL (Starts with http ot https).
* If relative URL, append basePath in starting.
*********************************************/
var pat = /^https?:\/\//i;
if(!pat.test(href)){
href = marked.defaults.basePath + href;
}
var out = '<img src="' + href + '" alt="' + text + '"';
if (title) {
out += ' title="' + title + '"';
Expand Down Expand Up @@ -1214,7 +1227,10 @@ function marked(src, opt, callback) {
return;
}
try {
if (opt) opt = merge({}, marked.defaults, opt);
if (opt){
opt = merge({}, marked.defaults, opt);
marked.defaults.basePath = opt.basePath || '';
};
return Parser.parse(Lexer.lex(src, opt), opt);
} catch (e) {
e.message += '\nPlease report this to https://github.com/chjj/marked.';
Expand Down Expand Up @@ -1252,7 +1268,8 @@ marked.defaults = {
smartypants: false,
headerPrefix: '',
renderer: new Renderer,
xhtml: false
xhtml: false,
basePath: '',
};

/**
Expand Down

0 comments on commit 670395f

Please sign in to comment.