/** * Where each character of a rendered block came from in its Markdown source. * * The rich surface and the preview show DOM, while selections, comments, * peers' carets and every edit are source offsets. A BlockMap pairs one block * element with the source it was rendered from (or serialized to) and * translates between the two. * * It is built by walking the block in document order with a pointer into the * source. The syntax an element implies — a heading's `#`, a list marker, * emphasis delimiters, a link's `](url)` — is skipped on entering and leaving * it, and every character of text is matched forward: literally, as a * backslash escape, or as an entity. Atoms carry their source in * `data-md-src`. Whatever cannot be matched maps to a zero-width position, so * an unexpected shape degrades the map to "close" instead of breaking it. */ export interface SourceUnit { node: Node; /** Code unit in a Text node; -1 for an element taken as a whole (atom, image, break, checkbox). */ index: number; start: number; end: number; } export interface DomPoint { node: Node; offset: number; } export interface SourceDomPoint extends DomPoint { /** * The outermost inline element the source position lies outside of while * the DOM point sits inside it — the caret after `**bold**` is still in the * ``. Typing there must first step out of `element`. */ outside: { element: Element; side: 'before' | 'after'; } | null; } export interface SourceRect { left: number; top: number; width: number; height: number; } /** Marks a span the rich surface shows an element's Markdown in; its text is that source verbatim. */ export declare const REVEAL_ATTRIBUTE = "data-md-reveal"; export declare function isMarkdownAtom(node: Node | null | undefined): node is HTMLElement; /** An atom's exact Markdown, or null for an ordinary element. */ export declare function atomSource(node: Node): string | null; /** The newlines marked puts between block tags: markup formatting, not content. */ export declare function isFormattingWhitespace(node: Text): boolean; /** * A `
` with nothing after it in its block draws no line: it only gives an * empty block its height, as the surface and the browser add to hold a caret. * It has no source. */ export declare function isPlaceholderBreak(br: Element): boolean; export declare class BlockMap { readonly units: SourceUnit[]; /** Source span of every element walked, opening syntax to closing syntax. */ private readonly ranges; private readonly firstUnit; private p; /** Inside a revealed span: no element implies syntax, every character is itself. */ private verbatim; /** Where the line of the table row being walked ends. */ private rowEnd; readonly root: Element; readonly raw: string; constructor(root: Element, raw: string); private push; private skip; private walkChildren; private walkElement; /** Skips the opening syntax of an inline element; returns the skip for its closing syntax. */ private openInline; /** `](destination "title")`, `][label]` or a lone `]`. */ private closeBracketLink; private walkAtom; private walkBreak; /** Rendered images are atoms; this covers an `` that arrived without its source. */ private walkImage; private inCode; private walkText; /** The source span of an element unit (checkbox, atom, image) or a walked element. */ rangeOf(el: Element): [number, number] | null; unitOf(el: Element): SourceUnit | null; private enclosingAtom; /** * The source offset of a DOM point. Between two characters with syntax in * between (a code block's indent, a closing `**`), `bias` 1 takes the * position before the next character — where typing lands — and -1 the one * after the previous character, which is what a selection's end wants. */ domToSource(node: Node, offset: number, bias?: -1 | 1): number; private startOf; private endOf; /** Locates an unmapped DOM point between the units around it. */ private byOrder; private unitPoint; private before; private after; private outside; /** * Whether `pos`, between units on two lines (list items, a quote's * paragraphs, table cells), comes before the break between them. A closing * `**` there ends the line it is on; it is not the start of the next one. */ private endsLine; sourceToDom(pos: number): SourceDomPoint; /** Client rects of the source range, one per text run or element, never the whole block. */ rangeRects(from: number, to: number): SourceRect[]; /** A zero-width rect where the caret for `pos` would be drawn. */ caretRect(pos: number): SourceRect | null; }