wikitrans


Namewikitrans JSON
Version 1.4 PyPI version JSON
download
home_pagehttp://www.gnu.org.ua/projects/wikitrans
SummaryWiki markup translator.
upload_time2024-07-07 11:21:01
maintainerNone
docs_urlNone
authorSergey Poznyakoff
requires_python>=3.5
licenseGPL License
keywords mediawiki markup translation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            MediaWiki Markup Translator
===========================
This 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.

Classes
=======

class ``WikiMarkup``
--------------------
A 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 = *name*
  The file *name* is opened and used for input.
file = *fd*
  An already opened file *fd* is used for input.
text = *string*
  Input is taken from *string*, line by line.

lang = *code*
  Specifies language version. Default is ``en``. This variable can be
  referred to as ``%(lang)s`` in the keyword arguments below.
html_base = *url*
  Base URL for cross-references. Default is
  ``http://%(lang)s.wikipedia.org/wiki/``.
image_base = *url*
  Base URL for images. Default is
  ``http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf``
media_base = *url*
  Base URL for media files. Default is
  ``http://www.mediawiki.org/xml/export-0.3``

debug_level = *int*
  Debug verbosity level (0 - no debug info, 100 - excessively
  copious debug messages). Default is 0.

strict = *bool*
  Strict parsing mode. Throw exceptions on syntax errors. Default is False.

class ``TextWikiMarkup``
------------------------
Translates 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 = *N*
  Limit output width to *N* columns. Default is 78.  
show_urls = *bool*
  Whether or not to show the URLs links refer to. If *bool* is
  ``True`` (the default), a URL will be displayed in parentheses next
  to the link text. If ``False``, only the link text will be displayed. 

class ``TextWiktionaryMarkup``
------------------------------
Translate material from wiktionary to plain text form. This is
supposed to provide a wiktionary-specific form of
``TextWikiMarkup``. Currently, this class differs from
``TextWikiMarkup`` only in that the default value for ``html_base``
is ``http://%(lang)s.wikipedia.org/wiki/``.


class ``TexiWikiMarkup``
------------------------
Translate 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 = *model*
  Selects the Texinfo sectioning model for the output
  document. Possible values are:

  ``numbered``
     Top of document is marked with ``@top``. Headings (``=``, ``==``,
     ``===``, etc) produce ``@chapter``,
     ``@section``, ``@subsection``, etc.
  ``unnumbered``
     Unnumbered sectioning: ``@top``, ``@unnumbered``, ``@unnumberedsec``,
     ``@unnumberedsubsec``.
  ``appendix``
     Sectioning suitable for appendix entries: ``@top``, ``@appendix``,
     ``@appendixsec``, ``@appendixsubsec``, etc.
  ``heading``
     Use heading directives to reflect sectioning: ``@majorheading``,
     ``@chapheading``, ``@heading``, ``@subheading``, etc.

sectioning_start = *n*
  Shift resulting heading level by *n* positions. For example, supposing
  ``sectioning_model=numbered``, ``== A ==`` will produce ``@section
  A`` on output. If ``sectioning_start=1`` is also given, this
  directive will produce ``@subsection A`` instead.

class ``HtmlWikiMarkup``
------------------------
Translates 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 for ``WikiMarkup`` class.

class ``HtmlWiktionaryMarkup``
------------------------------
Translate material from wiktionary to HTML form. This is
supposed to provide a wiktionary-specific form of
``HtmlWikiMarkup``. Currently both classes are equivalent, except that
the default value for ``html_base`` in ``HtmlWiktionaryMarkup``
is ``http://%(lang)s.wikipedia.org/wiki/``.

The ``wikitrans`` utility
=========================
This command line utility converts the supplied text to selected
output format. The usage syntax is::

  wikitrans [OPTIONS] ARG

If ARG looks like a URL, the wiki text to be converted will be
downloaded from that URL.

Otherwise, if the ``--base-url=URL`` option is given, ARG is treated as
the name of the page to get from the WikiMedia istallation at ``URL``.

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/door

Options are:

``--version``
  Show program's version number and exit.
``-h``, ``--help``
  Show a short usage summary and exit.
``-v``, ``--verbose``
  Verbose operation.
``-I ITYPE``, ``--input-type=ITYPE``
  Set input document type. *ITYPE* is one of: ``default`` or ``wiktionary``.
``-t OTYPE``, ``--to=OTYPE``, ``--type=OTYPE``
  Set output document type (``html`` (the default), ``texi``,
  ``text``, or ``dump``).
``-l LANG``, ``--lang=LANG``
  Set input document language.
``-o KW=VAL``, ``--option=KW=VAL``
  Pass the keyword argument ``KW=VAL`` to the parser class constructor.
``-d DEBUG``, ``--debug=DEBUG``
  Set debug level (0..100).
``-D``, ``--dump``
  Dump parse tree and exit; same as ``--type=dump``.
``-b URL``, ``--base-url=URL``
  Set base url. 

Note: when using ``--base-url`` or 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 ``--lang`` are set automatically.
            

Raw data

            {
    "_id": null,
    "home_page": "http://www.gnu.org.ua/projects/wikitrans",
    "name": "wikitrans",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": null,
    "keywords": "mediawiki markup translation",
    "author": "Sergey Poznyakoff",
    "author_email": "gray@gnu.org",
    "download_url": "https://files.pythonhosted.org/packages/2a/ca/d8f3b475a4579f783d65efc36fd004133097731767b0e4c195e9c020275e/wikitrans-1.4.tar.gz",
    "platform": "any",
    "description": "MediaWiki Markup Translator\n===========================\nThis package provides Python framework for translating WikiMedia\narticles to various formats. The present version supports\nconversions to plain text, HTML, and Texinfo formats.\n\nA command line converter utility is included.\n\nClasses\n=======\n\nclass ``WikiMarkup``\n--------------------\nA base class for all translator classes. Unless you plan extending\nwikitrans, you will never have to create objects of this\nclass. Instead, you will be using one of its derived classes.\n\nConstructor arguments common for all derived classes:\n\nfilename = *name*\n  The file *name* is opened and used for input.\nfile = *fd*\n  An already opened file *fd* is used for input.\ntext = *string*\n  Input is taken from *string*, line by line.\n\nlang = *code*\n  Specifies language version. Default is ``en``. This variable can be\n  referred to as ``%(lang)s`` in the keyword arguments below.\nhtml_base = *url*\n  Base URL for cross-references. Default is\n  ``http://%(lang)s.wikipedia.org/wiki/``.\nimage_base = *url*\n  Base URL for images. Default is\n  ``http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf``\nmedia_base = *url*\n  Base URL for media files. Default is\n  ``http://www.mediawiki.org/xml/export-0.3``\n\ndebug_level = *int*\n  Debug verbosity level (0 - no debug info, 100 - excessively\n  copious debug messages). Default is 0.\n\nstrict = *bool*\n  Strict parsing mode. Throw exceptions on syntax errors. Default is False.\n\nclass ``TextWikiMarkup``\n------------------------\nTranslates material in Wiki markup language to plain text. Usage::\n\n   from WikiTrans.wiki2text import TextWikiMarkup\n\n   markup = TextWikiMarkup(filename='input.txt')\n   markup.parse()\n   print(str(markup))\n\nSpecific constructor arguments:\n\nwidth = *N*\n  Limit output width to *N* columns. Default is 78.  \nshow_urls = *bool*\n  Whether or not to show the URLs links refer to. If *bool* is\n  ``True`` (the default), a URL will be displayed in parentheses next\n  to the link text. If ``False``, only the link text will be displayed. \n\nclass ``TextWiktionaryMarkup``\n------------------------------\nTranslate material from wiktionary to plain text form. This is\nsupposed to provide a wiktionary-specific form of\n``TextWikiMarkup``. Currently, this class differs from\n``TextWikiMarkup`` only in that the default value for ``html_base``\nis ``http://%(lang)s.wikipedia.org/wiki/``.\n\n\nclass ``TexiWikiMarkup``\n------------------------\nTranslate Wiki markup to Texinfo source. Usage::\n\n   from WikiTrans.wiki2texi import TexiWikiMarkup\n\n   markup = TexiWikiMarkup(filename='input.txt')\n   markup.parse()\n   print(str(markup))\n\nTwo markup-specific keywords control the sectioning model used.\n\nsectioning_model = *model*\n  Selects the Texinfo sectioning model for the output\n  document. Possible values are:\n\n  ``numbered``\n     Top of document is marked with ``@top``. Headings (``=``, ``==``,\n     ``===``, etc) produce ``@chapter``,\n     ``@section``, ``@subsection``, etc.\n  ``unnumbered``\n     Unnumbered sectioning: ``@top``, ``@unnumbered``, ``@unnumberedsec``,\n     ``@unnumberedsubsec``.\n  ``appendix``\n     Sectioning suitable for appendix entries: ``@top``, ``@appendix``,\n     ``@appendixsec``, ``@appendixsubsec``, etc.\n  ``heading``\n     Use heading directives to reflect sectioning: ``@majorheading``,\n     ``@chapheading``, ``@heading``, ``@subheading``, etc.\n\nsectioning_start = *n*\n  Shift resulting heading level by *n* positions. For example, supposing\n  ``sectioning_model=numbered``, ``== A ==`` will produce ``@section\n  A`` on output. If ``sectioning_start=1`` is also given, this\n  directive will produce ``@subsection A`` instead.\n\nclass ``HtmlWikiMarkup``\n------------------------\nTranslates Wiki markup to HTML. Usage::\n\n   from WikiTrans.wiki2html import HtmlWikiMarkup\n\n   markup = HtmlWikiMarkup(filename='input.txt')\n   markup.parse()\n   print(str(markup))\n\nSupported keywords are same as for ``WikiMarkup`` class.\n\nclass ``HtmlWiktionaryMarkup``\n------------------------------\nTranslate material from wiktionary to HTML form. This is\nsupposed to provide a wiktionary-specific form of\n``HtmlWikiMarkup``. Currently both classes are equivalent, except that\nthe default value for ``html_base`` in ``HtmlWiktionaryMarkup``\nis ``http://%(lang)s.wikipedia.org/wiki/``.\n\nThe ``wikitrans`` utility\n=========================\nThis command line utility converts the supplied text to selected\noutput format. The usage syntax is::\n\n  wikitrans [OPTIONS] ARG\n\nIf ARG looks like a URL, the wiki text to be converted will be\ndownloaded from that URL.\n\nOtherwise, if the ``--base-url=URL`` option is given, ARG is treated as\nthe name of the page to get from the WikiMedia istallation at ``URL``.\n\nOtherwise, ARG is treated as the name of the file to read wiki\nmaterial from.\n\nExamples::\n\n  wikitrans text.wiki\n\n  wikitrans --base-url http://en.wiktionary.org door\n\n  wikitrans https://en.wiktionary.org/wiki/Special:Export/door\n\nOptions are:\n\n``--version``\n  Show program's version number and exit.\n``-h``, ``--help``\n  Show a short usage summary and exit.\n``-v``, ``--verbose``\n  Verbose operation.\n``-I ITYPE``, ``--input-type=ITYPE``\n  Set input document type. *ITYPE* is one of: ``default`` or ``wiktionary``.\n``-t OTYPE``, ``--to=OTYPE``, ``--type=OTYPE``\n  Set output document type (``html`` (the default), ``texi``,\n  ``text``, or ``dump``).\n``-l LANG``, ``--lang=LANG``\n  Set input document language.\n``-o KW=VAL``, ``--option=KW=VAL``\n  Pass the keyword argument ``KW=VAL`` to the parser class constructor.\n``-d DEBUG``, ``--debug=DEBUG``\n  Set debug level (0..100).\n``-D``, ``--dump``\n  Dump parse tree and exit; same as ``--type=dump``.\n``-b URL``, ``--base-url=URL``\n  Set base url. \n\nNote: when using ``--base-url`` or passing URL as an argument (2nd and 3rd\nuse cases above), if the URL is in 'wikipedia.org' or 'wiktionary.org'\ndomain, the options ``--input-type``, and ``--lang`` are set automatically.",
    "bugtrack_url": null,
    "license": "GPL License",
    "summary": "Wiki markup translator.",
    "version": "1.4",
    "project_urls": {
        "Homepage": "http://www.gnu.org.ua/projects/wikitrans"
    },
    "split_keywords": [
        "mediawiki",
        "markup",
        "translation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2acad8f3b475a4579f783d65efc36fd004133097731767b0e4c195e9c020275e",
                "md5": "69fe164c60637fbf77344df122261cae",
                "sha256": "99579ef820f476c287fc4fa27917560eef32dfb565ab9cc779c76ade71f8123f"
            },
            "downloads": -1,
            "filename": "wikitrans-1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "69fe164c60637fbf77344df122261cae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 67678,
            "upload_time": "2024-07-07T11:21:01",
            "upload_time_iso_8601": "2024-07-07T11:21:01.204795Z",
            "url": "https://files.pythonhosted.org/packages/2a/ca/d8f3b475a4579f783d65efc36fd004133097731767b0e4c195e9c020275e/wikitrans-1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-07 11:21:01",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "wikitrans"
}
        
Elapsed time: 0.36138s