main
1// SafeHtml is the only string the SSR response may carry. Escape produces it. Tag builders
2// concatenate it. A bare string is not SafeHtml, so it cannot be passed to htmlResponse or raw().
3import { raw } from 'hono/html';
5declare const safeHtmlBrand: unique symbol;
7export type SafeHtml = string & { readonly [safeHtmlBrand]: 'SafeHtml' };
9function mark(value: string): SafeHtml {
10 return value as SafeHtml;
11}
13/** Text and double-quoted attribute values. Named entities, so `"` is not a raw quote. */
14export function escapeHtml(value: string): SafeHtml {
15 return mark(value
16 .replace(/&/g, '&')
17 .replace(/</g, '<')
18 .replace(/>/g, '>')
19 .replace(/"/g, '"')
20 .replace(/'/g, '''));
21}
23export function concatHtml(parts: readonly SafeHtml[]): SafeHtml {
24 return mark(parts.join(''));
25}
27export type MdTag = 'p' | 'ul' | 'ol' | 'li' | 'pre' | 'code' | 'strong' | 'em' | 'del' | 'blockquote' | 'table' | 'thead' | 'tbody' | 'tr' | 'th' | 'td' | 'div' | 'span';
29/** Fixed class names the markdown renderer may attach. Never derived from the source text. */
30export type MdClass = 'md-code' | 'md-code-lang' | 'md-table' | 'task' | 'task done' | 'task-item' | 'al-l' | 'al-c' | 'al-r' | 'md-img' | 'md-frontmatter';
32export function tag(name: MdTag, content: SafeHtml, cls: MdClass | null): SafeHtml {
33 const open = cls === null ? `<${name}>` : `<${name} class="${cls}">`;
34 return concatHtml([mark(open), content, mark(`</${name}>`)]);
35}
37export function voidTag(name: 'br' | 'hr'): SafeHtml {
38 return mark(`<${name}>`);
39}
41/** h2–h6. The id is a slug of [a-z0-9-] only, so a README's `[x](#usage)` lands on its heading. */
42export function heading(level: 2 | 3 | 4 | 5 | 6, slug: string, content: SafeHtml): SafeHtml {
43 const id = /^[a-z0-9][a-z0-9-]{0,79}$/.test(slug) ? ` id="${slug}"` : '';
44 return concatHtml([mark(`<h${level}${id}>`), content, mark(`</h${level}>`)]);
45}
47/** An ordered list that starts at an integer other than 1. */
48export function orderedList(start: number, content: SafeHtml): SafeHtml {
49 const n = Number.isSafeInteger(start) && start >= 0 && start !== 1 ? ` start="${start}"` : '';
50 return concatHtml([mark(`<ol${n}>`), content, mark('</ol>')]);
51}
53/** href has already passed the scheme allowlist and contains no quote, space, or control. */
54export function anchor(href: string, content: SafeHtml): SafeHtml {
55 return concatHtml([
56 mark('<a href="'),
57 escapeHtml(href),
58 mark('" rel="noopener noreferrer nofollow">'),
59 content,
60 mark('</a>'),
61 ]);
62}
64/**
65 * Hono escapes interpolated children. The one raw() call in the viewer takes SafeHtml, which
66 * only the markdown renderer produces. This brands that JSX result for htmlResponse.
67 */
68export function trustRendered(markup: string): SafeHtml {
69 return mark(markup);
70}
72export function rawSafe(html: SafeHtml) {
73 return raw(html);
74}
76export function viewerErrorDocument(code: string, message: string): SafeHtml {
77 return concatHtml([
78 mark('<!doctype html><meta charset="utf-8"><title>'),
79 escapeHtml(code),
80 mark('</title><p>'),
81 escapeHtml(message),
82 mark('</p>'),
83 ]);
84}
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.3 KiB · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=1362 git.response.cache=HIT git.response.duration_ms=24 git.fetch.wants=13864bc1f8b3a19d174a87f4836ee4f005206262 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1362 git.pkt.payload.max=1341 git.sideband.band1.bytes=1340 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e2e883af9decfa
- Request
- 2e8866d2…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format