diff --git a/astro.config.mjs b/astro.config.mjs index b3abe04a7..eaa55e0d8 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -19,7 +19,7 @@ import rehypeImageFallback from "./src/plugins/rehype-image-fallback.mjs"; import { parseDirectiveNode } from "./src/plugins/remark-directive-rehype.js"; import { remarkExcerpt } from "./src/plugins/remark-excerpt.js"; import { remarkReadingTime } from "./src/plugins/remark-reading-time.mjs"; - +import rehypeExternalLinks from 'rehype-external-links'; import expressiveCode from "astro-expressive-code"; import { pluginCollapsibleSections } from "@expressive-code/plugin-collapsible-sections"; import { pluginLineNumbers } from "@expressive-code/plugin-line-numbers"; @@ -128,6 +128,12 @@ export default defineConfig({ }, }, ], + [ + rehypeExternalLinks, + { + target: '_blank', + }, + ], [ rehypeAutolinkHeadings, { diff --git a/package.json b/package.json index 1d2c5bd64..46166e980 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "reading-time": "^1.5.0", "rehype-autolink-headings": "^7.1.0", "rehype-components": "^0.3.0", + "rehype-external-links": "^3.0.0", "rehype-katex": "^7.0.1", "rehype-slug": "^6.0.0", "remark-directive": "^3.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 08f2a9c1c..f6894dcbf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -104,6 +104,9 @@ importers: rehype-components: specifier: ^0.3.0 version: 0.3.0 + rehype-external-links: + specifier: ^3.0.0 + version: 3.0.0 rehype-katex: specifier: ^7.0.1 version: 7.0.1 @@ -2949,6 +2952,10 @@ packages: iron-webcrypto@1.2.1: resolution: {integrity: sha512-feOM6FaSr6rEABp/eDfVseKyTMDt+KGpeB35SkVn9Tyn0CqvVsY3EwI0v5i8nMHyJnzCIQf7nsy3p41TPkJZhg==} + is-absolute-url@4.0.1: + resolution: {integrity: sha512-/51/TKE88Lmm7Gc4/8btclNXWS+g50wXhYJq8HWIBAGUBnoAdRu1aXeh364t/O7wXDAcTJDP8PNuNKWUDWie+A==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + is-alphabetical@2.0.1: resolution: {integrity: sha512-FWyyY60MeTNyeSRpkM2Iry0G9hpr7/9kD40mD/cGQEuilcZYS4okz8SN2Q6rLCJ8gbCt6fN+rC+6tMGS99LaxQ==} @@ -4234,6 +4241,9 @@ packages: rehype-expressive-code@0.41.3: resolution: {integrity: sha512-8d9Py4c/V6I/Od2VIXFAdpiO2kc0SV2qTJsRAaqSIcM9aruW4ASLNe2kOEo1inXAAkIhpFzAHTc358HKbvpNUg==} + rehype-external-links@3.0.0: + resolution: {integrity: sha512-yp+e5N9V3C6bwBeAC4n796kc86M4gJCdlVhiMTxIrJG5UHDMh+PJANf9heqORJbt1nrCbDwIlAZKjANIaVBbvw==} + rehype-katex@7.0.1: resolution: {integrity: sha512-OiM2wrZ/wuhKkigASodFoo8wimG3H12LWQaH8qSPVJn9apWKFSH3YOCtbKpBorTVw/eI7cuT21XBbvwEswbIOA==} @@ -8487,6 +8497,8 @@ snapshots: iron-webcrypto@1.2.1: {} + is-absolute-url@4.0.1: {} + is-alphabetical@2.0.1: {} is-alphanumerical@2.0.1: @@ -9961,6 +9973,15 @@ snapshots: dependencies: expressive-code: 0.41.3 + rehype-external-links@3.0.0: + dependencies: + '@types/hast': 3.0.4 + '@ungap/structured-clone': 1.3.0 + hast-util-is-element: 3.0.0 + is-absolute-url: 4.0.1 + space-separated-tokens: 2.0.2 + unist-util-visit: 5.0.0 + rehype-katex@7.0.1: dependencies: '@types/hast': 3.0.4