diff --git a/lib/rules_core/replacements.js b/lib/rules_core/replacements.js index 517afc9..a748b31 100644 --- a/lib/rules_core/replacements.js +++ b/lib/rules_core/replacements.js @@ -34,22 +34,32 @@ function replaceFn(match, name) { } function replace_scoped(inlineTokens) { - var i, token; + var i, token, inside_autolink = 0; for (i = inlineTokens.length - 1; i >= 0; i--) { token = inlineTokens[i]; - if (token.type === 'text') { + + if (token.type === 'text' && !inside_autolink) { token.content = token.content.replace(SCOPED_ABBR_RE, replaceFn); } + + if (token.type === 'link_open' && token.info === 'auto') { + inside_autolink--; + } + + if (token.type === 'link_close' && token.info === 'auto') { + inside_autolink++; + } } } function replace_rare(inlineTokens) { - var i, token; + var i, token, inside_autolink = 0; for (i = inlineTokens.length - 1; i >= 0; i--) { token = inlineTokens[i]; - if (token.type === 'text') { + + if (token.type === 'text' && !inside_autolink) { if (RARE_RE.test(token.content)) { token.content = token.content .replace(/\+-/g, '±') @@ -64,6 +74,14 @@ function replace_rare(inlineTokens) { .replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); } } + + if (token.type === 'link_open' && token.info === 'auto') { + inside_autolink--; + } + + if (token.type === 'link_close' && token.info === 'auto') { + inside_autolink++; + } } } diff --git a/test/fixtures/markdown-it/linkify.txt b/test/fixtures/markdown-it/linkify.txt index c093574..1e86cac 100644 --- a/test/fixtures/markdown-it/linkify.txt +++ b/test/fixtures/markdown-it/linkify.txt @@ -53,5 +53,5 @@ typorgapher should not break href . http://example.com/(c) . -

http://example.com/©

+

http://example.com/(c)

. diff --git a/test/fixtures/markdown-it/normalize.txt b/test/fixtures/markdown-it/normalize.txt index 296b296..14fa2a9 100644 --- a/test/fixtures/markdown-it/normalize.txt +++ b/test/fixtures/markdown-it/normalize.txt @@ -32,7 +32,7 @@ Invalid punycode: . . -

http://xn–xn.com/

+

http://xn--xn.com/

. Invalid punycode (non-ascii): @@ -40,7 +40,7 @@ Invalid punycode (non-ascii): . . -

http://xn–γ.com/

+

http://xn--γ.com/

. Two slashes should start a domain: @@ -96,5 +96,5 @@ test xn--n3h.net foo . test xn--n3h@xn--n3h.net foo . -

test xn–n3h@☃.net foo

+

test xn--n3h@☃.net foo

.