summaryrefslogtreecommitdiff
path: root/website/src/renderGemtextToHtml.ts
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-06-18 19:21:59 +0100
committerJoe Carstairs <me@joeac.net>2026-06-18 19:21:59 +0100
commitca8e6824eaa711105f4092365792720c9dde026b (patch)
tree2b6493941352d11b799ee63d3f1311c13de649b8 /website/src/renderGemtextToHtml.ts
parenta0f25057283a397f006127b6f582d190d2c4294e (diff)
remove Astro website
Diffstat (limited to 'website/src/renderGemtextToHtml.ts')
-rw-r--r--website/src/renderGemtextToHtml.ts71
1 files changed, 0 insertions, 71 deletions
diff --git a/website/src/renderGemtextToHtml.ts b/website/src/renderGemtextToHtml.ts
deleted file mode 100644
index 1c01072..0000000
--- a/website/src/renderGemtextToHtml.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-import * as Gemtext from "gemtext";
-
-export function renderGemtextToHtml(gemtext: string, title?: string): string {
- gemtext = title ? gemtext.replace(`# ${title}`, "") : gemtext;
- return postProcessGemtextToHtml(
- Gemtext.parse(gemtext).generate(GemtextHTMLRenderer),
- );
-}
-
-const GemtextHTMLRenderer: Gemtext.Renderer<string> = {
- preamble: function (): string {
- return "";
- },
-
- postamble: function (): string {
- return "";
- },
-
- text: function (content: string): string {
- content = content.trim();
- if (content === "") {
- return "";
- }
- return `<p>${htmlEscape(content)}</p>`;
- },
-
- link: function (url: string, alt: string): string {
- const imgExtensions: (string | undefined)[] = [
- "webp",
- "png",
- "svg",
- "gif",
- "jpg",
- "jpeg",
- "apng",
- ];
- if (imgExtensions.includes(url.split(".").at(-1)?.toLowerCase())) {
- return `<img src="${url}" alt="${alt}" />`;
- }
- return `<p>=> <a href="${url}">${alt}</a></p>`;
- },
-
- preformatted: function (content: string[], alt: string): string {
- return `<pre alt="${alt}">${htmlEscape(content.join("\n"))}</pre>`;
- },
-
- heading: function (level: number, text: string): string {
- return `<h${level}>${htmlEscape(text)}</h${level}>`;
- },
-
- unorderedList: function (content: string[]): string {
- return `<ul>${content.map((li) => `<li>${htmlEscape(li)}</li>`).join("")}</ul>`;
- },
-
- quote: function (content: string): string {
- return `<blockquote>${htmlEscape(content)}</blockquote>`;
- },
-};
-
-function htmlEscape(str: string) {
- return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
-}
-
-function postProcessGemtextToHtml(html: string): string {
- html = mergeAdjacentBlockquotes(html);
- return html;
-}
-
-function mergeAdjacentBlockquotes(html: string): string {
- return html.replaceAll(/\<\/blockquote\>\<blockquote\>/gm, "<br>");
-}