Skip to content

Commit

Permalink
Add option to overwrite the default prefilter for links
Browse files Browse the repository at this point in the history
  • Loading branch information
Leandro Balmaceda committed Dec 5, 2016
1 parent a92f0a1 commit 66da440
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/configs/commonmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module.exports = {
linkify: false, // autoconvert URL-like texts to links
linkTarget: '', // set target to open link in

// linkifyPrefilter. Function that overwrite the default link prefilter,
// specified by this regex: /www|@|\:\/\//
//
// @param { string } link that will be tested.
// @returns { Boolean } whether or not the link passes the prefilter.
linkifyPrefilter: null,

// Enable some language-neutral replacements + quotes beautification
typographer: false,

Expand Down
7 changes: 7 additions & 0 deletions lib/configs/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module.exports = {
linkify: false, // autoconvert URL-like texts to links
linkTarget: '', // set target to open link in

// linkifyPrefilter. Function that overwrite the default link prefilter,
// specified by this regex: /www|@|\:\/\//
//
// @param { string } link that will be tested.
// @returns { Boolean } whether or not the link passes the prefilter.
linkifyPrefilter: null,

// Enable some language-neutral replacements + quotes beautification
typographer: false,

Expand Down
7 changes: 7 additions & 0 deletions lib/configs/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ module.exports = {
linkify: false, // autoconvert URL-like texts to links
linkTarget: '', // set target to open link in

// linkifyPrefilter. Function that overwrite the default link prefilter,
// specified by this regex: /www|@|\:\/\//
//
// @param { string } link that will be tested.
// @returns { Boolean } whether or not the link passes the prefilter.
linkifyPrefilter: null,

// Enable some language-neutral replacements + quotes beautification
typographer: false,

Expand Down
9 changes: 8 additions & 1 deletion lib/rules_core/linkify.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ module.exports = function linkify(state) {
}
if (htmlLinkLevel > 0) { continue; }

if (token.type === 'text' && LINK_SCAN_RE.test(token.content)) {
var linkifyPrefilter = state.options.linkifyPrefilter;
var passPrefilter = LINK_SCAN_RE.test(token.content);
if (linkifyPrefilter && typeof linkifyPrefilter === 'function') {
// Use the custom prefilter for links.
passPrefilter = linkifyPrefilter(token.content);
}

if (token.type === 'text' && passPrefilter) {

// Init linkifier in lazy manner, only if required.
if (!linkifier) {
Expand Down

0 comments on commit 66da440

Please sign in to comment.