// Type definitions for parse5 2.1.5 // Project: https://github.com/inikulin/parse5 // Definitions by: Nico Jansen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// declare module 'parse5' { import * as stream from "stream"; import * as events from "events"; /** * Parses an HTML string. * @function * @param {string} html - Input HTML string. * @param {ParserOptions} html - Parsing options. * * @example * var parse5 = require('parse5'); * var document = parse5.parse('Hi there!'); */ export function parse(html: string, options?: ParserOptions): ASTNode; /** * Parses an HTML fragment. * * @param {string} html - Input html fragment * @param {ParserOptions} - Parsign options * @example * var parse5 = require('parse5'); * var documentFragment = parse5.parseFragment('
'); * // Parses the html fragment in the context of the parsed element. * var trFragment = parser.parseFragment(documentFragment.childNodes[0], ''); */ export function parseFragment(html: string, options?: ParserOptions): ASTNode; export function parseFragment(fragmentContext: any, html: string, options?: ParserOptions): ASTNode; /** * Serializes an AST node to an HTML string. * @param node Node to serialize. * @param options Serialization options */ export function serialize(node: ASTNode, options?: SerializerOptions): string; export interface ASTAttribute { name: string; value: string; } export interface Attribute { key: string; value: string; } export interface ASTNode { attrs: ASTAttribute[]; childNodes?: ASTNode[]; namespaceURI?: string; parentNode?: ASTNode; nodeName: string; quirksMode?: boolean; value?: string; __location: LocationInfo | ElementLocationInfo; } export interface LocationInfo { /** * One-based line index */ line: number; /** * Zero-based first character index */ col: number; /** * Zero-based first character index */ startOffset: number; /** * Zero-based last character index */ endOffset: number; } /** * Streaming AST node to an HTML serializer. A readable stream. */ export class SerializerStream extends stream.Readable { /** * Streaming AST node to an HTML serializer. A readable stream. * * @param Node to serialize. * @param options Serialization options. */ constructor(node: ASTNode, options: SerializerOptions); } /** * Streaming HTML parser with scripting support. A writable stream. */ export class ParserStream extends stream.Writable { /** * @param options Parsing options. */ constructor(options?: ParserOptions); /** * The resulting document node. */ document: ASTNode; on(event: string, listener: Function): this; /** * Raised then parser encounters a
Shake it, baby