on master help sign in
Markdown: open external links in a new tab
3071619Matilde Park
components/Markdown.js+34−2
@@ -31,9 +31,41 @@ function Img(h, node) {
31 };
31 };
32}
32}
33
33
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+
34const options = {
64const options = {
65+ allowDangerousHtml: true,
35 handlers: {
66 handlers: {
36 image: Img,
67 image: Img,
68+ link: Link,
37 },
69 },
38 sanitize: merge(github, {
70 sanitize: merge(github, {
39 // remove user-content from github.json to remark-slug work as expected
71 // remove user-content from github.json to remark-slug work as expected
@@ -45,14 +77,14 @@ const options = {
45// Converts markdown strings into markdown HTML/React components
77// Converts markdown strings into markdown HTML/React components
46export default async function Markdown({ post }, disablePlugins) {
78export default async function Markdown({ post }, disablePlugins) {
47 const result = await remark()
79 const result = await remark()
48− .use(remarkParse, options)
80+ .use(remarkParse)
49 .use(remarkprism, {
81 .use(remarkprism, {
50 plugins: !disablePlugins ? ["show-invisibles"] : [],
82 plugins: !disablePlugins ? ["show-invisibles"] : [],
51 })
83 })
52 .use(gfm)
84 .use(gfm)
53 .use(slug)
85 .use(slug)
54 .use(heading)
86 .use(heading)
55− .use(remarkRehype, { allowDangerousHtml: true })
87+ .use(remarkRehype, options)
56 .use(rehypeRaw)
88 .use(rehypeRaw)
57 .use(rehypeStringify)
89 .use(rehypeStringify)
58 .process(post.content);
90 .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.
45Unsure whether you have been invited to claim a L2 or L1 planet? The quickest
45Unsure whether you have been invited to claim a L2 or L1 planet? The quickest
46way to identify a L2 planet is if you used the below flow to claim.
46way to identify a L2 planet is if you used the below flow to claim.
47
47
48−![](/images/planet-l2-claim.gif)
48+<img src="/images/planet-l2-claim.gif" style="max-height: 400px; width: auto; margin: 0 auto;"/>
49
49
50For those with L1 planets, you can avoid future transaction fees by migrating
50For those with L1 planets, you can avoid future transaction fees by migrating
51your L1 planet to L2. Read the migration instructions
51your L1 planet to L2. Read the migration instructions