From 22af15279da83d6e0768f6672f97e2f5d157e9a6 Mon Sep 17 00:00:00 2001 From: Efe Date: Thu, 24 Oct 2024 11:13:13 +0200 Subject: [PATCH] www: Fix block quotes not rendering links (#2712) - Fixes a bug where block quotes were not able to properly render URLs in docs (e.g. Info section at https://fresh.deno.dev/docs/getting-started/create-a-route) - Replaces existing JSX docs url with the suggested, up-to-date docs url image --- docs/latest/getting-started/create-a-route.md | 2 +- www/utils/markdown.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/latest/getting-started/create-a-route.md b/docs/latest/getting-started/create-a-route.md index 0356f5ff..508eb0a9 100644 --- a/docs/latest/getting-started/create-a-route.md +++ b/docs/latest/getting-started/create-a-route.md @@ -52,7 +52,7 @@ The new page will be visible at `http://localhost:8000/about`. pages in the _Getting Started_ guide will also explain more features of routes. --> [concepts-routing]: /docs/concepts/routing -[jsx]: https://reactjs.org/docs/introducing-jsx.html +[jsx]:https://react.dev/learn/writing-markup-with-jsx [preact]: https://preactjs.com/ diff --git a/www/utils/markdown.ts b/www/utils/markdown.ts index 89d7bb76..f7d96046 100644 --- a/www/utils/markdown.ts +++ b/www/utils/markdown.ts @@ -113,22 +113,27 @@ class DefaultRenderer extends Marked.Renderer { return out; } - override blockquote({ text }: Marked.Tokens.Blockquote): string { + override blockquote({ text, tokens }: Marked.Tokens.Blockquote): string { const match = text.match(ADMISSION_REG); + if (match) { const label: Record = { tip: "Tip", warn: "Warning", info: "Info", }; + Marked.walkTokens(tokens, (token) => { + if (token.type === "text" && token.text.startsWith(match[0])) { + token.text = token.text.slice(match[0].length); + } + }); const type = match[1]; - text = text.slice(match[0].length); const icon = ``; return `
\n${icon}${ label[type] - }${Marked.parse(text)}
\n`; + }${Marked.parser(tokens)}\n`; } - return `
\n${Marked.parse(text)}
\n`; + return `
\n${Marked.parser(tokens)}
\n`; } }