diff options
-rw-r--r-- | README.rst | 11 | ||||
-rwxr-xr-x | bin/wikitrans | 10 | ||||
-rw-r--r-- | testdata/headings.html | 2 | ||||
-rw-r--r-- | wikitrans/wiki2html.py | 25 | ||||
-rw-r--r-- | wikitrans/wiki2texi.py | 14 | ||||
-rw-r--r-- | wikitrans/wiki2text.py | 14 | ||||
-rw-r--r-- | wikitrans/wikimarkup.py | 25 |
7 files changed, 62 insertions, 39 deletions
@@ -29,7 +29,7 @@ lang = *code* referred to as ``%(lang)s`` in the keyword arguments below. html_base = *url* Base URL for cross-references. Default is - ``http://%(lang)s.wiktionary.org/wiki/``. + ``http://%(lang)s.wikipedia.org/wiki/``. image_base = *url* Base URL for images. Default is ``http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf`` @@ -61,7 +61,10 @@ class ``TextWiktionaryMarkup`` ------------------------------ Translate material from wiktionary to plain text form. This is supposed to provide a wiktionary-specific form of -``TextWikiMarkup``. Currently both classes are entirely equivalent. +``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`` ------------------------ @@ -115,7 +118,9 @@ 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. +``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 ========================= diff --git a/bin/wikitrans b/bin/wikitrans index adf779d..e9ab81f 100755 --- a/bin/wikitrans +++ b/bin/wikitrans @@ -141,7 +141,15 @@ Otherwise, ARG is name of the file to read wiki material from. (options, args) = parser.parse_args() if len(args) == 1: if options.base_url: - options.kwdict['text'] = getwiki(options.base_url + '/wiki/Special:Export/' + args[0]) + options.kwdict['text'] = getwiki(options.base_url + + '/wiki/Special:Export/' + args[0]) + m = re.match('(?:.+://)(.+?)\.(wik(?:ipedia|tionary))\.org', + options.base_url) + if m: + options.lang = m.group(1) + options.kwdict['html_base'] = options.base_url + '/wiki/' + if m.group(2) == 'wiktionary': + options.itype = 'wiktionary' elif args[0] == '-': options.kwdict['file'] = sys.stdin elif re.match('^(http|ftp)s?://',args[0]): diff --git a/testdata/headings.html b/testdata/headings.html index de9c9c3..bf02987 100644 --- a/testdata/headings.html +++ b/testdata/headings.html @@ -2,7 +2,7 @@ <p><i>Headings</i> organize your writing into sections. The Wiki software can automatically -generate a <a href="http://en.wiktionary.org/wiki/table%20of%20contents">table of contents</a> from them.</p> +generate a <a href="http://en.wikipedia.org/wiki/table%20of%20contents">table of contents</a> from them.</p> <h3>Subsection</h3> <p>Using more "equals" (=) signs creates a subsection.</p> diff --git a/wikitrans/wiki2html.py b/wikitrans/wiki2html.py index ce65bae..fc6b142 100644 --- a/wikitrans/wiki2html.py +++ b/wikitrans/wiki2html.py @@ -219,26 +219,11 @@ class HtmlWikiMarkup(WikiMarkup): def __init__(self, *args, **kwargs): """Create a HtmlWikiMarkup object. - Arguments: + HtmlWikiMarkup([filename=FILE],[file=FD],[text=STRING],[lang=CODE], + [html_base=URL],[image_base=URL],[media_base=URL]) - filename=FILE - Read Wiki material from the file named FILE. - file=FD - Read Wiki material from file object FD. - text=STRING - Read Wiki material from STRING. - lang=CODE - Specifies source language. 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.wiktionary.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' + The arguments have the same meaning as in the WikiMarkup constructor. + """ super(HtmlWikiMarkup, self).__init__(*args, **kwargs) @@ -318,3 +303,5 @@ class HtmlWiktionaryMarkup(HtmlWikiMarkup): Reserved for future use. Currently does the same as HtmlWikiMarkup. """ + + html_base='http://%(lang)s.wiktionary.org/wiki/' diff --git a/wikitrans/wiki2texi.py b/wikitrans/wiki2texi.py index d9e5f52..55dffe2 100644 --- a/wikitrans/wiki2texi.py +++ b/wikitrans/wiki2texi.py @@ -311,14 +311,14 @@ class TexiWikiMarkup(WikiMarkup): def __init__(self, *args, **keywords): """Create a TexiWikiMarkup object. - Arguments: + TexiWikiMarkup([filename=FILE],[file=FD],[text=STRING],[lang=CODE], + [html_base=URL],[image_base=URL],[media_base=URL], + [sectioning_model=MODEL],[sectioning_start=N]) - filename=FILE - Read Wiki material from the file named FILE. - file=FD - Read Wiki material from file object FD. - text=STRING - Read Wiki material from STRING. + For a discussion of generic arguments, see the constructor of + the WikiMarkup class. + + Additional arguments: sectioning_model=MODEL Select the Texinfo sectioning model for the output document. Possible diff --git a/wikitrans/wiki2text.py b/wikitrans/wiki2text.py index 1fbc61b..88e7610 100644 --- a/wikitrans/wiki2text.py +++ b/wikitrans/wiki2text.py @@ -247,14 +247,13 @@ class TextWikiMarkup(WikiMarkup): def __init__(self, *args, **keywords): """Create a TextWikiMarkup object. - Arguments: + TextWikiMarkup([filename=FILE],[file=FD],[text=STRING],[lang=CODE], + [html_base=URL],[image_base=URL],[media_base=URL], + [width=N],[show_urls=False]) - filename=FILE - Read Wiki material from the file named FILE. - file=FD - Read Wiki material from file object FD. - text=STRING - Read Wiki material from STRING. + Most arguments have the same meaning as in the WikiMarkup constructor. + + Class-specific arguments: width=N Limit output width to N columns. Default is 78. @@ -345,4 +344,5 @@ class TextWiktionaryMarkup(TextWikiMarkup): Reserved for future use. Currently does the same as TextWikiMarkup. """ + html_base='http://%(lang)s.wiktionary.org/wiki/' diff --git a/wikitrans/wikimarkup.py b/wikitrans/wikimarkup.py index 77c3b30..a3e17d5 100644 --- a/wikitrans/wikimarkup.py +++ b/wikitrans/wikimarkup.py @@ -952,11 +952,34 @@ class WikiMarkup(WikiMarkupParser): file = None text = None lang = 'en' - html_base = 'http://%(lang)s.wiktionary.org/wiki/' + html_base = 'http://%(lang)s.wikipedia.org/wiki/' image_base = 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf' media_base = 'http://www.mediawiki.org/xml/export-0.3' def __init__(self, *args, **keywords): + """Create a WikiMarkup object. + + Arguments: + + filename=FILE + Read Wiki material from the file named FILE. + file=FD + Read Wiki material from file object FD. + text=STRING + Read Wiki material from STRING. + lang=CODE + Specifies source language. 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' + """ for kw in keywords: if kw == 'file': self.file = keywords[kw] |