Skip to content

Allow passing available tags and namespace names to parser #305

@NguoiDungKhongDinhDanh

Description

@NguoiDungKhongDinhDanh

Currently I don't see an option for this.

By default, mwparserfromhell treats everything that looks like a XML tag as one, regardless of whether MediaWiki recognizes it or not. The same applies to wikilinks and file links. That makes sense since mph has no way to know what MW would do, but what if we provide necessary information as arguments to the Parser constructor?

For example:

# Namespaces taken from ptwiki, a wiki whose language has grammatical gender.
parser = Parser(
  recognized_tags = ['categorytree', 'charinsert', ...]  # Or any kind of Iterable[str],
  namespaces = {  # Or any kind of Mapping[int, str | Iterable[str]]
    0: '',
    1: 'Discussão',
    2: ['Usuário', 'Usuária', 'Usuário(a)'],
    ...: ...
  }
)

Namespace 0 would have a default value of '' (I'm not sure if MediaWiki allows configuring namespace prefix for this one or not). A non-recognized namespace would be considered to be a page in namespace 0 if that has no prefix, or cause an exception otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions