on master help sign in
Merge pull request #1561 from urbit/mp/nextlinks
03b87d7matildepark
components/Markdown.js+11
@@ -1,4 +1,5 @@
1import React from "react";
1import React from "react";
2+import Link from "next/link";
2import Markdoc, { Ast, Node, Tag, Raw } from "@markdoc/markdoc";
3import Markdoc, { Ast, Node, Tag, Raw } from "@markdoc/markdoc";
3import { heading } from "./schema/Heading.markdoc";
4import { heading } from "./schema/Heading.markdoc";
4import { footnoteRef } from "./schema/footnoteRef.markdoc";
5import { footnoteRef } from "./schema/footnoteRef.markdoc";
@@ -126,6 +127,14 @@ const superscript = ({ children }) => <sup>{children}</sup>;
126
127
127const CustomFence = ({ children }) => <pre>{children}</pre>;
128const CustomFence = ({ children }) => <pre>{children}</pre>;
128
129
130+const NextLink = ({ href, target, children }) => {
131+ return (
132+ <Link href={href} passHref>
133+ <a target={target}>{children}</a>
134+ </Link>
135+ );
136+};
137+
129export function MarkdownParse({ post }) {
138export function MarkdownParse({ post }) {
130 const tokeniser = new Markdoc.Tokenizer({ html: true, linkify: true });
139 const tokeniser = new Markdoc.Tokenizer({ html: true, linkify: true });
131 const tokens = tokeniser.tokenize(post.content);
140 const tokens = tokeniser.tokenize(post.content);
@@ -150,6 +159,7 @@ export function MarkdownParse({ post }) {
150 customFence,
159 customFence,
151 RenderHtml,
160 RenderHtml,
152 superscript,
161 superscript,
162+ NextLink,
153 },
163 },
154 });
164 });
155}
165}
@@ -164,6 +174,7 @@ export default function Markdown({ content }) {
164 Callout,
174 Callout,
165 CustomFence,
175 CustomFence,
166 RenderHtml,
176 RenderHtml,
177+ NextLink,
167 },
178 },
168 });
179 });
169}
180}
components/schema/link.markdoc.js+2−2
@@ -15,7 +15,7 @@ function checkIfExternal(attributes) {
15}
15}
16
16
17export const link = {
17export const link = {
18− render: "a",
18+ render: "NextLink",
19 children: ["strong", "em", "s", "code", "text", "tag"],
19 children: ["strong", "em", "s", "code", "text", "tag"],
20 attributes: {
20 attributes: {
21 href: { type: String, required: true },
21 href: { type: String, required: true },
@@ -28,6 +28,6 @@ export const link = {
28
28
29 const target = checkIfExternal(attributes);
29 const target = checkIfExternal(attributes);
30
30
31− return new Tag(`a`, { ...attributes, target }, children);
31+ return new Tag("NextLink", { ...attributes, target }, children);
32 },
32 },
33};
33};