on master help sign in
Markdown: properly wraps child nodes for italicised links
commit4718e6c39971c3ab019a265e2c62b281bc665020 authorMatilde Park <matilde.park@urbit.org> dateFri 6 May 2022, 14:19 (4 years ago) parent92805b5
1 file changed+10−6
components/Markdown.js+10−6
components/Markdown.js+10−6
@@ -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, { defaultHandlers } 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,7 +31,7 @@ function Img(h, node) {
3131 };
3232}
3333
34−function Link(h, node) {
34+function a(h, node) {
3535 const url = node.url;
3636
3737 if (
@@ -45,7 +45,7 @@ function Link(h, node) {
4545 properties: {
4646 href: url,
4747 },
48− children: node.children,
48+ children: all(h, node),
4949 };
5050 } else {
5151 return {
@@ -56,14 +56,18 @@ function Link(h, node) {
5656 rel: "noopener",
5757 href: url,
5858 },
59− children: node.children,
59+ children: all(h, node),
6060 };
6161 }
6262}
6363
64+const handlers = defaultHandlers;
65+handlers.link = a;
66+handlers.image = img;
67+
6468const options = {
6569 allowDangerousHtml: true,
66− handlers: Object.assign(defaultHandlers, { image: Img, link: Link }),
70+ handlers: handlers,
6771 sanitize: merge(github, {
6872 // remove user-content from github.json to remark-slug work as expected
6973 clobberPrefix: "",