Skip to content

Commit debafc2

Browse files
committed
re-enable target names for extern links
1 parent 1da1caa commit debafc2

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"react-inlinesvg": "^3.0.3",
9797
"react-markdown": "^10.1.0",
9898
"react-syntax-highlighter": "^15.6.1",
99+
"rehype-external-links": "^3.0.0",
99100
"rehype-raw": "^7.0.0",
100101
"remark-definition-list": "^2.0.0",
101102
"remark-gfm": "^4.0.1",

src/cmem/markdown/Markdown.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ReactMarkdown from "react-markdown";
33
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
44
// @ts-ignore: No declaration file for module (TODO: should be @ts-expect-error but GUI elements is used inside project with `noImplicitAny=false`)
55
import remarkTypograf from "@mavrin/remark-typograf";
6+
import rehypeExternalLinks from "rehype-external-links";
67
import rehypeRaw from "rehype-raw";
78
import { remarkDefinitionList } from "remark-definition-list";
89
import remarkGfm from "remark-gfm";
@@ -118,6 +119,13 @@ export const Markdown = ({
118119
htmlContentBlockProps,
119120
...otherProps
120121
}: MarkdownProps) => {
122+
const configHtmlExternalLinks = {
123+
rel: ["nofollow"],
124+
target: linkTargetName,
125+
};
126+
127+
configDefault.rehypePlugins = configDefault.rehypePlugins.concat([[rehypeExternalLinks, configHtmlExternalLinks]]);
128+
121129
const configHtml = allowHtml
122130
? {
123131
rehypePlugins: [...configDefault.rehypePlugins].concat([rehypeRaw]),
@@ -155,7 +163,6 @@ export const Markdown = ({
155163
}}
156164
children={String(children).replace(/\n$/, "")}
157165
language={match[1]}
158-
target={linkTargetName}
159166
/>
160167
) : (
161168
<code {...rest} className={className}>

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6549,6 +6549,11 @@ invariant@^2.2.3:
65496549
dependencies:
65506550
loose-envify "^1.0.0"
65516551

6552+
is-absolute-url@^4.0.0:
6553+
version "4.0.1"
6554+
resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-4.0.1.tgz#16e4d487d4fded05cfe0685e53ec86804a5e94dc"
6555+
integrity sha512-/51/TKE88Lmm7Gc4/8btclNXWS+g50wXhYJq8HWIBAGUBnoAdRu1aXeh364t/O7wXDAcTJDP8PNuNKWUDWie+A==
6556+
65526557
is-alphabetical@^1.0.0:
65536558
version "1.0.4"
65546559
resolved "https://registry.yarnpkg.com/is-alphabetical/-/is-alphabetical-1.0.4.tgz#9e7d6b94916be22153745d184c298cbf986a686d"
@@ -9624,6 +9629,18 @@ regjsparser@^0.12.0:
96249629
dependencies:
96259630
jsesc "~3.0.2"
96269631

9632+
rehype-external-links@^3.0.0:
9633+
version "3.0.0"
9634+
resolved "https://registry.yarnpkg.com/rehype-external-links/-/rehype-external-links-3.0.0.tgz#2b28b5cda1932f83f045b6f80a3e1b15f168c6f6"
9635+
integrity sha512-yp+e5N9V3C6bwBeAC4n796kc86M4gJCdlVhiMTxIrJG5UHDMh+PJANf9heqORJbt1nrCbDwIlAZKjANIaVBbvw==
9636+
dependencies:
9637+
"@types/hast" "^3.0.0"
9638+
"@ungap/structured-clone" "^1.0.0"
9639+
hast-util-is-element "^3.0.0"
9640+
is-absolute-url "^4.0.0"
9641+
space-separated-tokens "^2.0.0"
9642+
unist-util-visit "^5.0.0"
9643+
96279644
rehype-minify-whitespace@^6.0.0:
96289645
version "6.0.2"
96299646
resolved "https://registry.yarnpkg.com/rehype-minify-whitespace/-/rehype-minify-whitespace-6.0.2.tgz#7dd234ce0775656ce6b6b0aad0a6093de29b2278"

0 commit comments

Comments
 (0)