Skip to main content

A simple, purely python, WikiText parsing tool.

Project description

A simple, purely python, WikiText parsing tool.

The project is still in early development stages and I’m not sure if it will ever succeed. It sure can’t parse a page the same way the MediaWiki does (for example because it’s completely offline and can’t expand templates and also has not implemented many details of MediaWiki parser), but my guess is that for most usual uses it will be enough.

Installation

Use pip install wikitextparser

Usage

Here is a short demo of some of the functionalities:

>>> import wikitextparser as wtp
>>>
>>> wt = wtp.WikiText("""
== h2 ==
t2

=== h3 ===
t3

== h22 ==
t22

{{text|value1{{text|value2}}}}

[[A|B]]""")
>>>
>>> wt.templates
[Template("{{text|value2}}"), Template("{{text|value1{{text|value2}}}}")]
>>> _[1].arguments
[Argument("|value1{{text|value2}}")]
>>> _[0].value = 'value3'
>>> wt
WikiText("
== h2 ==
t2

=== h3 ===
t3

== h22 ==
t22

{{text|value3}}

[[A|B]]")
>>>
>>>
>>> wt.wikilinks
[WikiLink("[[A|B]]")]
>>> wt.wikilinks[0].target = 'Z'
>>> wt.wikilinks[0].text = 'X'
>>> wt
WikiText("
== h2 ==
t2

=== h3 ===
t3

== h22 ==
t22

{{text|value3}}

[[Z|X]]")
>>>
>>>
>>> wt.sections
[Argument(""), Argument("== h2 ==
t2

=== h3 ===
t3

"), Argument("=== h3 ===
t3

"), Argument("== h22 ==
t22

{{text|value3}}

[[Z|X]]")]
>>> wt.sections[1].title = 'newtitle'
>>> print(wt)
==newtitle==
t2

=== h3 ===
t3

== h22 ==
t22

{{text|value3}}

[[Z|X]]
>>>

See also:

Project details


Release history Release notifications | RSS feed

This version

0.4

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikitextparser-0.4.zip (15.6 kB view details)

Uploaded Source

File details

Details for the file wikitextparser-0.4.zip.

File metadata

  • Download URL: wikitextparser-0.4.zip
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wikitextparser-0.4.zip
Algorithm Hash digest
SHA256 bc82cb9d28973bba89b5a005bc4c2c23a2d84ea54a00bed08587d3374a2e5cb6
MD5 87e9e391c23351eb07cb17cbd9d5bba0
BLAKE2b-256 a19f2a9b563af5d2aadcabfc080a1b23f281bb3653e5737e9e93eae6ec984ca7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page