/** * @file * * The top-level blocks of the text between two sections the parser has already found, read the way Obsidian's metadata * worker reads them. That worker is `remark-parse` 8 with `commonmark` and `gfm` on, plus block tokenizers of * Obsidian's own - a `%%` comment, a `$$` math block, a footnote definition and a standalone block id - so each tokenizer * below is a port of one of those, quirks and all: * * - A block's position starts at its line start, its indent included, and ends at the end of its last line, trailing * whitespace included. An unclosed fenced code block, comment, math block or HTML block of the first five kinds runs to * the end of the text, its final line break included. * - A line is an indented code block when it starts with a tab or with four spaces. A tab after a space indents nothing, * so ` \tx` is a paragraph. * - A paragraph is interrupted by a thematic break, an ATX heading, a fence, a comment, a math block, a blockquote and * the first six kinds of HTML block, but never by a line indented four or more columns. * - A blockquote takes every `>` line and every lazy line after it, until a blank line, or a line that starts an indented * code block, a fence, a comment, a math block, an ATX or setext heading, a thematic break or an HTML block of the first * six kinds. * - A comment ends just past its closing `%%`, wherever on the line that is, and the rest of the line starts a paragraph. * - A table row needs a `|` past its first character, and keeps the header's choice of a leading `|`. * - A link reference definition, a footnote definition or a standalone block id interrupts no paragraph. * * List items are not read here. */ /** * What a link reference definition names, as {@link readDefinitionParts} reads it. */ export interface DefinitionParts { /** * The destination, out of its angle brackets, with its escapes and character references still as written. */ readonly destination: string; /** * The label, as written between the brackets, escapes included. */ readonly label: string; } /** * A block found in the text. */ export interface GapBlock { /** * The id of a standalone block id, which is no section of its own. */ readonly blockId?: string; /** * The offset just past the block, relative to the text. */ readonly end: number; /** * The heading's level and text, when the block is a heading. */ readonly heading?: GapHeading; /** * The offset the block starts at, relative to the text. */ readonly start: number; /** * The section type Obsidian reports for the block. */ readonly type: string; } /** * A heading found in the text. */ export interface GapHeading { /** * The heading level, from `1` to `6`. */ readonly level: number; /** * The heading text, without its markers. */ readonly text: string; } /** * A block read at the start of a text. */ export interface GapToken { /** * The id of a standalone block id. */ readonly blockId?: string; /** * The heading's level and text, when the block is a heading. */ readonly heading?: GapHeading; /** * How much of the text the block takes. */ readonly length: number; /** * The section type Obsidian reports for the block. */ readonly type: string; } type Token = GapToken; /** * What a line ending an HTML block of the last two kinds holds: nothing, since such a block ends before an empty line. */ export declare const BLANK_LINE_END_REGEX: RegExp; /** * One of the seven kinds of HTML block CommonMark defines. */ export interface HtmlBlockKind { /** * Whether the kind may interrupt a paragraph or a blockquote. */ readonly canInterrupt: boolean; /** * What a line ending the block holds; an empty line for the last two kinds, which end before it. */ readonly end: RegExp; /** * What the block's first line starts with. */ readonly start: RegExp; } /** * The type of the token a standalone block id is read as. Obsidian reports no section for it: the parser gives its id to * the section before it and drops it. */ export declare const BLOCK_ID_TYPE = "blockId"; /** * Checks whether a text starts an HTML block of a kind that may interrupt a paragraph or a blockquote: one of the first * six. * * @param text - The text, from the line start. * @returns Whether it does. */ export declare function canHtmlBlockInterrupt(text: string): boolean; /** * Finds the kind of HTML block a text starts with, if any, by its first line. * * @param text - The text, from the line start. * @returns The kind. */ export declare function findHtmlBlockKind(text: string): HtmlBlockKind | null; /** * Reads the label and the destination of a link reference definition {@link tokenizeDefinition} has found, both as they * are written: the label with its escapes, and the destination out of its angle brackets but not yet unescaped. * * @param text - The definition's text, from its line start. * @returns The label and the destination. */ export declare function readDefinitionParts(text: string): DefinitionParts; /** * Reads the top-level blocks of a text that holds no list item the parser has already found. * * @param text - The text. * @param isAtNoteEnd - Whether the text runs to the end of the note, which a standalone block id can need. * @returns The blocks, in order, with positions relative to the text. */ export declare function scanGapBlocks(text: string, isAtNoteEnd: boolean): GapBlock[]; /** * Reads an ATX heading at the start of a text: a run of one to six `#`, then whitespace or the end of the line. * * @param text - The text, from the heading's line start. * @returns The heading, if the text starts with one. */ export declare function tokenizeAtxHeading(text: string): GapToken | null; /** * Reads a link reference definition, a port of `remark-parse` 8's: a label in brackets and a `:`, a destination after * any whitespace, line breaks included, an optional title after more of it, and nothing else on the last line. A title * that opens and never closes, or holds an empty line, spoils the whole definition rather than being left out. * * @param text - The text, from the definition's line start. * @returns The definition, if the text starts with one. */ export declare function tokenizeDefinition(text: string): null | Token; /** * Reads a table: a header row, a delimiter row and the rows after it. Every row holds a `|` past its first character, * and starts with a `|` exactly when the header does. * * @param text - The text, from the table's line start. * @returns The table, if the text starts with one. */ export declare function tokenizeTable(text: string): null | Token; export {};