UNPKG

fortissimo-html

Version:

Fortissimo HTML - Flexible, Forgiving, Formatting HTML Parser

142 lines 5.14 kB
import { DocType, DomNode } from './dom'; export interface HtmlParserOptions { emptyEndTag?: boolean; eol?: string | boolean; fast?: boolean; tabSize?: number; xmlMode?: boolean; } export declare class ParseResults { domRoot: DomNode; characters: number; errors: number; implicitlyClosedTags: number; lines: number; stopped: boolean; totalTime: number; unclosedTags: number; toString(): string; } export declare enum State { OUTSIDE_MARKUP = 0, AT_ATTRIBUTE_ASSIGNMENT = 1, AT_ATTRIBUTE_START = 2, AT_ATTRIBUTE_VALUE = 3, AT_END_TAG_START = 4, AT_MARKUP_START = 5, AT_START_TAG_START = 6, IN_END_TAG = 7, AT_COMMENT_START = 8, AT_DECLARATION_START = 9, AT_PROCESSING_START = 10, IN_SCRIPT_ELEMENT = 11, IN_STYLE_ELEMENT = 12, IN_TEXT_AREA_ELEMENT = 13 } declare type AttributeCallback = (leadingSpace: string, name: string, equalSign: string, value: string, quote: string) => void; declare type BasicCallback = (depth: number, text: string, terminated: boolean) => void; declare type CompletionCallback = (results?: ParseResults) => void; declare type DocTypeCallback = (docType: DocType, terminated: boolean) => void; declare type EncodingCallback = (encoding: string, normalizedEncoding?: string, explicit?: boolean) => boolean; declare type EndTagCallback = (depth: number, tag: string, innerWhitespace: string) => void; declare type ErrorCallback = (error: string, line?: number, column?: number, source?: string) => void; declare type StartTagEndCallback = (depth: number, innerWhitespace: string, end: string) => void; declare type TextCallback = (depth: number, text: string, possibleEntities: boolean) => void; declare type EventType = 'attribute' | 'cdata' | 'comment' | 'completion' | 'declaration' | 'doctype' | 'encoding' | 'end-tag' | 'error' | 'generic' | 'processing' | 'request-data' | 'start-tag-end' | 'start-tag-start' | 'text'; export declare class HtmlParser { private static TEXT_STARTERS; private static DEFAULT_OPTIONS; private static tagForState; private attribute; private charset; private callbacks; private checkingCharset; private collectedSpace; private column; private columnIncrement; private contentType; private currentTag; private currentTagLc; private dom; private fast; private htmlSource; private leadingSpace; private line; private markupColumn; private markupLine; readonly options: HtmlParserOptions; private parseResults; private parserRunning; private pendingCharset; private pendingSource; private pendingReset; private preEqualsSpace; private putBacks; private reWhitespace; private reText; private reComment; private reDeclaration; private reAttribValue; private startTime; private state; private stopped; private tabSize; private textColumn; private textLine; private xmlMode; private yieldTime; constructor(options?: HtmlParserOptions); on(event: 'attribute', callback: AttributeCallback): HtmlParser; on(event: 'cdata' | 'comment' | 'declaration' | 'generic' | 'processing' | 'start-tag-start', callback: BasicCallback): HtmlParser; on(event: 'completion', callback: CompletionCallback): HtmlParser; on(event: 'doctype', callback: DocTypeCallback): HtmlParser; on(event: 'encoding', callback: EncodingCallback): HtmlParser; on(event: 'end-tag', callback: EndTagCallback): HtmlParser; on(event: 'error', callback: ErrorCallback): HtmlParser; on(event: 'request-data', callback: () => void): HtmlParser; on(event: 'start-tag-end', callback: StartTagEndCallback): HtmlParser; on(event: 'text', callback: TextCallback): HtmlParser; off(event: EventType): HtmlParser; private callback; stop(): void; reset(): void; private startParsing; parse(source: string): ParseResults; parseAsync(source?: string, yieldTime?: number): Promise<ParseResults>; private checkEncoding; private parseLoop; private parseLoopWrapUp; private handleText; private handleMarkupStart; private handleFullTag; private handleStartTagStart; private handleEndTag; private handleAttributeStart; private handleAttributeAssignment; private handleAttributeValueStepOne; private handleAttributeValueStepTwo; private handleDeclarationStartStepOne; private handleDeclarationStartStepTwo; private handleProcessingStart; private handleCommentStart; private handleTextBlockElements; private pop; private reportError; private doEndTagCallback; private doAttributeCallback; private atEOF; private getChar; private putBack; private gatherWhitespace; private gatherText; private gatherTagName; private gatherInvalidEndTagEnding; private gatherAttributeName; private gatherAttributeValue; private gatherComment; private gatherDeclarationOrProcessing; private gatherUntilEndTag; private adjustOptions; } export {}; //# sourceMappingURL=html-parser.d.ts.map