all2md.options.mediawiki

Configuration options for MediaWiki rendering.

This module defines options for rendering AST to MediaWiki format.

class all2md.options.mediawiki.MediaWikiOptions

Bases: BaseRendererOptions

Configuration options for MediaWiki rendering.

This dataclass contains settings for rendering AST documents as MediaWiki markup, suitable for Wikipedia and other MediaWiki-based wikis.

Parameters:
  • use_html_for_unsupported (bool, default True) – Whether to use HTML tags as fallback for unsupported elements. When True, unsupported formatting uses HTML tags (e.g., <u>underline</u>). When False, unsupported formatting is stripped.

  • image_thumb (bool, default True) – Whether to render images as thumbnails. When True, images use |thumb option in MediaWiki syntax. When False, images are rendered at full size.

  • image_caption_mode ({"auto", "alt_only", "caption_only"}, default "alt_only") – How to render image captions when image_thumb is True: - “auto”: Use alt_text as caption, with alt attribute when available - “alt_only”: Only render alt attribute, no caption text (default, backward compatible) - “caption_only”: Only render caption text, no alt attribute

  • html_passthrough_mode ({"pass-through", "escape", "drop", "sanitize"}, default "pass-through") – How to handle HTMLBlock and HTMLInline nodes: - “pass-through”: Pass through unchanged (use only with trusted content) - “escape”: HTML-escape the content - “drop”: Remove HTML content entirely - “sanitize”: Remove dangerous elements/attributes (requires bleach for best results)

  • comment_mode ({"html", "visible", "ignore"}, default "html") – How to render Comment and CommentInline AST nodes: - “html”: Use HTML comment syntax <!– –> (default) - “visible”: Render as visible text - “ignore”: Skip comments entirely

Examples

Basic MediaWiki rendering:
>>> from all2md.ast import Document, Heading, Text
>>> from all2md.renderers.mediawiki import MediaWikiRenderer
>>> from all2md.options.mediawiki import MediaWikiOptions
>>> doc = Document(children=[
...     Heading(level=1, content=[Text(content="Title")])
... ])
>>> options = MediaWikiOptions()
>>> renderer = MediaWikiRenderer(options)
>>> wiki_text = renderer.render_to_string(doc)
use_html_for_unsupported: bool = True
image_thumb: bool = True
image_caption_mode: Literal['auto', 'alt_only', 'caption_only'] = 'alt_only'
html_passthrough_mode: Literal['pass-through', 'escape', 'drop', 'sanitize'] = 'escape'
comment_mode: Literal['html', 'visible', 'ignore'] = 'html'
__init__(fail_on_resource_errors: bool = False, max_asset_size_bytes: int = 52428800, metadata_policy: MetadataRenderPolicy = <factory>, creator: str | None = 'all2md', use_html_for_unsupported: bool = True, image_thumb: bool = True, image_caption_mode: MediaWikiImageCaptionMode = 'alt_only', html_passthrough_mode: HtmlPassthroughMode = 'escape', comment_mode: MediaWikiCommentMode = 'html') None
class all2md.options.mediawiki.MediaWikiParserOptions

Bases: BaseParserOptions

Configuration options for MediaWiki-to-AST parsing.

This dataclass contains settings specific to parsing MediaWiki/WikiText documents into AST representation using mwparserfromhell.

Parameters:
  • parse_templates (bool, default False) – Whether to parse templates or strip them entirely. When True, templates are converted to HTMLInline nodes. When False, templates are completely removed from the output.

  • parse_tags (bool, default True) – Whether to parse parser tags (e.g., <ref>, <nowiki>). When True, tags are processed and included in the AST. When False, tags are stripped from the output.

  • strip_comments (bool, default True) – Whether to strip HTML comments from the output. When True, comments are removed completely. When False, comments are preserved as HTMLInline nodes.

  • html_passthrough_mode ({"pass-through", "escape", "drop", "sanitize"}, default "escape") – How to handle inline HTML in WikiText: - “pass-through”: Preserve HTML unchanged (use only with trusted content) - “escape”: HTML-escape the content to display as text - “drop”: Remove HTML content entirely - “sanitize”: Remove dangerous elements/attributes

Examples

Basic usage:
>>> options = MediaWikiParserOptions()
>>> parser = MediaWikiParser(options)
Parse templates as HTML:
>>> options = MediaWikiParserOptions(parse_templates=True)
>>> parser = MediaWikiParser(options)
parse_templates: bool = False
parse_tags: bool = True
strip_comments: bool = True
html_passthrough_mode: Literal['pass-through', 'escape', 'drop', 'sanitize'] = 'escape'
__init__(extract_metadata: bool = False, parse_templates: bool = False, parse_tags: bool = True, strip_comments: bool = True, html_passthrough_mode: Literal['pass-through', 'escape', 'drop', 'sanitize'] = 'escape') None