UNPKG

wikiparser-node

Version:

A Node.js parser for MediaWiki markup with AST

141 lines (140 loc) 4.75 kB
import { Token } from './index'; import { AtomToken } from './atom'; import { AttributeToken } from './attribute'; import type { Config, LintError } from '../base'; import type { ExtToken, HtmlToken, SyntaxToken } from '../internal'; import type { AttributeTypes } from './attribute'; import type { TableTokens } from './table/index'; declare type AttributesTypes = `${AttributeTypes}s`; declare type Child = AtomToken | AttributeToken; /** * attributes of extension and HTML tags * * 扩展和HTML标签属性 * @classdesc `{childNodes: (AtomToken|AttributeToken)[]}` */ export declare abstract class AttributesToken extends Token { #private; readonly name: string; readonly childNodes: readonly Child[]; abstract get firstChild(): Child | undefined; abstract get lastChild(): Child | undefined; abstract get parentNode(): ExtToken | HtmlToken | TableTokens | undefined; abstract get previousSibling(): SyntaxToken | undefined; abstract get children(): Child[]; abstract get firstElementChild(): Child | undefined; abstract get lastElementChild(): Child | undefined; abstract get parentElement(): ExtToken | HtmlToken | TableTokens | undefined; abstract get previousElementSibling(): SyntaxToken | undefined; get type(): AttributesTypes; /** all attributes / 全部属性 */ get attributes(): Record<string, string | true>; set attributes(attrs: Record<string, string | true>); /** class attribute in string / 以字符串表示的class属性 */ get className(): string; set className(className: string); /** class attribute in Set / 以Set表示的class属性 */ get classList(): Set<string>; /** id attribute / id属性 */ get id(): string; set id(id: string); /** whether to contain invalid attributes / 是否含有无效属性 */ get sanitized(): boolean; set sanitized(sanitized: boolean); /** * @param attr 标签属性 * @param type 标签类型 * @param name 标签名 */ constructor(attr: string | undefined, type: AttributesTypes, name: string, config: Config, accum?: Token[]); /** * Get all AttributeTokens with the specified attribute name * * 所有指定属性名的AttributeToken * @param key attribute name / 属性名 */ getAttrTokens(key?: string): AttributeToken[]; /** * Check if the token has a certain attribute * * 是否具有某属性 * @param key attribute name / 属性键 */ hasAttr(key: string): boolean; /** * Get the last AttributeToken with the specified attribute name * * 指定属性名的最后一个AttributeToken * @param key attribute name / 属性名 */ getAttrToken(key: string): AttributeToken | undefined; /** * Get the attribute * * 获取指定属性 * @param key attribute name / 属性键 */ getAttr(key: string): string | true | undefined; /** * Sanitize invalid attributes * * 清理无效属性 */ sanitize(): void; cloneNode(): this; /** * @override * @param token node to be inserted / 待插入的子节点 * @param i position to be inserted at / 插入位置 * @throws `RangeError` 标签不匹配 */ insertAt<T extends Child>(token: T, i?: number): T; /** * Set the attribute * * 设置指定属性 * @param key attribute name / 属性键 * @param value attribute value / 属性值 * @param prop attribute object / 属性对象 * @throws `RangeError` 扩展标签属性不能包含">" */ setAttr(key: string, value: string | boolean): void; setAttr(prop: Record<string, string | boolean>): void; /** * Get all attribute names * * 获取全部的属性名 */ getAttrNames(): Set<string>; /** * Get all attributes * * 获取全部属性 */ getAttrs(): Record<string, string | true>; /** * Remove an attribute * * 移除指定属性 * @param key attribute name / 属性键 */ removeAttr(key: string): void; /** * Toggle the specified attribute * * 开关指定属性 * @param key attribute name / 属性键 * @param force whether to force enabling or disabling / 强制开启或关闭 * @throws `RangeError` 不为Boolean类型的属性值 */ toggleAttr(key: string, force?: boolean): void; /** * Get the value of a style property * * 获取某一样式属性的值 * @param key style property / 样式属性 * @param value style property value / 样式属性值 */ css(key: string, value?: string): string | undefined; } export {};