UNPKG

wikiparser-node

Version:

A Node.js parser for MediaWiki markup with AST

97 lines (96 loc) 3.64 kB
import { LintConfiguration } from './lib/lintConfig'; import type { Config, ConfigData, LintError, LintConfig, TokenTypes, Parser as ParserBase, Stage, AST } from './base'; import type { Title, TitleOptions } from './lib/title'; import type { LanguageService, QuickFixData } from './lib/lsp'; import type { Token, TranscludeToken, ExtToken } from './internal'; declare type FunctionHook = (token: TranscludeToken, context?: TranscludeToken) => string; declare type TagHook = (token: ExtToken) => string; declare interface Parser extends ParserBase { default: Parser; /** @since v1.5.1 */ readonly rules: readonly LintError.Rule[]; conversionTable: Map<string, string>; redirects: Map<string, string>; /** @since v1.10.0 */ templateDir?: string; /** @since v1.10.0 */ templates: Map<string, string>; warning: boolean; debugging: boolean; /** * Specify the current time of the parser * * 指定解析器的当前时间 * @since v1.21.2 */ now?: Date; configPaths: string[]; /** * Normalize page title * * 规范化页面标题 * @param title title (with or without the namespace prefix) / 标题(含或不含命名空间前缀) * @param defaultNs default namespace number / 命名空间 * @param include whether to be transcluded / 是否嵌入 */ normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config): Title; parse(wikitext: string, include?: boolean, maxStage?: number | Stage | Stage[], config?: Config): Token; /** * Create a language server * * 创建语言服务 * @param uri document URI / 文档标识 * @since v1.16.1 */ createLanguageService(uri?: object): LanguageService; /** * get the name of a WMF site from a URL * * 获取一个WMF网站的名称 * @param url script path * @since v1.22.0 */ getWMFSite(url: string): [string, string]; /** * Get the parser configuration for a MediaWiki project with Extension:CodeMirror installed * * 获取一个安装了CodeMirror扩展的MediaWiki项目的解析设置 * @param site site nickname / 网站别名 * @param url script path / 脚本路径 * @param user URI for wiki userpage or email address of the user / 维基用户页面地址或用户的电子邮件地址 * @since v1.18.4 */ fetchConfig(site: string, url: string, user?: string): Promise<Config>; /** * Define how to expand a parser function * * 定义如何展开一个解析器函数 * @param name parser function name / 解析器函数名 * @param hook handler function / 处理函数 * @since v1.22.0 */ setFunctionHook(name: string, hook: FunctionHook): void; /** * Define how to convert an extension tag to HTML * * 定义如何将一个扩展标签转换为HTML * @param name tag name / 标签名 * @param hook handler function / 处理函数 * @since v1.22.0 */ setHook(name: string, hook: TagHook): void; /** * Check if the title is an interwiki link * * 是否是跨维基链接 * @param title title / 链接标题 */ isInterwiki(title: string, config?: Config): RegExpExecArray | null; } declare const Parser: Parser; // @ts-expect-error mixed export styles export = Parser; export default Parser; export type { Config, ConfigData, LintConfig, LintError, TokenTypes, LanguageService, QuickFixData, AST, }; export type * from './internal'; declare global { type WikiParserAcceptable = Record<string, any>; }