diff --git a/lib/configs/commonmark.js b/lib/configs/commonmark.js index 40d8c1d0..a13a7272 100644 --- a/lib/configs/commonmark.js +++ b/lib/configs/commonmark.js @@ -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, diff --git a/lib/configs/default.js b/lib/configs/default.js index ae01184b..7dee16bb 100644 --- a/lib/configs/default.js +++ b/lib/configs/default.js @@ -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, diff --git a/lib/configs/full.js b/lib/configs/full.js index f1ac24d6..d39c2835 100644 --- a/lib/configs/full.js +++ b/lib/configs/full.js @@ -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, diff --git a/lib/rules_core/linkify.js b/lib/rules_core/linkify.js index e9bc88c5..245e2b69 100644 --- a/lib/rules_core/linkify.js +++ b/lib/rules_core/linkify.js @@ -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) {