Skip to content

Commit 66da440

Browse files
author
Leandro Balmaceda
committed
Add option to overwrite the default prefilter for links
1 parent a92f0a1 commit 66da440

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

lib/configs/commonmark.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ module.exports = {
1212
linkify: false, // autoconvert URL-like texts to links
1313
linkTarget: '', // set target to open link in
1414

15+
// linkifyPrefilter. Function that overwrite the default link prefilter,
16+
// specified by this regex: /www|@|\:\/\//
17+
//
18+
// @param { string } link that will be tested.
19+
// @returns { Boolean } whether or not the link passes the prefilter.
20+
linkifyPrefilter: null,
21+
1522
// Enable some language-neutral replacements + quotes beautification
1623
typographer: false,
1724

lib/configs/default.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ module.exports = {
1212
linkify: false, // autoconvert URL-like texts to links
1313
linkTarget: '', // set target to open link in
1414

15+
// linkifyPrefilter. Function that overwrite the default link prefilter,
16+
// specified by this regex: /www|@|\:\/\//
17+
//
18+
// @param { string } link that will be tested.
19+
// @returns { Boolean } whether or not the link passes the prefilter.
20+
linkifyPrefilter: null,
21+
1522
// Enable some language-neutral replacements + quotes beautification
1623
typographer: false,
1724

lib/configs/full.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ module.exports = {
1212
linkify: false, // autoconvert URL-like texts to links
1313
linkTarget: '', // set target to open link in
1414

15+
// linkifyPrefilter. Function that overwrite the default link prefilter,
16+
// specified by this regex: /www|@|\:\/\//
17+
//
18+
// @param { string } link that will be tested.
19+
// @returns { Boolean } whether or not the link passes the prefilter.
20+
linkifyPrefilter: null,
21+
1522
// Enable some language-neutral replacements + quotes beautification
1623
typographer: false,
1724

lib/rules_core/linkify.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,14 @@ module.exports = function linkify(state) {
9595
}
9696
if (htmlLinkLevel > 0) { continue; }
9797

98-
if (token.type === 'text' && LINK_SCAN_RE.test(token.content)) {
98+
var linkifyPrefilter = state.options.linkifyPrefilter;
99+
var passPrefilter = LINK_SCAN_RE.test(token.content);
100+
if (linkifyPrefilter && typeof linkifyPrefilter === 'function') {
101+
// Use the custom prefilter for links.
102+
passPrefilter = linkifyPrefilter(token.content);
103+
}
104+
105+
if (token.type === 'text' && passPrefilter) {
99106

100107
// Init linkifier in lazy manner, only if required.
101108
if (!linkifier) {

0 commit comments

Comments
 (0)