Skip to content

Commit

Permalink
www: Fix block quotes not rendering links (#2712)
Browse files Browse the repository at this point in the history
- 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

<img width="775" alt="image"
src="https://github.com/user-attachments/assets/e2e83456-697b-47d5-b074-66e4f287f17a">
  • Loading branch information
efekrskl authored Oct 24, 2024
1 parent bf45e86 commit 22af152
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/latest/getting-started/create-a-route.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/

<!-- [concepts-routes]: /docs/concepts/routes -->
13 changes: 9 additions & 4 deletions www/utils/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
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 = `<svg class="icon"><use href="/icons.svg#${type}" /></svg>`;
return `<blockquote class="admonition ${type}">\n<span class="admonition-header">${icon}${
label[type]
}</span>${Marked.parse(text)}</blockquote>\n`;
}</span>${Marked.parser(tokens)}</blockquote>\n`;
}
return `<blockquote>\n${Marked.parse(text)}</blockquote>\n`;
return `<blockquote>\n${Marked.parser(tokens)}</blockquote>\n`;
}
}

Expand Down

0 comments on commit 22af152

Please sign in to comment.