/** * The block half of Markdown, scanned once for every served page. * * Two surfaces render a Markdown document — the review page (`extensions/plan`) and the * browse file view (`extensions/file-browse`) — and both need the same answer to "where * does a block begin and end". The review anchors a comment to a source line, so a block * is what a person points at; browse renders a README a file holds, so a block is what a * reader sees. This module is that one answer: it splits lines into source-anchored blocks * and carries the structure an emitter would otherwise parse a second time. * * The scan is deliberately smaller than CommonMark: the constructs a plan and a README * use, with every block keeping its raw source lines so a caller can render, edit or hash * exactly what it read. Blank lines are blocks of their own, because the review renders no * line for one but a comment placed in blank space resolves through them to the nearest * content block. * * The structure here is the *document's*, not a page's: a caller with a stricter rendering * rule decides that at its emitter. Browse refuses a table whose delimiter row does not * match its header, and runs one blockquote across a blank line where the scan keeps two * blocks — both decisions that would move an anchor if they lived in the scan. * * Value-only, and no page imports it the other way round: `lib/web` never reaches into an * extension. */ /** * A markdown heading outside a fence: up to three leading spaces, a space after the * hashes, and a closing hash run only when a space separates it, so `## C#` keeps its * title. Shared with the plan's section split, so the outline and the block scan read a * heading line the same way. */ export const HEADING = /^ {0,3}(#{1,6})\s+(.*?)(?:\s+#+)?\s*$/; /** * A markdown code-fence opener or closer (backticks or tildes). A tab-indented fence is * prose for every reader, never code for one and prose for another. */ export const FENCE = /^ {0,3}(`{3,}|~{3,})/; /** A list marker with its leading indentation, its trailing gap and the item's own text. */ const LIST_ITEM = /^( *)([-*+]|\d+[.)])(\s+)(.*)$/; /** A blockquote line. */ const QUOTE = /^ {0,3}>/; /** A thematic break (`---`, `***`, `___`, spaced or not). */ const THEMATIC_BREAK = /^ {0,3}(?:(?:\*\s*){3,}|(?:-\s*){3,}|(?:_\s*){3,})$/; /** A line that can be a table row: it carries at least one pipe. */ const TABLE_ROW = /\|/; /** A GFM alignment row (`| --- | :--: |`), with or without edge pipes. */ const TABLE_DELIM = /^ {0,3}\|? *:?-+:? *(?:\| *:?-+:? *)*\|? *$/; /** What a caller may tell the scan that the text alone cannot say. */ export interface ScanOptions { /** * How far a raw-HTML block runs from `index`, or `undefined` when this line opens none. * * The page owns this: which tags are allowed, and where a suppressed element (`