import type { InlineIcon, InlineSpan, RefCase, RefStyle, SwatchShape } from './types.js'; import type { TabStop } from '../types.js'; /** Atomic plain-text placeholder for an inline reference span. One code unit * per `:ref{…}` so `sourceMap` stays 1-to-1 (mirroring the inline-math * `MATH_PLACEHOLDER` technique). A distinct code point from the math * placeholder so `sourceMap` building and span injection can tell the two * apart even when a paragraph mixes refs and math. */ export declare const REF_PLACEHOLDER = "\u2063"; /** Atomic plain-text placeholder for an inline colour swatch span * (`:swatch{…}`), one code unit per swatch like the ref and math * placeholders, and a code point of its own so the three never collide. */ export declare const SWATCH_PLACEHOLDER = "\u2064"; /** Atomic plain-text placeholder for an inline chip (`:chip[…]`), one * code unit per chip. A private-use code point: the chip's words are never * painted from it (they live in the span's `chip.spans`). */ export declare const CHIP_PLACEHOLDER = "\uE1A0"; /** `text` without its chip placeholders, each with the space before it * (a chip at the start takes the space after it): a heading's title as * its contents entry, running heads and bookmarks read it (#1100). */ export declare function withoutChips(text: string): string; /** Atomic plain-text placeholder for a footnote marker (`[^id]`), one code * unit per marker. A private-use code point of its own. */ export declare const FOOTNOTE_PLACEHOLDER = "\uE1A6"; /** Metadata of an inline footnote marker `[^id]`. */ export interface FootnoteMarkerMeta { id: string; /** Absolute source offset of the `[`. */ sourceStart: number; /** Absolute source offset just past the `]`. */ sourceEnd: number; } /** * Extract footnote markers (`[^id]`) from a line's text, replacing each by * `FOOTNOTE_PLACEHOLDER` and returning their metadata in order. Runs right * after {@link extractInlineChips}. */ export declare function extractInlineFootnotes(text: string, fallbackStart: number): { cleaned: string; markers: FootnoteMarkerMeta[]; }; /** Attach a `footnote` to each `FOOTNOTE_PLACEHOLDER` occurrence in order. */ export declare function injectFootnoteSpans(spans: InlineSpan[], markers: FootnoteMarkerMeta[]): InlineSpan[]; /** Forced line break inside a title: `\\` in a heading (or a part `title`) * becomes this LINE SEPARATOR in the plain text. Opener designs render it * as a real line break; the in-column heading, running heads, outlines and * `{chapterTitle}` show a space instead. */ export declare const BREAK_PLACEHOLDER = "\u2028"; /** `\\` with optional surrounding spaces. */ export declare const TITLE_BREAK_RE: RegExp; /** Forced line break in a resource snippet (caption, note, table cell): * `\\`, as in a title, or a backslash that ends a line (Markdown's hard * break), with the spaces before it and, after `\\`, the spaces and one * newline that follow. The indentation of the next line is kept: in a * table cell two leading spaces nest a list item. It becomes * {@link BREAK_PLACEHOLDER} in the snippet's plain text (see * {@link replaceSnippetBreaks}); a plain newline stays a space in captions * and notes. */ export declare const SNIPPET_BREAK_RE: RegExp; /** * `text` with each title break ({@link TITLE_BREAK_RE}: `\\` and the * spaces and tabs around it) replaced by `by`, as * `text.replace(TITLE_BREAK_RE, by)` replaces them. A scan in one pass: the * expression's leading run of spaces is tried again from each position of * a long run that no break ends. */ export declare function replaceTitleBreaks(text: string, by: string): string; /** * `[start, end)` of the text between the braces of each inline directive's * `{…}` attributes in `text`, in order: the directives named in `braced` * take them right after the name (`:ref{…}`), those in `bracketed` after a * `[…]` text (`:chip[…]{…}`, the text never empty unless `emptyText`). What * a global expression of those alternatives finds — the attributes on one * line, a `\\]` in the text no bracket — read in one pass, where the * expression would read a long line again from every unclosed directive. */ export declare function directiveAttrRanges(text: string, braced: readonly string[], bracketed: readonly string[], emptyText?: boolean): Array<[number, number]>; /** Positions of the break placeholder in a plain text. */ export declare function titleBreakIndices(text: string): number[]; /** Whether `ch` (one character, a surrogate pair included) is Han, kana, * CJK punctuation or a fullwidth form. */ export declare function isCjkWideChar(ch: string | undefined): boolean; /** The character that ends at `at` (exclusive), a surrogate pair whole. */ export declare function charBefore(text: string, at: number): string | undefined; /** The character that starts at `at`, a surrogate pair whole. */ export declare function charFrom(text: string, at: number): string | undefined; /** What goes between a text and a suffix set after it (a continued * caption's or box title's `continuedSuffix`): nothing when the suffix * opens with a wide character, since Chinese sets `(续)` solid against the * text and the fullwidth bracket carries its own space; one space * otherwise (`(cont.)`, after Chinese text too, which keeps a gap before * Latin). */ export declare function suffixJoiner(suffix: string): '' | ' '; /** Whether two characters meet as Chinese or Japanese text does: both wide, * or a Chinese dash or ellipsis beside a wide one. */ export declare function joinsWide(before: string | undefined, after: string | undefined): boolean; /** Replace the break placeholder with a space (single-line contexts): an * ideographic space (U+3000) between two Chinese or Japanese characters, * so a couplet title `甄士隱夢幻識通靈 \\ 賈雨村風塵懷閨秀` reads * `甄士隱夢幻識通靈 賈雨村風塵懷閨秀` in the column, the contents and the * running heads (and `「紅樓夢」 \\ ——序` reads `「紅樓夢」 ——序`); one * space anywhere else. One character for one, so the source map holds. */ export declare function flattenTitleBreaks(text: string): string; /** What a forced title break reads as in plain text (PDF bookmarks, the * document title): the ideographic space between two Chinese or Japanese * characters, as {@link flattenTitleBreaks} sets it; nothing where such a * character meets a digit or Latin text, since plain Chinese text puts no * space there (the page sets the Han–Latin space, `cjk.latinSpacing`); * one space between Latin words. */ export declare function plainTitleBreak(before: string | undefined, after: string | undefined): '' | ' ' | '\u3000'; /** Replace the break placeholder as plain text reads it (see * {@link plainTitleBreak}). Unlike {@link flattenTitleBreaks} the text may * get shorter: it maps to no source. */ export declare function plainTitleBreaks(text: string): string; /** {@link flattenTitleBreaks} over a block's spans, read against the whole * `text` (the spans' texts joined): a break at a span's edge sees both of * its neighbours. Maths spans are kept as they are. */ export declare function flattenTitleBreakSpans(text: string, spans: readonly T[]): T[]; /** Insert `\n` at the recorded break indices when the (possibly uppercased * or otherwise length-preserving transformed) title still has the parsed * length; otherwise the title is returned unchanged. */ export declare function applyTitleBreaks(title: string, breaks: readonly number[] | undefined, parsedLength: number): string; /** Resolved metadata for an inline `:ref{…}` directive. The owning span's * `text` is a single `REF_PLACEHOLDER`; the pipeline later resolves the * reference to its computed number/label. */ export interface RefMeta { resourceId: string; style?: RefStyle; text?: string; case?: RefCase; /** Absolute source offset of the leading `:` of `:ref{…}`. */ sourceStart: number; /** Absolute source offset just past the closing `}`. */ sourceEnd: number; } /** * Extract inline `:ref{…}` references from a line's text. * - Returns a cleaned text where each match is replaced by `REF_PLACEHOLDER`. * - Returns the list of ref metadata aligned with the order of placeholders. * * This runs as the first inline pre-pass (before math and formatting) so that * a `text="…"` attribute cannot be mangled by later passes. * * `fallbackStart` is the absolute source offset of `text[0]` in the original * markdown; ref offsets are computed relative to it. */ export declare function extractInlineRefs(text: string, fallbackStart: number): { cleaned: string; refs: RefMeta[]; }; /** Metadata of an inline `:swatch{color="…"}` directive: the colour as * written (a hex, or a palette entry id the pipeline resolves) and its * source extent. */ export interface SwatchMeta { color: string; /** Absolute source offset of the leading `:` of `:swatch{…}`. */ sourceStart: number; /** Absolute source offset just past the closing `}`. */ sourceEnd: number; /** An inline symbol (`:icon[alt]{…}`, #1058) read in the swatch's * place: `color` is then its tint as written (`''` for none). */ icon?: InlineIcon; /** `size`, `border`, `borderColor`, `borderWidth`, `radius` and `gap` * as written (#1104). */ shape?: SwatchShape; } /** The shape attributes of a `:swatch{…}` (#1104): `size`, `radius` and * `gap` lengths (`8pt`, `0.9em`; a bare number is in points), `border` * as `none` or a width and a colour in either order (`1pt #333`), * `borderColor` and `borderWidth` on their own (they win over `border`). * A value that does not read is left out; undefined when none reads. */ export declare function swatchShapeFromAttrs(attrs: Readonly>): SwatchShape | undefined; /** * Extract inline `:swatch{…}` colour swatches from a line's text, replacing * each by `SWATCH_PLACEHOLDER` and returning the swatch metadata in order. * `:swatch{…}` takes the same attribute grammar as `:ref{…}`; a swatch * without a `color` is not a swatch (left as text). With `icons`, the * inline symbols (`:icon[alt]{resource=…|glyph=…|line=…}`, #1058) are read * too, in the same placeholder: a figure label's text, a caption, a note, * a table cell (not the body text in this round). * Runs right after {@link extractInlineRefs} on its cleaned text. */ export declare function extractInlineSwatches(text: string, fallbackStart: number, options?: { icons?: boolean; }): { cleaned: string; swatches: SwatchMeta[]; }; /** Plain-text placeholder of a tab (#622) while a paragraph's inline marks * are read; the spans' text has `'\t'` in its place (`buildBlockMapping`). */ export declare const TAB_PLACEHOLDER = "\uE1A8"; /** Metadata of a tab (#622): a tab character of the source (`literal`), or * `:tab` with the one-off stop of its attributes. */ export interface TabMeta { literal?: true; /** Tab characters in a row (spaces between them aside): one tab of the * plain text that goes on this many stops. */ count?: number; stop?: TabStop; } /** * Take the tabs of a paragraph's text out (#622): every `:tab` (with its * attributes, see `tabStopFromAttrs`) and every tab character becomes * {@link TAB_PLACEHOLDER}, outside inline code, link destinations and * directive attributes. Runs on the text with its chips, references, * swatches and maths already taken out. */ export declare function extractInlineTabs(text: string): { cleaned: string; tabs: TabMeta[]; }; /** Attach a `tab` to each {@link TAB_PLACEHOLDER} in order; the tab is a * span of its own. */ export declare function injectTabSpans(spans: InlineSpan[], tabs: TabMeta[]): InlineSpan[]; /** Metadata of an inline `:chip[text]{style="…"}`: the text as written * between the brackets, the style id and the source extent. */ export interface ChipMeta { /** Whitespace collapsed and trimmed; `''` for a chip of spaces alone. */ text: string; style?: string; /** Absolute source offset of the leading `:` of `:chip[…]`. */ sourceStart: number; /** Absolute source offset just past the directive (`]` or its `{…}`). */ sourceEnd: number; } /** * `:chip[text]` with an optional `{attrs}` right after the bracket * (`/:chip\[((?:\\.|[^\]\\\n])+)\](?:\{([^}\n]*)\})?/g`). The text is * one line, may not be empty (`:chip[]` stays literal text) and takes `\]` * for a literal bracket. Text of spaces alone (NBSP included) makes an empty * chip: a blank box as wide as its style's padding. * * Extract inline `:chip[…]` chips from a line's text, replacing each by * `CHIP_PLACEHOLDER` and returning the chip metadata in order. Runs first, * before {@link extractInlineRefs}, so the chip text (which may hold marks * of its own) is shielded from the later passes. */ export declare function extractInlineChips(text: string, fallbackStart: number): { cleaned: string; chips: ChipMeta[]; }; /** Attach a `chip` to each `CHIP_PLACEHOLDER` occurrence in order; the chip * span is its own entry carrying the ambient bold / italic, and its words * are parsed for their own inline marks. A chip's label is not parsed for * maths, so its `\$` is unescaped here, as in the running text. */ export declare function injectChipSpans(spans: InlineSpan[], chips: ChipMeta[]): InlineSpan[]; /** Attach a `swatch` to each `SWATCH_PLACEHOLDER` occurrence in order; the * swatch span is its own entry, like a ref's. */ export declare function injectSwatchSpans(spans: InlineSpan[], swatches: SwatchMeta[]): InlineSpan[]; /** Walk an InlineSpan list and attach a `ref` to each `REF_PLACEHOLDER` * occurrence in order. Splits plain-text spans around the placeholder so the * ref span is its own entry (carrying the ambient bold/italic). Mirrors * `injectMathSpans`. */ export declare function injectRefSpans(spans: InlineSpan[], refs: RefMeta[]): InlineSpan[]; export declare function protectEscapes(text: string): string; export declare function restoreEscapes(text: string): string; export declare function protectCodeSpans(text: string): string; /** `:smallcaps[text]`: the text set in small capitals. The text is one * line, may not be empty, may hold other inline marks and takes `\]` for a * literal bracket (like `:chip[…]`). */ export declare const INLINE_SMALLCAPS_RE: RegExp; /** Opening of a `:smallcaps[` run in the source (see `computeSourceMap`). */ export declare const SMALLCAPS_OPENER = ":smallcaps["; /** Opening of a highlight mark (`:mark[text]{style="…"}`, #888) in the * source. */ export declare const MARK_OPENER = ":mark["; /** Where the `:mark[` at `at` ends: past its closing `]` and the `{…}` * attributes right after it (on the same line), with the text between * the brackets and the attributes. The text may hold other inline marks, * links included (brackets nest), may run over a soft line break and * takes `\]` for a literal bracket; it may not be empty. Undefined when * the bracket does not close before a blank line or the end. */ export declare function readMarkAt(text: string, at: number): { end: number; inner: string; attrs?: string; } | undefined; /** `spans` with the whitespace at the start of the first and at the end of * the last trimmed, as `String.prototype.trim` trims their joined text; * spans left empty are dropped and link ranges follow their text. */ export declare function trimSpans(spans: InlineSpan[]): InlineSpan[]; /** `spans` set plain: bold, italic, scripts, small capitals, links and the * Chinese and Japanese marks (emphasis dots, proper-name and book-title * marks, side lines) dropped, * adjacent text spans merged — a heading's spans as they were built before * headings read inline marks (`headings.inlineMarks: false`). Formulas, * references, swatches, ruby, kanbun marks and warichu notes keep their * own spans, and so do characters the layout added (a book title's 《》). */ export declare function plainSpans(spans: readonly InlineSpan[]): InlineSpan[]; /** The text {@link parseInlineFormatting} sets, without its spans: each * mark taken out leaves a {@link MARKUP_BOUNDARY}, as the parser's own * marks and span splits do, so an `_` next to bold, a link or code opens * emphasis in a heading as it does in a paragraph. */ export declare function stripInlineFormatting(text: string): string; /** `^text^` (superscript) and `~text~` (subscript): the marked text starts * and ends with a non-space character and carries no other marker of the * same kind, so a stray caret or tilde in prose stays literal. The faces * `^_^` and `^o^` never reach them (see `protectEscapes`). */ export declare const SUPERSCRIPT_RE: RegExp; export declare const SUBSCRIPT_RE: RegExp; /** * The target of a Markdown link destination (`url`, `url "title"`, ``) * when it is safe to follow: an `http:`, `https:`, `mailto:`, `tel:` or * `ftp:` URL, or a relative one (`../guide`, `#top`). Spaces inside `<…>` * are percent-encoded; anything else unsafe or malformed gives undefined. */ export declare function linkHref(destination: string): string | undefined; /** * Turn the forced line breaks of a resource snippet ({@link SNIPPET_BREAK_RE}) * into {@link BREAK_PLACEHOLDER}. A `\\` inside a link destination belongs * to the URL (an escaped backslash, as in CommonMark) and one inside a * directive's attributes (a ref's `text="…"`) to the value: both stay. Run * after {@link protectCodeSpans}, so inline code keeps its backslashes too. */ export declare function replaceSnippetBreaks(text: string): string; /** * Turn the forced line breaks of a paragraph, a quotation or a list item * (#620, see `BODY_BREAK_RE`) into {@link BREAK_PLACEHOLDER}, as * {@link replaceSnippetBreaks} does in a caption: a backslash at the end of * a source line (CommonMark's hard break) or `\\` before a space. Run on * the text with its maths and chips already taken out, and its inline code * protected, so a `\\` in a formula or in code stays; one inside a link * destination or a directive's attributes stays too. A break that opens or * ends the block is no break (CommonMark: a backslash at the end of a * paragraph prints), and two in a row are one. A line feed left (a line * join no break took) reads as the space it stands for. The break is * written as `mark`: the block parser passes {@link BODY_BREAK_MARK}, which * the emphasis patterns read as any character (U+2028 is a line terminator * to a regular expression's `.`), and turns it into the placeholder in the * spans ({@link bodyBreakSpans}). */ export declare function replaceBodyBreaks(text: string, mark?: string): string; /** A forced line break of body text while its inline formatting is read * (see {@link replaceBodyBreaks}). */ export declare const BODY_BREAK_MARK = "\uE1A7"; /** The spans with every {@link BODY_BREAK_MARK} set as * {@link BREAK_PLACEHOLDER} (the same length: link ranges hold). */ export declare function bodyBreakSpans(spans: InlineSpan[]): InlineSpan[]; export declare function protectDollarEscapes(text: string): string; /** * Parse inline formatting to produce spans with bold and italic flags. * Recognizes ***bold italic***, **bold**, *italic* (and underscore equivalents), * `^sup^` / `~sub~` and `:smallcaps[…]`. */ export declare function parseInlineFormatting(text: string): InlineSpan[]; //# sourceMappingURL=inlineFormatting.d.ts.map