/** * @file * * A container-aware pre-pass over a note's body that finds which lines start a list item, and which lines sit inside a * block that hides them: a fenced code block, a `%%` comment, a `$$` math block or an indented code block. Obsidian * never reports a list item inside one of those, and an unclosed one runs to the end of its container, which is the * end of the note at the top level. A regular expression over the whole note cannot see either fact, since both depend * on the blockquote levels and list items the block sits in. * * The container model follows CommonMark's, with the departures measured against Obsidian 1.14.4: * * - A line that leaves a container is a lazy continuation of whatever block is open, a fenced code block or a comment * included, unless it starts a block that can interrupt a paragraph, or follows a blank line. * - A `$$` line lazily continuing a list item opens a math block inside the item, while one leaving a blockquote ends * the blockquote. Either needs a line break after it in the text the list item around it gathers. * - A line indented four or more columns past a blockquote it does not continue is no lazy continuation: it ends the * blockquote and starts an indented code block. * - A `>` line that lazily continues a list item opens a blockquote inside that item, which later `>` lines continue at * any indent. * - A list marker of the closed item's kind on a line that closes a list item starts the next item at any indent; a * marker of another kind ends the list there. * - An indented code block inside a list item is measured from the column Obsidian strips the item's lines to, which is * the least indent among them, and at most the marker's width (see {@link getBulletWidth}). * - A whitespace-only line led by a tab continues a paragraph outside a list item. * - Only a bullet or an ordered marker numbered 1 starts a list that interrupts a paragraph. * - A line starting an ordered item not numbered 1 continues a blockquote lazily, and is read inside it as if it carried * the quote's prefix. */ /** * What the pre-pass found, by line number in the note. */ export interface LeafBlockScan { /** * Non-blank lines that leave a blockquote without being a lazy continuation, so they end it, each with the number of * blockquote levels it stays inside. */ readonly breakLines: ReadonlyMap; /** * Lines that close a fenced code block, a comment or a math block. */ readonly closerLines: ReadonlySet; /** * Lines inside a fenced code block, a comment, a math block or an indented code block, other than the line that opens * it. Such a line is never a list item and never ends one. */ readonly contentLines: ReadonlySet; /** * Lines that open a fenced code block, a comment or a math block outside a blockquote, which unlike an indented code * block runs on until a line closes it or its container ends. */ readonly hidingOpenerLines: ReadonlySet; /** * Lines that start a list item, each with the index of every marker on it. A line can start several items, each * nested in the one before it: `- - x` is an item holding a nested item. */ readonly itemMarkerIndexes: ReadonlyMap; /** * Lines that continue blockquote levels lazily, with no `>` of their own for those levels, and that are still read * inside them, each with the number of blockquote levels it sits in. Only a line that starts an ordered list item not * numbered 1 is one, since that item cannot interrupt the blockquote: `> - q\n2. y` is one blockquote holding both * items. */ readonly lazyQuoteLines: ReadonlyMap; /** * Lines that close a list item with a marker of another kind than the item's, indented too far to start an item, so * they end the item's list and start an indented code block rather than continuing the item lazily. */ readonly listEndLines: ReadonlySet; /** * Lines that open a fenced code block, a comment, a math block or an indented code block. */ readonly openerLines: ReadonlySet; } /** * Computes the widest indent Obsidian strips from a list item's later lines before it reads the item's blocks: the * width of the marker and the spaces after it, which are one to four spaces not followed by another, and otherwise one. * `remark-parse` 8, which Obsidian's metadata worker runs, widens an ordered marker below 10 with a `.` by one column * whenever the item's indent, marker and spaces together have an odd length, so `1. A` strips four columns where its * content starts at the third. * * @param indentLength - How many characters of indent stand before the marker inside the item's container. * @param marker - The marker, such as `-` or `1.`. * @param afterMarker - The line's text after the marker. * @returns The width, from the marker's column. */ export declare function getBulletWidth(indentLength: number, marker: string, afterMarker: string): number; /** * Computes the column a list item's content starts at, as `remark-parse` 8 measures it on the marker's line: right past * a tab that follows the marker, past one to four spaces that do, and one column past the marker when more spaces * follow it. A tab after spaces is content, so `- \tx` has its content at the third column. A marker that ends its line * has its content right past it. * * @param markerEndColumn - The visual column right past the marker. * @param afterMarker - The line's text after the marker. * @returns The visual column. */ export declare function getItemContentColumn(markerEndColumn: number, afterMarker: string): number; /** * Measures the marker-like run a line's text opens with when it starts no list item: a bullet, or a number with its * delimiter, followed by anything but whitespace, as in `-x`, `---` or `10.x`. `remark-parse` 8 counts that run into the * line's indent before it finds no whitespace after it, and then decides whether the line belongs to the list item above * by that indent, so `-\n\n-x` and `-\n---` are each one item, holding a paragraph and a thematic break. * * @param text - The line's text past its whitespace. * @returns The run's width, or `0` when the text opens with none. */ export declare function getMarkerLikeWidth(text: string): number; /** * Checks whether the whitespace before a `>` inside a line's quote prefix indents it four or more columns past the * quote level before it, which makes it the start of an indented code block rather than a nested blockquote. The * columns are measured as the scan measures them, so a tab straight after a `>`, or after its optional space, is four. * * @param line - The line. * @param levelEnd - The index just past the quote level before it. * @param markerIndex - The index of the `>`. * @returns Whether the `>` opens no nested blockquote. */ export declare function isNestedQuoteMarkerIndented(line: string, levelEnd: number, markerIndex: number): boolean; /** * Scans a note's body for list items and the blocks that hide them. * * @param lines - The note's lines, without their line breaks. * @param firstLine - The first line of the body, past any frontmatter. * @returns What the scan found. */ export declare function scanLeafBlocks(lines: readonly string[], firstLine: number): LeafBlockScan;