@@ -7,12 +7,12 @@ import normalize from "mdurl/encode";
77import merge from "deepmerge";
88import github from "hast-util-sanitize/lib/github";
99import remarkParse from "remark-parse";
10−import remarkRehype from "remark-rehype";
10+import remarkRehype, { defaultHandlers, all } from "remark-rehype";
1111import rehypeStringify from "rehype-stringify";
1212import rehypeRaw from "rehype-raw";
1313
1414// img is wrapped in figure so that images can be extra wide in the blog posts
15−function Img(h, node) {
15+function img(h, node) {
1616 var props = { src: normalize(node.url), alt: node.alt };
1717 if (node.title !== null && node.title !== undefined) {
1818 props.title = node.title;
@@ -31,10 +31,43 @@ function Img(h, node) {
3131 };
3232}
3333
34+function a(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: all(h, node),
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: all(h, node),
60+ };
61+ }
62+}
63+
64+const handlers = defaultHandlers;
65+handlers.link = a;
66+handlers.image = img;
67+
3468const options = {
35− handlers: {
36− image: Img,
37− },
69+ allowDangerousHtml: true,
70+ handlers: handlers,
3871 sanitize: merge(github, {
3972 // remove user-content from github.json to remark-slug work as expected
4073 clobberPrefix: "",
@@ -45,14 +78,14 @@ const options = {
4578// Converts markdown strings into markdown HTML/React components
4679export default async function Markdown({ post }, disablePlugins) {
4780 const result = await remark()
48− .use(remarkParse, options)
81+ .use(remarkParse)
4982 .use(remarkprism, {
5083 plugins: !disablePlugins ? ["show-invisibles"] : [],
5184 })
5285 .use(gfm)
5386 .use(slug)
5487 .use(heading)
55− .use(remarkRehype, { allowDangerousHtml: true })
88+ .use(remarkRehype, options)
5689 .use(rehypeRaw)
5790 .use(rehypeStringify)
5891 .process(post.content);