Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing available tags and namespace names to parser #305

Open
NguoiDungKhongDinhDanh opened this issue May 18, 2023 · 0 comments
Open

Comments

@NguoiDungKhongDinhDanh
Copy link

NguoiDungKhongDinhDanh commented May 18, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant