Skip to main content

Crate wikioxide

Crate wikioxide 

Source
Expand description

§wikioxide

Parse MediaWiki wikitext into typed domain models — locally, deterministically and without HTML: template calls with full parameter maps, categories with sort keys, internal/external links, typed parser warnings and structural statistics, mirroring what the Action API’s action=parse reports for prop=templates|categories|links|externallinks|parsewarnings.

Configure a WikitextParser once per wiki (vendored presets for en/ru Wikipedia ship behind the default presets feature), then parse any number of pages:

use wikioxide::{DocumentView, NamespaceDef, PageContext, SiteConfig, WikitextParser};

let config = SiteConfig::builder("ru", "Вики")
    .namespace(NamespaceDef::main())
    .namespace(NamespaceDef::new(10, "Template", "Шаблон", ["Ш"], true))
    .link_trail("a-zа-яё")
    .build()?;
let parser = WikitextParser::builder().site_config(config).build()?;

let doc = parser.parse(
    "Стихи [[кота|котика]] в {{рамке|цвет=серый}}",
    &PageContext::default(),
);
assert_eq!(doc.links()[0].target().text(), "Кота");
assert_eq!(doc.links()[0].anchor_text(), Some("котика"));
assert_eq!(doc.templates()[0].title().text(), "Шаблон:Рамке");
assert_eq!(doc.templates()[0].param("цвет"), Some("серый"));

The parser is total over input: malformed wikitext yields a document plus typed Warnings, never an error. Template expansion (with a pluggable template source) arrives with the next milestone; today’s ParsedDocument is the faithful as-written view of a page.

Modules§

discussion
Discussion parsing: turns a talk page’s raw wikitext into signed comments with authors, timestamps and original-source spans.

Structs§

CategoryLink
A category membership (the API’s prop=categories item).
EmptyTemplateSource
A TemplateSource that knows nothing — every lookup is TemplateFetch::Unknown. The default source when a parser is built without one.
ExistenceMap
A batch of existence facts, keyed by title, applied to a parsed document via ExpandedDocument::apply_existence.
ExistenceRecord
A page-existence fact returned by an ExistenceProvider.
ExpandedDocument
The post-expansion view of a page: templates transcluded, {{{arguments}}} substituted and parser functions evaluated. Its links/categories/external_links are the API’s post-expansion sets, and transclusion_closure is the recursive template/module set (prop=templates). Produced by WikitextParser::expand.
ExternalLink
An external link (the API’s externallinks item).
FixedClock
A frozen clock for reproducible parses (tests, golden fixtures).
InMemoryTemplateStore
A thread-safe in-memory template cache. Share one via Arc between the parser and a prefetch task: expand, collect MissingTemplates, fill the store, expand again.
InterLanguageLink
An interlanguage (or interwiki) sidebar link, e.g. [[fr:Chat]].
InternalLink
An internal wikilink (the API’s prop=links item).
Limits
Expansion and parsing resource limits.
MagicLinks
Toggles for MediaWiki’s RFC/PMID/ISBN “magic links” (still enabled on Wikimedia wikis).
MagicWordDef
One magic word — a variable, parser function or behavior switch — with its aliases.
MissingTemplates
The template pages an expansion pass could not resolve under UnresolvedPolicy::Halt.
ModuleInvocation
One {{#invoke:Module|function|…}} call (Scribunto is not executed in v1).
MonthNames
Localized month names in the three forms MediaWiki date formatting uses. The genitive form is the one that appears in signature timestamps (Russian 8 мая 2026 uses the genitive мая); English uses the nominative for all three.
Namespace
A MediaWiki namespace number.
NamespaceDef
One namespace definition fed to SiteConfigBuilder::namespace.
PageContext
Per-page parse context: the page’s own title (drives {{PAGENAME}} and self-link detection once expansion lands) and an optional fixed “now” override.
ParsedDocument
The as-written view of one page: what is literally in the wikitext, templates unexpanded. Produced by WikitextParser::parse.
ProviderError
Opaque, caller-defined error from an ExistenceProvider lookup.
Redirect
A #REDIRECT [[Target#fragment]] declaration at the top of the page.
Section
A heading and the section it introduces, with byte spans into the original source (never the flattened text) so a consumer can slice or move the raw wikitext.
SiteConfig
Compiled per-wiki configuration. Cheap to share (Clone clones the compiled tables); build one per wiki and reuse it for every parse.
SiteConfigBuilder
Builder for SiteConfig — the JSON-free construction path.
Span
A byte range into the original input passed to the parser.
StructuralStats
Structural counts over the parsed document — the replacement for counting <table/<tr substrings in API HTML.
SystemClock
Wall-clock time (the default for interactive use).
TemplateCall
One template call, with its full parameter map — including calls nested inside other calls’ argument values.
Timestamp
A point in time: seconds since the Unix epoch, UTC.
Title
A normalized MediaWiki page title: a namespace plus a dbkey (underscored page name).
WikitextParser
A configured, reusable, thread-safe wikitext parser. Build one per wiki and share it — Clone is cheap (Arc inside).
WikitextParserBuilder
Builder for WikitextParser.

Enums§

BuildError
Errors from constructing a parser.
ConfigError
Errors from loading or building a SiteConfig.
ExpandOutcome
The outcome of WikitextParser::expand.
ExtTagContent
How an extension tag’s body is treated by the parser.
Origin
Where an extracted item came from.
TemplateFetch
The result of asking a TemplateSource for a page.
TitleError
Errors from Title::parse.
UnresolvedPolicy
What expansion does when a TemplateSource returns TemplateFetch::Unknown.
Warning
One parser warning: machine-readable data with a human-readable Display.

Traits§

Clock
Source of “now” for time-dependent magic words.
DocumentView
The read surface shared by every parse result — write one diff/analysis routine over &dyn DocumentView and it works for both the as-written and (later) the expanded view.
ExistenceProvider
A synchronous page-existence oracle consulted by {{#ifexist:}} during expansion. Optional: without one, {{#ifexist:}} records the query and takes the false branch.
TemplateSource
Where template and module wikitext comes from. Implementations must be pure and deterministic per call (the engine may ask for the same title more than once) and perform no blocking I/O on the calling thread — prefetch into a cache instead.