Skip to content

Commit

Permalink
refactor(external_link): relpace test() with includes()
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 6, 2019
1 parent 6d9ed7a commit 216f653
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/plugins/filter/after_post_render/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function externalLinkFilter(data) {
: [config.external_link.exclude];

data.content = data.content.replace(/<a.*?(href=['"](.*?)['"]).*?>/gi, (str, hrefStr, href) => {
if (/target=/gi.test(str) || !isExternal(href, config)) return str;
if (str.includes('target=') || !isExternal(href, config)) return str;

if (/rel=/gi.test(str)) {
if (str.includes('rel=')) {
str = str.replace(/rel="(.*?)"/gi, (relStr, rel) => {
if (!rel.includes('noopenner')) relStr = relStr.replace(rel, `${rel} noopener`);
return relStr;
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/filter/after_render/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function externalLinkFilter(data) {
: [config.external_link.exclude];

data = data.replace(/<a.*?(href=['"](.*?)['"]).*?>/gi, (str, hrefStr, href) => {
if (/target=/gi.test(str) || !isExternal(href, config)) return str;
if (str.includes('target=') || !isExternal(href, config)) return str;

if (/rel=/gi.test(str)) {
if (str.includes('rel=')) {
str = str.replace(/rel="(.*?)"/gi, (relStr, rel) => {
if (!rel.includes('noopenner')) relStr = relStr.replace(rel, `${rel} noopener`);
return relStr;
Expand Down

0 comments on commit 216f653

Please sign in to comment.