simple-html-tokenizer
Version:
Simple HTML Tokenizer is a lightweight JavaScript library that can be used to tokenize the kind of HTML normally found in templates.
82 lines (81 loc) • 2.29 kB
TypeScript
export interface NamedEntityMap {
[name: string]: string;
}
export interface EntityParser {
parse(entity: string): string | undefined;
}
export interface TokenizerOptions {
loc?: boolean;
mode?: 'precompile' | 'codemod';
}
export type Attribute = [string, string, boolean];
export interface Location {
start: {
line: number;
column: number;
};
end: {
line: number;
column: number;
};
}
export interface TokenBase<T extends TokenType> {
type: T;
syntaxError?: string;
loc?: Location;
}
export interface Doctype extends TokenBase<'Doctype'> {
name: string;
publicIdentifier?: string;
systemIdentifier?: string;
}
export interface StartTag extends TokenBase<'StartTag'> {
tagName: string;
attributes: Attribute[];
selfClosing: boolean;
}
export interface EndTag extends TokenBase<'EndTag'> {
tagName: string;
}
export interface Chars extends TokenBase<'Chars'> {
chars: string;
}
export interface Comment extends TokenBase<'Comment'> {
chars: string;
}
export type Token = StartTag | EndTag | Chars | Comment | Doctype;
export type TokenType = 'Doctype' | 'StartTag' | 'EndTag' | 'Chars' | 'Comment';
export interface TokenMap {
StartTag: StartTag;
EndTag: EndTag;
Chars: Chars;
Comment: Comment;
Doctype: Doctype;
}
export interface TokenizerDelegate {
reset(): void;
finishData(): void;
tagOpen(): void;
beginDoctype?(): void;
appendToDoctypeName?(char: string): void;
appendToDoctypePublicIdentifier?(char: string): void;
appendToDoctypeSystemIdentifier?(char: string): void;
endDoctype?(): void;
beginData(): void;
appendToData(char: string): void;
beginStartTag(): void;
appendToTagName(char: string): void;
beginAttribute(): void;
appendToAttributeName(char: string): void;
beginAttributeValue(quoted: boolean): void;
appendToAttributeValue(char: string): void;
finishAttributeValue(): void;
markTagAsSelfClosing(): void;
beginEndTag(): void;
finishTag(): void;
beginComment(): void;
appendToCommentData(char: string): void;
finishComment(): void;
reportSyntaxError(error: string): void;
}
export type { TokenizerState } from './generated/tokenizer-states.js';