/** * HTML helpers used by the corpus scanner. * * Full DOM based block segmentation belongs to the extraction pipeline and is intentionally not * done here. A corpus pass over 320k files runs this code once per message, and parsing every * newsletter into a DOM to compute aggregate statistics would dominate the whole scan. The client * hints this module looks for are literal class and id names, so a scan over the source is both * cheaper and more faithful than a DOM query, which would silently normalise malformed markup. */ /** * Decode HTML entities. Unknown entities are left as written rather than dropped. * * Both alternatives are length bounded so the pass stays linear on hostile input: a numeric * reference longer than twelve digits cannot name a code point, and an unbounded `+` there would * backtrack across the whole run of digits that follows an unterminated `&#`. */ export declare function decodeEntities(input: string): string; /** * Cheap text projection of an HTML body. * * Good enough for language estimation, marker detection and length statistics. It is not a * replacement for the extraction pipeline's DOM walk, and it deliberately keeps blank lines so that * paragraph structure survives. It is emphatically **not** a sanitiser: it produces a non executing * textual view, and says nothing about whether the source markup is safe to render. * * Written as a character scanner rather than a chain of regular expressions because the obvious * `/<[^>]*>/g` form is quadratic on unmatched `<`: every one of them rescans to end of input looking * for a closing delimiter that is not there. Measured at 5.8 seconds on 128k `<` characters, and * doubling the input quadrupled it. This is the projection the malformed HTML fallback uses, so it * is reached by exactly the input that triggers the quadratic case. * * Every code unit is visited a constant number of times. A construct that never closes is charged * to the input it covers: the scanned window is emitted as visible text and the cursor moves past * it, rather than resuming one character later and reading the same suffix again. Emitting it keeps * the projection on the safe side of the project's asymmetry, and matches what the previous regular * expression did with an unterminated trailing tag. */ export declare function stripTagsToText(html: string): string; /** Structural hints found in an HTML body, keyed by the id used in html-clients.json. */ export interface HtmlHints { ids: string[]; hasBlockquote: boolean; blockquoteCount: number; hasTable: boolean; tableCount: number; hasImage: boolean; /** True when the markup contains an unclosed tag pattern that suggests malformed HTML. */ suspectMalformed: boolean; } /** Detect client structure hints without building a DOM. */ export declare function detectHtmlHints(html: string): HtmlHints; //# sourceMappingURL=html.d.ts.map