Back to packages list

Vals using md4w

Description from the NPM package:
A Markdown renderer written in Zig & C, compiled to WebAssymbly for all JS runtimes.

mdRest

Based on markdown.rest. Converts markdown (plain text or base64 encoded) to HTML (plain text or base64 encoded)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { init, mdToHtml } from "https://esm.sh/md4w@0.2.4";
await init("fast");
function render(html: string) {
return mdToHtml(html);
}
type ReqBody = {
isBase64?: boolean;
returnBase64?: boolean;
content: string;
};
export default async function handler(request: Request) {
if (request.method !== "POST") {
return Response.json({ message: "This val responds to POST requests." }, {
status: 400,
});
}
try {
const { isBase64 = false, returnBase64 = false, content } = (await request.json()) as ReqBody;
const md = isBase64 ? atob(content) : content;
const html = returnBase64 ? btoa(render(md)) : renderx(md);
return new Response(html, { headers: { "Content-Type": "text/plain" } });
} catch (e) {
return Response.json({ message: "The body of this request was not JSON-encoded." }, {
status: 400,
});
}
}

md

A Markdown renderer written in Zig & C, compiled to WebAssymbly for val.town - https://github.com/ije/md4w

Create valimport { render } from "https://esm.town/v/ije/md" render("Stay _foolish_, stay **hungry**!") // -> <p>Stay <em>foolish</em>, stay <strong>hungry</strong>!</p>
1
2
3
4
5
6
7
import { init, mdToHtml } from "https://esm.sh/md4w@0.2.4";
await init("small");
export function render(html: string) {
return mdToHtml(html);
}
1
Next