on master help sign in
Markdown: open external links in a new tab

Fixes #725

commit3071619686e0553a60c9350d906850eeae0961c1 authorMatilde Park <matilde.park@urbit.org> dateThu 5 May 2022, 16:51 (4 years ago) parentfceb947
2 files changed+35−3
components/Markdown.js+34−2 content/blog/layer-2-faq.md+1−1
components/Markdown.js+34−2
@@ -31,9 +31,41 @@ function Img(h, node) {
3131 };
3232}
3333
34+function Link(h, node) {
35+ const url = node.url;
36+
37+ if (
38+ url.includes("https://urbit.org") ||
39+ url.startsWith("/") ||
40+ url.startsWith("#")
41+ ) {
42+ return {
43+ type: "element",
44+ tagName: "a",
45+ properties: {
46+ href: url,
47+ },
48+ children: node.children,
49+ };
50+ } else {
51+ return {
52+ type: "element",
53+ tagName: "a",
54+ properties: {
55+ target: "_blank",
56+ rel: "noopener",
57+ href: url,
58+ },
59+ children: node.children,
60+ };
61+ }
62+}
63+
3464const options = {
65+ allowDangerousHtml: true,
3566 handlers: {
3667 image: Img,
68+ link: Link,
3769 },
3870 sanitize: merge(github, {
3971 // remove user-content from github.json to remark-slug work as expected
@@ -45,14 +77,14 @@ const options = {
4577// Converts markdown strings into markdown HTML/React components
4678export default async function Markdown({ post }, disablePlugins) {
4779 const result = await remark()
48− .use(remarkParse, options)
80+ .use(remarkParse)
4981 .use(remarkprism, {
5082 plugins: !disablePlugins ? ["show-invisibles"] : [],
5183 })
5284 .use(gfm)
5385 .use(slug)
5486 .use(heading)
55− .use(remarkRehype, { allowDangerousHtml: true })
87+ .use(remarkRehype, options)
5688 .use(rehypeRaw)
5789 .use(rehypeStringify)
5890 .process(post.content);
content/blog/layer-2-faq.md+1−1
@@ -45,7 +45,7 @@ you **do not** need ETH to boot Urbit. That Urbit ID is now yours, forever.
4545Unsure whether you have been invited to claim a L2 or L1 planet? The quickest
4646way to identify a L2 planet is if you used the below flow to claim.
4747
48−![](/images/planet-l2-claim.gif)
48+<img src="/images/planet-l2-claim.gif" style="max-height: 400px; width: auto; margin: 0 auto;"/>
4949
5050For those with L1 planets, you can avoid future transaction fees by migrating
5151your L1 planet to L2. Read the migration instructions