Skip to content

Commit

Permalink
Add target="_blank" and rel="noopener" to external links
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomersiva committed Dec 18, 2018
1 parent 789f2cb commit d941964
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/utils/generateHtmlFromMd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const sharp = require('sharp');
const markdownIt = require('markdown-it');
const markdownItContainer = require('markdown-it-container');
const frontMatter = require('markdown-it-front-matter');
const mila = require('markdown-it-link-attributes')

const yamlToObject = require('./yamlToObject');
const { LAYOUTS, BUILD } = require('./constants');
Expand Down Expand Up @@ -107,6 +108,13 @@ const md = markdownIt(mdOptions)

return '';
}
})
.use(mila, {
pattern: /^https?:\/\//,
attrs: {
target: '_blank',
rel: 'noopener'
}
});

module.exports = function(pageContents) {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"markdown-it": "^8.4.2",
"markdown-it-container": "^2.0.0",
"markdown-it-front-matter": "^0.1.2",
"markdown-it-link-attributes": "^2.1.0",
"node-version-assets": "^1.2.2",
"postcss": "^7.0.1",
"postcss-preset-env": "^6.4.0",
Expand Down

0 comments on commit d941964

Please sign in to comment.