gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit32ba9d5932ba9d59gitoria: leave the host-only cookie experiment out of the browser gate (gitoria#24 is a separate mission)mre32ba9d59/lib/markdown.hl

20.4 KB

  1. // lib/markdown.hl — copied from tickets.worldapi.org (markdown.hl, ticket tickets#6) for the repo homepage (gitoria#8), with tables, quotes and rules added. Originally: MARKDOWN IN TEXT FIELDS (mission 014; CONCEPT.md
  2. // "Data formats": Markdown inside text fields). The summary, comment texts and state notes are
  3. // Markdown; the ticket page renders them. Statics only, server realm.
  4. //
  5. // SAFE BY CONSTRUCTION: the text is parsed HERE into plain data — blocks of spans — and the
  6. // View (components/markdown.hl) builds elements from it. Every character of the source ends
  7. // up in a TEXT node (hl:web escapes it); there is no HTML string anywhere, so raw HTML in the
  8. // source (`<script>`, `<img onerror>`) is shown as the text it is. A link's href is taken only
  9. // if `safeHref` accepts it: http(s):, mailto:, a same-site path (`/…`, not `//…`) or `#…`;
  10. // anything else (`javascript:`, `data:`, `vbscript:`, relative `foo`, quotes, spaces, control
  11. // characters) stays plain text.
  12. //
  13. // WHAT IS UNDERSTOOD (the subset ticket #6 names — headings, lists, code, links, emphasis):
  14. // blocks: `#`…`######` headings, `-`/`*`/`+` and `1.`/`1)` list items (one level; deeper
  15. // indentation is flattened; a list may interrupt a paragraph — the import writes
  16. // them that way), ``` / ~~~ fenced code, paragraphs (blank-line separated; their
  17. // single line breaks are KEPT — the page showed them before, `white-space: pre-wrap`)
  18. // inline: `code` (any backtick run), [text](url), <https://…>, bare http(s):// URLs,
  19. // *em* _em_ **strong** __strong__ ***both***, backslash escapes of punctuation
  20. // Also understood here (gitoria#8): `> block quotes` (inline text only), | tables |, horizontal rules.
  21. // Not understood (shown as typed): images, nested lists, HTML.
  22. //
  23. // A block is COMPACT (it travels in the page values): ONE flag that names its kind (omitted = false) and only the fields that
  24. // kind has. The View's `if` takes a field, not a comparison (a `kind == 'p'` string cannot be tested there), so the kind IS the field.
  25. // { isP | isQuote | isH1 | isH2 | isH3 (3 = level 3+) = true, spans } { isUl = true, items: [{ spans }] } { isOl = true, items, start }
  26. // { isCode = true, code (the text) } { isTable = true, head: [{ spans }], rows: [[{ spans }]] } { isHr = true }
  27. // A span: { text, isText | isStrong | isEm | isStrongEm | isCode | isLink = true, href (link only) }
  28. static NL = "
  29. "
  30. import { sha256 } from 'hl:crypto'
  31. // ---- the parsed-blocks cache (G3) ----------------------------------------------------------
  32. // The homepage reads README.md from git on EVERY request and the scanner below costs ~100 ms on a big README (~26 % of the
  33. // page's server time, W113). The blocks are a pure function of the text, so they are kept under the text's sha256: a push
  34. // changes the text, hence the key — nothing to invalidate, a stale entry can only be unused. BOUNDED: at most mdMaxEntries
  35. // texts and mdMaxChars characters of source in total (the cost of an entry is its text length); the least recently used goes
  36. // first. A text over mdMaxOne characters is parsed but not kept. Flat statics written key by key (like tracker's maps).
  37. static mdMaxEntries = 32
  38. static mdMaxChars = 4000000
  39. static mdMaxOne = 1000000
  40. static mdCache = {} // sha256 hex → blocks
  41. static mdSize = {} // sha256 hex → characters of its text
  42. static mdOrder = [] // keys, least recently used first
  43. static mdChars = [0] // the sum of mdSize (one slot: a static number cannot be written from a lambda)
  44. static isSpaceC = (c) => { return c == 32 || c == 9 || c == 10 || c == 13 }
  45. static isAlnumC = (c) => { return (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c > 127 }
  46. static isPunctC = (c) => { return (c >= 33 && c <= 47) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126) }
  47. // ---- links ------------------------------------------------------------------------------
  48. // the href of a link, or null when it is not one we let through
  49. static safeHref = (u) => {
  50. if (u == null) { return null }
  51. t = ('' + u).trim()
  52. if (t == '' || t.length > 2000) { return null }
  53. let i = 0
  54. while (i < t.length) {
  55. let c = t.charCodeAt(i)
  56. // no spaces / control characters, no quotes, no < > ` and no backslash
  57. if (c <= 32 || c == 127 || c == 34 || c == 39 || c == 60 || c == 62 || c == 96 || c == 92) { return null }
  58. i = i + 1
  59. }
  60. low = t.toLowerCase()
  61. if (low.startsWith('https://') && t.length > 8) { return t }
  62. if (low.startsWith('http://') && t.length > 7) { return t }
  63. if (low.startsWith('mailto:') && t.length > 7) { return t }
  64. if (t.startsWith('/') && !t.startsWith('//')) { return t }
  65. if (t.startsWith('#')) { return t }
  66. return null
  67. }
  68. static isUrlStart = (s, i) => {
  69. low = s.slice(i, i + 8).toLowerCase()
  70. return low.startsWith('https://') || low.startsWith('http://')
  71. }
  72. // where a bare URL starting at i ends: up to whitespace or < > " `, minus trailing punctuation
  73. // (and a closing parenthesis that has no opening one inside the URL)
  74. static isUrlStop = (c) => { return isSpaceC(c) || c == 60 || c == 62 || c == 34 || c == 96 }
  75. static urlEnd = (s, i) => {
  76. let end = i
  77. while (end < s.length && !isUrlStop(s.charCodeAt(end))) { end = end + 1 }
  78. let trimming = true
  79. while (trimming && end > i) {
  80. let c = s.charCodeAt(end - 1)
  81. if (c == 46 || c == 44 || c == 59 || c == 58 || c == 33 || c == 63 || c == 39 || c == 42 || c == 95) {
  82. end = end - 1
  83. } else if (c == 41) {
  84. let opens = 0
  85. let closes = 0
  86. let k = i
  87. while (k < end) {
  88. if (s.charCodeAt(k) == 40) { opens = opens + 1 }
  89. if (s.charCodeAt(k) == 41) { closes = closes + 1 }
  90. k = k + 1
  91. }
  92. if (closes > opens) { end = end - 1 } else { trimming = false }
  93. } else {
  94. trimming = false
  95. }
  96. }
  97. return end
  98. }
  99. // `[label](url)` at i → { label, href (null = not allowed), end } or null (not a link)
  100. static linkAt = (s, i) => {
  101. let j = i + 1
  102. let found = -1
  103. while (j < s.length && found < 0) {
  104. let c = s.charCodeAt(j)
  105. if (c == 91) { return null }
  106. if (c == 93) { found = j }
  107. j = j + 1
  108. }
  109. if (found < 0 || found == i + 1) { return null }
  110. if (found + 1 >= s.length || s.charCodeAt(found + 1) != 40) { return null }
  111. k = s.indexOf(')', found + 2)
  112. if (k < 0) { return null }
  113. let target = s.slice(found + 2, k).trim()
  114. // an optional title after a space is dropped: [x](url "title")
  115. sp = target.indexOf(' ')
  116. if (sp > 0) { target = target.slice(0, sp) }
  117. return { label = s.slice(i + 1, found) href = safeHref(target) end = k + 1 }
  118. }
  119. // ---- spans --------------------------------------------------------------------------------
  120. static textSpan = (t, strong, em) => {
  121. if (strong && em) { return { text = t isStrongEm = true } }
  122. if (strong) { return { text = t isStrong = true } }
  123. if (em) { return { text = t isEm = true } }
  124. return { text = t isText = true }
  125. }
  126. static codeSpan = (t) => {
  127. return { text = t isCode = true }
  128. }
  129. static linkSpan = (t, h) => {
  130. return { text = t isLink = true href = h }
  131. }
  132. // the index of a run of EXACTLY n characters c at or after `at`, or -1. `esc`: a character
  133. // after a backslash does not count (emphasis; inside `code` a backslash is just a backslash)
  134. static runAt = (s, at, c, n, esc) => {
  135. let i = at
  136. while (i < s.length) {
  137. if (esc && s.charCodeAt(i) == 92) {
  138. i = i + 2
  139. } else if (s.charCodeAt(i) == c) {
  140. let k = i
  141. while (k < s.length && s.charCodeAt(k) == c) { k = k + 1 }
  142. if (k - i == n) { return i }
  143. i = k
  144. } else {
  145. i = i + 1
  146. }
  147. }
  148. return -1
  149. }
  150. // is there a CLOSING delimiter run (exactly n of c, not after a space; `_` not before a
  151. // letter/digit) after `at`?
  152. static hasCloser = (s, at, c, n) => {
  153. let i = at
  154. while (i < s.length) {
  155. let r = runAt(s, i, c, n, true)
  156. if (r < 0) { return false }
  157. let prev = r > 0 ? s.charCodeAt(r - 1) : 32
  158. let next = r + n < s.length ? s.charCodeAt(r + n) : 32
  159. if (r > at && !isSpaceC(prev) && (c != 95 || !isAlnumC(next))) { return true }
  160. i = r + n
  161. }
  162. return false
  163. }
  164. static inlineSpans = (src) => {
  165. out = []
  166. if (src == null || src == '') { return out }
  167. s = '' + src
  168. n = s.length
  169. let buf = ''
  170. let strong = false
  171. let em = false
  172. let strongC = 0
  173. let emC = 0
  174. let i = 0
  175. while (i < n) {
  176. let c = s.charCodeAt(i)
  177. if (c == 92 && i + 1 < n && isPunctC(s.charCodeAt(i + 1))) {
  178. // a backslash escape: the next punctuation character as itself
  179. buf = buf + s[i + 1]
  180. i = i + 2
  181. } else if (c == 96) {
  182. // `code`: a run of backticks up to the same run
  183. let k = i
  184. while (k < n && s.charCodeAt(k) == 96) { k = k + 1 }
  185. let close = runAt(s, k, 96, k - i, false)
  186. if (close < 0) {
  187. buf = buf + s.slice(i, k)
  188. i = k
  189. } else {
  190. if (buf != '') { out.push(textSpan(buf, strong, em)) }
  191. buf = ''
  192. let code = s.slice(k, close).replaceAll(NL, ' ')
  193. if (code.length > 2 && code.startsWith(' ') && code.endsWith(' ') && code.trim() != '') { code = code.slice(1, code.length - 1) }
  194. out.push(codeSpan(code))
  195. i = close + (k - i)
  196. }
  197. } else if (c == 91) {
  198. // [label](url)
  199. let l = linkAt(s, i)
  200. if (l == null) {
  201. buf = buf + '['
  202. i = i + 1
  203. } else if (l.href == null) {
  204. buf = buf + s.slice(i, l.end)
  205. i = l.end
  206. } else {
  207. if (buf != '') { out.push(textSpan(buf, strong, em)) }
  208. buf = ''
  209. out.push(linkSpan(l.label, l.href))
  210. i = l.end
  211. }
  212. } else if (c == 60 && i + 1 < n && isUrlStart(s, i + 1)) {
  213. // <https://…>
  214. let e = s.indexOf('>', i + 1)
  215. let url = e > 0 ? s.slice(i + 1, e) : ''
  216. let h = safeHref(url)
  217. if (e < 0 || h == null) {
  218. buf = buf + '<'
  219. i = i + 1
  220. } else {
  221. if (buf != '') { out.push(textSpan(buf, strong, em)) }
  222. buf = ''
  223. out.push(linkSpan(url, h))
  224. i = e + 1
  225. }
  226. } else if ((c == 104 || c == 72) && (i == 0 || !isAlnumC(s.charCodeAt(i - 1))) && isUrlStart(s, i)) {
  227. // a bare http(s):// URL
  228. let e = urlEnd(s, i)
  229. let url = s.slice(i, e)
  230. let h = safeHref(url)
  231. if (h == null) {
  232. buf = buf + s[i]
  233. i = i + 1
  234. } else {
  235. if (buf != '') { out.push(textSpan(buf, strong, em)) }
  236. buf = ''
  237. out.push(linkSpan(url, h))
  238. i = e
  239. }
  240. } else if (c == 42 || c == 95) {
  241. // * and _: emphasis (1), strong (2), both (3)
  242. let k = i
  243. while (k < n && s.charCodeAt(k) == c) { k = k + 1 }
  244. let run = k - i
  245. let prev = i > 0 ? s.charCodeAt(i - 1) : 32
  246. let next = k < n ? s.charCodeAt(k) : 32
  247. let wantStrong = run == 2 || run == 3
  248. let wantEm = run == 1 || run == 3
  249. let canOpen = !isSpaceC(next) && (c == 42 || !isAlnumC(prev))
  250. let canClose = !isSpaceC(prev) && (c == 42 || !isAlnumC(next))
  251. let closes = canClose && run <= 3 && (!wantStrong || (strong && strongC == c)) && (!wantEm || (em && emC == c))
  252. let opens = !closes && canOpen && run <= 3 && (!wantStrong || !strong) && (!wantEm || !em) && hasCloser(s, k, c, run)
  253. if (closes || opens) {
  254. if (buf != '') { out.push(textSpan(buf, strong, em)) }
  255. buf = ''
  256. if (wantStrong) {
  257. strong = opens
  258. strongC = c
  259. }
  260. if (wantEm) {
  261. em = opens
  262. emC = c
  263. }
  264. } else {
  265. buf = buf + s.slice(i, k)
  266. }
  267. i = k
  268. } else {
  269. buf = buf + s[i]
  270. i = i + 1
  271. }
  272. }
  273. if (buf != '') { out.push(textSpan(buf, strong, em)) }
  274. return out
  275. }
  276. // ---- blocks -------------------------------------------------------------------------------
  277. static noCr = (line) => { return line.length > 0 && line.charCodeAt(line.length - 1) == 13 ? line.slice(0, line.length - 1) : line }
  278. static indentOf = (line) => {
  279. let i = 0
  280. while (i < line.length && (line.charCodeAt(i) == 32 || line.charCodeAt(i) == 9)) { i = i + 1 }
  281. return i
  282. }
  283. // a heading line (≤ 3 spaces in, 1–6 '#', a space or the end) → { level, text } or null
  284. static headingOf = (line) => {
  285. if (indentOf(line) > 3) { return null }
  286. t = line.trim()
  287. let k = 0
  288. while (k < t.length && t.charCodeAt(k) == 35) { k = k + 1 }
  289. if (k == 0 || k > 6) { return null }
  290. if (k < t.length && t.charCodeAt(k) != 32 && t.charCodeAt(k) != 9) { return null }
  291. let body = t.slice(k).trim()
  292. // a closing run of '#' after a space goes
  293. let e = body.length
  294. while (e > 0 && body.charCodeAt(e - 1) == 35) { e = e - 1 }
  295. if (e == 0) { body = '' } else if (e < body.length && (body.charCodeAt(e - 1) == 32 || body.charCodeAt(e - 1) == 9)) { body = body.slice(0, e).trim() }
  296. return { level = k text = body }
  297. }
  298. // a list item line → { ordered, start, text } or null
  299. static itemOf = (line) => {
  300. t = line.trim()
  301. if (t.length >= 2 && (t.charCodeAt(0) == 45 || t.charCodeAt(0) == 42 || t.charCodeAt(0) == 43) && (t.charCodeAt(1) == 32 || t.charCodeAt(1) == 9)) {
  302. return { ordered = false start = 1 text = t.slice(2).trim() }
  303. }
  304. if (t.length == 1 && (t == '-' || t == '*' || t == '+')) { return { ordered = false start = 1 text = '' } }
  305. let k = 0
  306. while (k < t.length && k < 9 && t.charCodeAt(k) >= 48 && t.charCodeAt(k) <= 57) { k = k + 1 }
  307. if (k == 0 || k >= t.length) { return null }
  308. d = t.charCodeAt(k)
  309. if (d != 46 && d != 41) { return null }
  310. if (k + 1 < t.length && t.charCodeAt(k + 1) != 32 && t.charCodeAt(k + 1) != 9) { return null }
  311. return { ordered = true start = toNumber(t.slice(0, k)) text = t.slice(k + 1).trim() }
  312. }
  313. // a code fence line (``` or ~~~, ≥ 3) → its run (e.g. '````') or null
  314. static fenceOf = (line) => {
  315. if (indentOf(line) > 3) { return null }
  316. t = line.trim()
  317. if (t.length < 3) { return null }
  318. c = t.charCodeAt(0)
  319. if (c != 96 && c != 126) { return null }
  320. let k = 0
  321. while (k < t.length && t.charCodeAt(k) == c) { k = k + 1 }
  322. if (k < 3) { return null }
  323. // an info string after ``` must not contain a backtick
  324. if (c == 96 && t.slice(k).includes('`')) { return null }
  325. return t.slice(0, k)
  326. }
  327. static paraBlock = (lines) => {
  328. let spans = inlineSpans(lines.join(NL))
  329. return { isP = true spans = spans }
  330. }
  331. static headingBlock = (level, text) => {
  332. let spans = inlineSpans(text)
  333. if (level == 1) { return { isH1 = true spans = spans } }
  334. if (level == 2) { return { isH2 = true spans = spans } }
  335. return { isH3 = true spans = spans }
  336. }
  337. static codeBlock = (lines) => {
  338. text = lines.join(NL)
  339. return { isCode = true code = text }
  340. }
  341. static listBlock = (ordered, first, itemLines) => {
  342. let items = []
  343. for (lines of itemLines) {
  344. let spans = inlineSpans(lines.join(NL))
  345. items.push({ spans = spans })
  346. }
  347. if (ordered) { return { isOl = true items = items start = first } }
  348. return { isUl = true items = items }
  349. }
  350. static quoteBlock = (lines) => {
  351. let spans = inlineSpans(lines.join(NL))
  352. return { isQuote = true spans = spans }
  353. }
  354. static hrBlock = () => {
  355. return { isHr = true }
  356. }
  357. static tableBlock = (head, rows) => {
  358. return { isTable = true head = head rows = rows }
  359. }
  360. // a line of 3+ of one of - * _ (spaces between allowed) and nothing else
  361. static isHrLine = (line) => {
  362. if (indentOf(line) > 3) { return false }
  363. t = line.trim()
  364. if (t.length < 3) { return false }
  365. c = t.charCodeAt(0)
  366. if (c != 45 && c != 42 && c != 95) { return false }
  367. let n = 0
  368. let i = 0
  369. while (i < t.length) {
  370. let d = t.charCodeAt(i)
  371. if (d == c) { n = n + 1 } else if (d != 32 && d != 9) { return false }
  372. i = i + 1
  373. }
  374. return n >= 3
  375. }
  376. // `> text` → the text after the marker, or null
  377. static quoteOf = (line) => {
  378. if (indentOf(line) > 3) { return null }
  379. t = line.trim()
  380. if (!t.startsWith('>')) { return null }
  381. return t.slice(1).trim()
  382. }
  383. // the cells of a table row line: `| a | b |` → [a, b] as spans lists
  384. static cellsOf = (line) => {
  385. let t = line.trim()
  386. if (t.startsWith('|')) { t = t.slice(1) }
  387. if (t.endsWith('|')) { t = t.slice(0, t.length - 1) }
  388. out = []
  389. for (c of t.split('|')) { out.push({ spans = inlineSpans(c.trim()) }) }
  390. return out
  391. }
  392. // is this the `|---|:--:|` line under a table head?
  393. static isSepLine = (line) => {
  394. t = line.trim()
  395. if (!t.includes('-') || !t.includes('|') && !t.includes(':')) { return false }
  396. let i = 0
  397. while (i < t.length) {
  398. let d = t.charCodeAt(i)
  399. if (d != 124 && d != 45 && d != 58 && d != 32 && d != 9) { return false }
  400. i = i + 1
  401. }
  402. return true
  403. }
  404. // the Markdown text → blocks (see the header): the scanner itself, no cache
  405. static parseBlocks = (text) => {
  406. out = []
  407. if (text == null || text == '') { return out }
  408. lines = ('' + text).split(NL)
  409. let para = []
  410. let inList = false
  411. let listOrdered = false
  412. let listStart = 1
  413. let items = []
  414. let blankBefore = false
  415. let i = 0
  416. while (i < lines.length) {
  417. let line = noCr(lines[i])
  418. let fence = fenceOf(line)
  419. let hr = fence == null && isHrLine(line)
  420. let q = fence == null && !hr ? quoteOf(line) : null
  421. let isTab = fence == null && !hr && q == null && line.includes('|') && i + 1 < lines.length && isSepLine(noCr(lines[i + 1])) && noCr(lines[i + 1]).includes('|')
  422. let h = fence == null && !hr && q == null && !isTab ? headingOf(line) : null
  423. let it = fence == null && !hr && q == null && !isTab && h == null ? itemOf(line) : null
  424. if (hr) {
  425. if (para.length > 0) { out.push(paraBlock(para)) }
  426. para = []
  427. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  428. inList = false
  429. items = []
  430. out.push(hrBlock())
  431. blankBefore = false
  432. i = i + 1
  433. } else if (q != null) {
  434. if (para.length > 0) { out.push(paraBlock(para)) }
  435. para = []
  436. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  437. inList = false
  438. items = []
  439. let ql = []
  440. let j = i
  441. let more = true
  442. while (j < lines.length && more) {
  443. let x = quoteOf(noCr(lines[j]))
  444. if (x == null) { more = false } else {
  445. ql.push(x)
  446. j = j + 1
  447. }
  448. }
  449. out.push(quoteBlock(ql))
  450. i = j
  451. blankBefore = false
  452. } else if (isTab) {
  453. if (para.length > 0) { out.push(paraBlock(para)) }
  454. para = []
  455. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  456. inList = false
  457. items = []
  458. let head = cellsOf(line)
  459. let rows = []
  460. let j = i + 2
  461. while (j < lines.length && noCr(lines[j]).trim() != '' && noCr(lines[j]).includes('|')) {
  462. rows.push(cellsOf(noCr(lines[j])))
  463. j = j + 1
  464. }
  465. out.push(tableBlock(head, rows))
  466. i = j
  467. blankBefore = false
  468. } else if (fence != null) {
  469. if (para.length > 0) { out.push(paraBlock(para)) }
  470. para = []
  471. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  472. inList = false
  473. items = []
  474. let code = []
  475. let j = i + 1
  476. let closed = false
  477. let fc = fence.charCodeAt(0)
  478. while (j < lines.length && !closed) {
  479. let l = noCr(lines[j])
  480. let f = fenceOf(l)
  481. if (f != null && f.charCodeAt(0) == fc && f.length >= fence.length && l.trim() == f) {
  482. closed = true
  483. } else {
  484. code.push(l)
  485. }
  486. j = j + 1
  487. }
  488. out.push(codeBlock(code))
  489. i = j
  490. blankBefore = false
  491. } else if (line.trim() == '') {
  492. if (para.length > 0) { out.push(paraBlock(para)) }
  493. para = []
  494. blankBefore = true
  495. i = i + 1
  496. } else if (h != null) {
  497. if (para.length > 0) { out.push(paraBlock(para)) }
  498. para = []
  499. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  500. inList = false
  501. items = []
  502. out.push(headingBlock(h.level, h.text))
  503. blankBefore = false
  504. i = i + 1
  505. } else if (it != null) {
  506. if (para.length > 0) { out.push(paraBlock(para)) }
  507. para = []
  508. if (inList && listOrdered != it.ordered) {
  509. out.push(listBlock(listOrdered, listStart, items))
  510. inList = false
  511. items = []
  512. }
  513. if (!inList) {
  514. inList = true
  515. listOrdered = it.ordered
  516. listStart = it.start
  517. items = []
  518. }
  519. items.push([it.text])
  520. blankBefore = false
  521. i = i + 1
  522. } else if (inList && (!blankBefore || indentOf(line) >= 2)) {
  523. // a wrapped item line (or an indented paragraph of the item): onto the last item
  524. let last = items[items.length - 1]
  525. last.push(line.trim())
  526. items[items.length - 1] = last
  527. blankBefore = false
  528. i = i + 1
  529. } else {
  530. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  531. inList = false
  532. items = []
  533. para.push(line.trim())
  534. blankBefore = false
  535. i = i + 1
  536. }
  537. }
  538. if (para.length > 0) { out.push(paraBlock(para)) }
  539. if (inList) { out.push(listBlock(listOrdered, listStart, items)) }
  540. return out
  541. }
  542. // the Markdown text → blocks, from the cache when this exact text was parsed before
  543. static markdownBlocks = (text) => {
  544. if (text == null || text == '') { return [] }
  545. let t = '' + text
  546. if (t.length > mdMaxOne) { return parseBlocks(t) }
  547. let key = sha256(t)
  548. let hit = mdCache[key]
  549. if (hit != null) {
  550. // most recently used: to the end of the order
  551. let rest = []
  552. for (k of mdOrder) { if (k != key) { rest.push(k) } }
  553. rest.push(key)
  554. mdOrder = rest
  555. return hit
  556. }
  557. let blocks = parseBlocks(t)
  558. while (mdOrder.length > 0 && (mdOrder.length >= mdMaxEntries || mdChars[0] + t.length > mdMaxChars)) {
  559. let old = mdOrder[0]
  560. mdChars[0] = mdChars[0] - mdSize[old]
  561. delete mdCache[old]
  562. delete mdSize[old]
  563. mdOrder = mdOrder.slice(1)
  564. }
  565. mdCache[key] = blocks
  566. mdSize[key] = t.length
  567. mdChars[0] = mdChars[0] + t.length
  568. mdOrder.push(key)
  569. return blocks
  570. }

Branches

Latest commits

  • 32ba9d59gitoria: leave the host-only cookie experiment out of the browser gate (gitoria#24 is a separate mission)mre
  • 43ad2bcfgitoria header: the selector alone plus your name and Log out as before the theme missions; tests follow (WIP: host-only cookie experiment fails)mre
  • ac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
  • b279f536theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 2b01515ctests/ticketskit: a failed start kills the tickets server (own process group); stop() kills the groupmre
  • 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
  • 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
  • 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
  • 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
  • d9e977f0reports/MG-mobile.md, LOGMG
  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre