Package: wikitrans
MediaWiki Markup TranslatorThis package provides Python framework for translating WikiMedia
articles to various formats. The present version supports
conversions to plain text, HTML, and Texinfo formats.A command line converter utility is included.ClassesclassWikiMarkupA base class for all translator classes. Unless you plan extending
wikitrans, you will never have to create objects of this
class. Instead, you will be using one of its derived classes.Constructor arguments common for all derived classes:filename =nameThe filenameis opened and used for input.file =fdAn already opened filefdis used for input.text =stringInput is taken fromstring, line by line.lang =codeSpecifies language version. Default isen. This variable can be
referred to as%(lang)sin the keyword arguments below.html_base =urlBase URL for cross-references. Default ishttp://%(lang)s.wikipedia.org/wiki/.image_base =urlBase URL for images. Default ishttp://upload.wikimedia.org/wikipedia/commons/thumb/a/bfmedia_base =urlBase URL for media files. Default ishttp://www.mediawiki.org/xml/export-0.3debug_level =intDebug verbosity level (0 - no debug info, 100 - excessively
copious debug messages). Default is 0.strict =boolStrict parsing mode. Throw exceptions on syntax errors. Default is False.classTextWikiMarkupTranslates material in Wiki markup language to plain text. Usage:from WikiTrans.wiki2text import TextWikiMarkup

markup = TextWikiMarkup(filename='input.txt')
markup.parse()
print(str(markup))Specific constructor arguments:width =NLimit output width toNcolumns. Default is 78.show_urls =boolWhether or not to show the URLs links refer to. IfboolisTrue(the default), a URL will be displayed in parentheses next
to the link text. IfFalse, only the link text will be displayed.classTextWiktionaryMarkupTranslate material from wiktionary to plain text form. This is
supposed to provide a wiktionary-specific form ofTextWikiMarkup. Currently, this class differs fromTextWikiMarkuponly in that the default value forhtml_baseishttp://%(lang)s.wikipedia.org/wiki/.classTexiWikiMarkupTranslate Wiki markup to Texinfo source. Usage:from WikiTrans.wiki2texi import TexiWikiMarkup

markup = TexiWikiMarkup(filename='input.txt')
markup.parse()
print(str(markup))Two markup-specific keywords control the sectioning model used.sectioning_model =modelSelects the Texinfo sectioning model for the output
document. Possible values are:numberedTop of document is marked with@top. Headings (=,==,===, etc) produce@chapter,@section,@subsection, etc.unnumberedUnnumbered sectioning:@top,@unnumbered,@unnumberedsec,@unnumberedsubsec.appendixSectioning suitable for appendix entries:@top,@appendix,@appendixsec,@appendixsubsec, etc.headingUse heading directives to reflect sectioning:@majorheading,@chapheading,@heading,@subheading, etc.sectioning_start =nShift resulting heading level bynpositions. For example, supposingsectioning_model=numbered,== A ==will produce@section Aon output. Ifsectioning_start=1is also given, this
directive will produce@subsection Ainstead.classHtmlWikiMarkupTranslates Wiki markup to HTML. Usage:from WikiTrans.wiki2html import HtmlWikiMarkup

markup = HtmlWikiMarkup(filename='input.txt')
markup.parse()
print(str(markup))Supported keywords are same as forWikiMarkupclass.classHtmlWiktionaryMarkupTranslate material from wiktionary to HTML form. This is
supposed to provide a wiktionary-specific form ofHtmlWikiMarkup. Currently both classes are equivalent, except that
the default value forhtml_baseinHtmlWiktionaryMarkupishttp://%(lang)s.wikipedia.org/wiki/.ThewikitransutilityThis command line utility converts the supplied text to selected
output format. The usage syntax is:wikitrans [OPTIONS] ARGIf ARG looks like a URL, the wiki text to be converted will be
downloaded from that URL.Otherwise, if the--base-url=URLoption is given, ARG is treated as
the name of the page to get from the WikiMedia istallation atURL.Otherwise, ARG is treated as the name of the file to read wiki
material from.Examples:wikitrans text.wiki

wikitrans --base-url http://en.wiktionary.org door

wikitrans https://en.wiktionary.org/wiki/Special:Export/doorOptions are:--versionShow program’s version number and exit.-h,--helpShow a short usage summary and exit.-v,--verboseVerbose operation.-IITYPE,--input-type=ITYPESet input document type.ITYPEis one of:defaultorwiktionary.-tOTYPE,--to=OTYPE,--type=OTYPESet output document type (html(the default),texi,text, ordump).-lLANG,--lang=LANGSet input document language.-oKW=VAL,--option=KW=VALPass the keyword argumentKW=VALto the parser class constructor.-dDEBUG,--debug=DEBUGSet debug level (0..100).-D,--dumpDump parse tree and exit; same as--type=dump.-bURL,--base-url=URLSet base url.Note: when using--base-urlor passing URL as an argument (2nd and 3rd
use cases above), if the URL is in ‘wikipedia.org’ or ‘wiktionary.org’
domain, the options--input-type, and--langare set automatically.