Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linksInNewTab config option #1030

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ marked.setOptions({
sanitize: false,
smartLists: true,
smartypants: false,
xhtml: false
xhtml: false,
linksInNewTab: false
});

console.log(marked('I am using __markdown__.'));
Expand Down Expand Up @@ -282,6 +283,13 @@ Default: `false`

Self-close the tags for void elements (<br/>, <img/>, etc.) with a "/" as required by XHTML.

### linksInNewTab

Type: `boolean`
Default: `false`

Opens links in new tabs.

## Access to lexer and parser

You also have direct access to the lexer and parser if you so desire.
Expand Down
6 changes: 6 additions & 0 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ Renderer.prototype.link = function(href, title, text) {
if (title) {
out += ' title="' + title + '"';
}

if (this.options.linksInNewTab) {
out += ' target="_blank"';
}

out += '>' + text + '</a>';
return out;
};
Expand Down Expand Up @@ -1331,6 +1336,7 @@ marked.defaults = {
headerPrefix: '',
renderer: new Renderer,
xhtml: false,
linksInNewTab: false,
baseUrl: null
};

Expand Down
1 change: 1 addition & 0 deletions test/new/linksinnewtab.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p><a href="https://www.google.com" target="_blank">Google</a></p>
4 changes: 4 additions & 0 deletions test/new/linksinnewtab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
linksInNewTab: true
---
[Google](https://www.google.com)