Cotton code
34 lines · 1.9 KB · TypeScriptRaw
/** Small helpers for writing HTML by hand, and the design's drawn marks. */export const esc = (s: string): string =>  s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");/** The design's drawings (site-v2 build.py), unchanged. */export const ARROW = '<svg viewBox="0 0 20 20" aria-hidden="true"><path d="M3.5 10h12M11 5.5l4.5 4.5-4.5 4.5"/></svg>';export const RING =  '<svg class="draw-path" viewBox="0 0 200 100" preserveAspectRatio="none" aria-hidden="true"><path d="M34 20C74 3 150 1 181 27c24 21 6 58-60 66C60 100 9 88 8 56 7 29 42 9 98 7c24-1 45 3 60 9"/></svg>';export const THREAD =  '<svg viewBox="0 0 200 12" preserveAspectRatio="none" aria-hidden="true"><path d="M2 7C28 2 52 10 80 6s52-3 78 1c14 2 28 1 40-3"/></svg>';export const QUOTE =  '<svg class="quote" viewBox="0 0 62 44" aria-hidden="true"><path fill="currentColor" d="M0 31C0 15 9 5 24 0l3 6c-8 3-12 8-13 13a12.500 12.500 0 1 1-14 12zm34 0C34 15 43 5 58 0l3 6c-8 3-12 8-13 13a12.500 12.500 0 1 1-14 12z"/></svg>';export const LOOSE =  '<svg class="loose" viewBox="0 0 1200 24" preserveAspectRatio="none" aria-hidden="true"><path d="M0 13c90-9 170 8 260 2s150-12 250-4 160 11 260 3 170-9 250-2 120 6 180 1"/></svg>';/** * A hyphenated word never splits at its hyphen (to-dos, one-time): text only, never inside a tag, a title or a * style. The design's keep_together, as it is. */export function keepTogether(page: string): string {  const parts = page.split(/(<[^>]+>)/);  let skip = false;  for (let i = 0; i < parts.length; i++) {    const part = parts[i]!;    if (part.startsWith("<")) {      if (/^<(title|style)\b/.test(part)) skip = true;      if (/^<\/(title|style)>/.test(part)) skip = false;      continue;    }    if (!skip) parts[i] = part.replace(/(?<![\w@.#/-])([A-Za-z]+-[A-Za-z]+)(?![\w@/-])/g, '<span class="nb">$1</span>');  }  return parts.join("");}