rphtml
Version:
A html parser written in rust, use wasm-pack for Nodejs package.
193 lines (168 loc) • 3.25 kB
TypeScript
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} content
* @param {IJsParseOptions | undefined} options
* @returns {IJsNode}
*/
export function parse(content: string, options?: IJsParseOptions): IJsNode;
/**
* @param {string} content
* @param {number | undefined} entities
* @param {number | undefined} encode_type
* @returns {IString}
*/
export function encode(content: string, entities?: number, encode_type?: number): IString;
/**
* @param {string} content
* @returns {IString}
*/
export function decode(content: string): IString;
/**
* @param {number} entity_set
* @param {string} ch
* @returns {boolean}
*/
export function contains(entity_set: number, ch: string): boolean;
/**
*/
export enum NodeType {
AbstractRoot,
HTMLDOCTYPE,
Comment,
Text,
SpacesBetweenTag,
Tag,
TagEnd,
XMLCDATA,
}
/**
* The type of characters you need encoded, default: `SpecialCharsAndNoASCII`
*/
export enum EntitySet {
Empty,
/**
* encode all
*/
All,
/**
* encode character not ascii
*/
NoASCII,
/**
* encode '<','>','&', main for entity in text node when call element's `innerHtml()` method
*/
Html,
/**
* encode '<','>','&', '\'', '"'
*/
SpecialChars,
/**
* this is default
*/
SpecialCharsAndNoASCII,
}
/**
* EncodeType: the output format type, default: `NamedOrDecimal`
*/
export enum EncodeType {
Ignore,
Named,
Hex,
Decimal,
NamedOrHex,
NamedOrDecimal,
}
export interface IJsParseOptions {
auto_fix_endtag?: boolean;
auto_remove_nostart_endtag?: boolean;
allow_self_closing?: boolean;
case_sensitive_tagname?: boolean;
}
export interface IJsRenderOptions {
always_close_void?: boolean;
lowercase_tagname?: boolean;
minify_spaces?: boolean;
remove_attr_quote?: boolean;
remove_comment?: boolean;
remove_endtag_space?: boolean;
inner_html?: boolean;
decode_entity?: boolean;
encode_content?: boolean;
}
export type IJsString = string;
export type IJsNodeTree = {
uuid?: string;
depth: number;
node_type: number;
begin_at: CodePosAt;
end_at: CodePosAt;
content?: Array<string>;
end_tag?: IJsNodeTree;
meta?: IJsNodeTagMeta;
childs?: Array<IJsNodeTree>;
};
export type IJsNodeAttrData = {
content: string;
begin_at: CodePosAt;
end_at: CodePosAt;
};
export type IJsNodeAttr = {
key?: IJsNodeAttrData;
value?: IJsNodeAttrData;
quote: string;
need_quote: boolean;
};
export type IJsNodeTagMeta = {
self_closed: boolean;
auto_fix: boolean;
name: string;
attrs: Array<IJsNodeAttr>;
};
export type IString = string;
/**
*
* * the doc's position
*/
export class CodePosAt {
free(): void;
/**
* @returns {number}
*/
col_no: number;
/**
* @returns {number}
*/
index: number;
/**
* @returns {number}
*/
line_no: number;
}
/**
*/
export class IJsNode {
free(): void;
/**
* @returns {IJsNodeTree}
*/
toJson(): IJsNodeTree;
/**
* @returns {IJsString}
*/
toString(): IJsString;
/**
* @param {IJsRenderOptions | undefined} options
* @returns {IJsString}
*/
render(options?: IJsRenderOptions): IJsString;
/**
* @param {string} uuid
* @returns {IJsNode | undefined}
*/
getTagByUuid(uuid: string): IJsNode | undefined;
/**
* @returns {boolean}
*/
isAloneTag(): boolean;
}