Skip to content

Commit

Permalink
docs: adds markdown-it plugin to automatically set all external links…
Browse files Browse the repository at this point in the history
… to _blank
  • Loading branch information
toastedtoast committed Feb 21, 2023
1 parent b030906 commit 18962a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
10 changes: 10 additions & 0 deletions config/.eleventy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight')
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
const markdownItReplaceLink = require('markdown-it-replace-link')
const markdownItLinkAttributes = require('markdown-it-link-attributes')
const pluginTOC = require('eleventy-plugin-toc')
const cheerio = require('cheerio')
const memoize = require('lodash.memoize')
Expand Down Expand Up @@ -110,6 +111,15 @@ module.exports = function (eleventyConfig) {
permalink: renderPermalink,
})
.use(markdownItReplaceLink)
.use(markdownItLinkAttributes, {
matcher(href) {
return href.match(/^https?:\/\//)
},
attrs: {
target: '_blank',
rel: 'noopener noreferrer',
},
})
)
eleventyConfig.addPassthroughCopy(
buildstamp
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@
"lint-staged": "^13.1.2",
"live-server": "1.2.2",
"lodash.memoize": "^4.1.2",
"markdown-it-anchor": "^8.6.6",
"markdown-it-replace-link": "^1.2.0",
"markdown-it-anchor": "^8.6.5",
"markdown-it-link-attributes": "^4.0.1",
"markdown-it-replace-link": "^1.1.0",
"mutation-observer": "^1.0.3",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.21",
Expand Down
16 changes: 12 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,9 @@ __metadata:
lint-staged: ^13.1.2
live-server: 1.2.2
lodash.memoize: ^4.1.2
markdown-it-anchor: ^8.6.6
markdown-it-replace-link: ^1.2.0
markdown-it-anchor: ^8.6.5
markdown-it-link-attributes: ^4.0.1
markdown-it-replace-link: ^1.1.0
mutation-observer: ^1.0.3
npm-run-all: ^4.1.5
postcss: ^8.4.21
Expand Down Expand Up @@ -10371,7 +10372,7 @@ cors@latest:
languageName: node
linkType: hard

"markdown-it-anchor@npm:^8.6.6":
"markdown-it-anchor@npm:^8.6.5":
version: 8.6.7
resolution: "markdown-it-anchor@npm:8.6.7"
peerDependencies:
Expand All @@ -10381,7 +10382,14 @@ cors@latest:
languageName: node
linkType: hard

"markdown-it-replace-link@npm:^1.2.0":
"markdown-it-link-attributes@npm:^4.0.1":
version: 4.0.1
resolution: "markdown-it-link-attributes@npm:4.0.1"
checksum: e859b0a3653998b7acddaf5e37052a00e940150d76b0275322e133a14179979c3516692610df75553f3b2e5d4010e1e5138f10bc85efab4768b9293a5b39f0a6
languageName: node
linkType: hard

"markdown-it-replace-link@npm:^1.1.0":
version: 1.2.0
resolution: "markdown-it-replace-link@npm:1.2.0"
dependencies:
Expand Down

0 comments on commit 18962a8

Please sign in to comment.