diff options
-rw-r--r-- | tests/test_html.py | 8 | ||||
-rw-r--r-- | tests/test_texi.py | 6 | ||||
-rw-r--r-- | tests/test_text.py | 8 | ||||
-rw-r--r-- | tests/wikitest.py (renamed from tests/WikiTest.py) | 6 | ||||
-rw-r--r-- | wikitrans/__init__.py (renamed from WikiTrans/__init__.py) | 0 | ||||
-rw-r--r-- | wikitrans/wiki2html.py (renamed from WikiTrans/wiki2html.py) | 115 | ||||
-rw-r--r-- | wikitrans/wiki2texi.py (renamed from WikiTrans/wiki2texi.py) | 63 | ||||
-rw-r--r-- | wikitrans/wiki2text.py (renamed from WikiTrans/wiki2text.py) | 74 | ||||
-rw-r--r-- | wikitrans/wikidump.py (renamed from WikiTrans/wikidump.py) | 41 | ||||
-rw-r--r-- | wikitrans/wikimarkup.py (renamed from WikiTrans/wikimarkup.py) | 784 | ||||
-rw-r--r-- | wikitrans/wikins.py (renamed from WikiTrans/wikins.py) | 0 | ||||
-rw-r--r-- | wikitrans/wikitoken.py (renamed from WikiTrans/wikitoken.py) | 154 |
12 files changed, 802 insertions, 457 deletions
diff --git a/tests/test_html.py b/tests/test_html.py index 3da57f6..5a15cb8 100644 --- a/tests/test_html.py +++ b/tests/test_html.py | |||
@@ -4,9 +4,9 @@ from __future__ import print_function | |||
4 | import unittest | 4 | import unittest |
5 | from WikiTrans.wiki2html import HtmlWiktionaryMarkup | 5 | from wikitrans.wiki2html import HtmlWikiMarkup |
6 | from WikiTest import populateMethods | 6 | from wikitest import populate_methods |
7 | 7 | ||
8 | class TestWiktionaryMarkup (unittest.TestCase): | 8 | class TestWikiMarkup (unittest.TestCase): |
9 | pass | 9 | pass |
10 | 10 | ||
11 | populateMethods(TestWiktionaryMarkup, HtmlWiktionaryMarkup, '.html') | 11 | populate_methods(TestWikiMarkup, HtmlWikiMarkup, '.html') |
12 | 12 | ||
diff --git a/tests/test_texi.py b/tests/test_texi.py index 75314c9..ddd26c7 100644 --- a/tests/test_texi.py +++ b/tests/test_texi.py | |||
@@ -4,4 +4,4 @@ from __future__ import print_function | |||
4 | import unittest | 4 | import unittest |
5 | from WikiTrans.wiki2texi import TexiWikiMarkup | 5 | from wikitrans.wiki2texi import TexiWikiMarkup |
6 | from WikiTest import populateMethods | 6 | from wikitest import populate_methods |
7 | 7 | ||
@@ -10,3 +10,3 @@ class TestTexiWikiMarkup (unittest.TestCase): | |||
10 | 10 | ||
11 | populateMethods(TestTexiWikiMarkup, TexiWikiMarkup, '.texi') | 11 | populate_methods(TestTexiWikiMarkup, TexiWikiMarkup, '.texi') |
12 | 12 | ||
diff --git a/tests/test_text.py b/tests/test_text.py index a06f519..b3d0a12 100644 --- a/tests/test_text.py +++ b/tests/test_text.py | |||
@@ -4,9 +4,9 @@ from __future__ import print_function | |||
4 | import unittest | 4 | import unittest |
5 | from WikiTrans.wiki2text import TextWiktionaryMarkup | 5 | from wikitrans.wiki2text import TextWikiMarkup |
6 | from WikiTest import populateMethods | 6 | from wikitest import populate_methods |
7 | 7 | ||
8 | class TestTextWiktionaryMarkup (unittest.TestCase): | 8 | class TestTextWikiMarkup (unittest.TestCase): |
9 | pass | 9 | pass |
10 | 10 | ||
11 | populateMethods(TestTextWiktionaryMarkup, TextWiktionaryMarkup, '.text') | 11 | populate_methods(TestTextWikiMarkup, TextWikiMarkup, '.text') |
12 | 12 | ||
diff --git a/tests/WikiTest.py b/tests/wikitest.py index 1429f5e..ff26227 100644 --- a/tests/WikiTest.py +++ b/tests/wikitest.py | |||
@@ -6,3 +6,3 @@ import os.path | |||
6 | 6 | ||
7 | def MarkupTest(classname, name_in, name_out): | 7 | def wiki_markup_test(classname, name_in, name_out): |
8 | fh = open(name_out) | 8 | fh = open(name_out) |
@@ -21,6 +21,6 @@ def MarkupTest(classname, name_in, name_out): | |||
21 | 21 | ||
22 | def populateMethods(cls, wcls, suffix): | 22 | def populate_methods(cls, wcls, suffix): |
23 | def settest(self, base, wiki_name, pat_name): | 23 | def settest(self, base, wiki_name, pat_name): |
24 | def dyntest(self): | 24 | def dyntest(self): |
25 | self.assertTrue(MarkupTest(wcls, wiki_name, pat_name)) | 25 | self.assertTrue(wiki_markup_test(wcls, wiki_name, pat_name)) |
26 | meth = 'test_' + wcls.__name__ + '_' + base | 26 | meth = 'test_' + wcls.__name__ + '_' + base |
diff --git a/WikiTrans/__init__.py b/wikitrans/__init__.py index 5832e38..5832e38 100644 --- a/WikiTrans/__init__.py +++ b/wikitrans/__init__.py | |||
diff --git a/WikiTrans/wiki2html.py b/wikitrans/wiki2html.py index 6147642..ce65bae 100644 --- a/WikiTrans/wiki2html.py +++ b/wikitrans/wiki2html.py | |||
@@ -17,6 +17,17 @@ | |||
17 | 17 | ||
18 | """ | ||
19 | Wiki markup to HTML translator. | ||
20 | |||
21 | Classes: | ||
22 | |||
23 | HtmlWikiMarkup -- Converts Wiki material to HTML. | ||
24 | HtmlWiktionaryMarkup -- Reserved for future use. Currently does the same as | ||
25 | HtmlWikiMarkup. | ||
26 | |||
27 | """ | ||
28 | |||
18 | from __future__ import print_function | 29 | from __future__ import print_function |
19 | from WikiTrans.wikimarkup import * | 30 | from wikitrans.wikimarkup import * |
20 | from WikiTrans.wikitoken import * | 31 | from wikitrans.wikitoken import * |
21 | from WikiTrans.wikins import wiki_ns_re, wiki_ns | 32 | from wikitrans.wikins import wiki_ns_re, wiki_ns |
22 | import re | 33 | import re |
@@ -81,4 +92,3 @@ class HtmlLinkNode(HtmlSeqNode): | |||
81 | return "<a href=\"%s\">%s</a>" % (tgt, | 92 | return "<a href=\"%s\">%s</a>" % (tgt, |
82 | text if (text and text != '') \ | 93 | text if (text and text != '') else arg) |
83 | else arg) | ||
84 | 94 | ||
@@ -88,5 +98,6 @@ class HtmlRefNode(WikiRefNode): | |||
88 | text = self.content.format() | 98 | text = self.content.format() |
89 | return "<a href=\"%s\">%s</a>" % (target, | 99 | return "<a href=\"%s\">%s</a>" % ( |
90 | text if (text and text != '') \ | 100 | target, |
91 | else target) | 101 | text if (text and text != '') else target |
102 | ) | ||
92 | 103 | ||
@@ -154,10 +165,10 @@ class HtmlTagNode(WikiTagNode): | |||
154 | n += 1 | 165 | n += 1 |
155 | s += ('<li id="cite_note-%d">' + \ | 166 | s += ('<li id="cite_note-%d">' |
156 | '<span class="mw-cite-backlink">' + \ | 167 | + '<span class="mw-cite-backlink">' |
157 | '<b><a href="#cite_ref-%d">^</a></b>' + \ | 168 | + '<b><a href="#cite_ref-%d">^</a></b>' |
158 | '</span>' + \ | 169 | + '</span>' |
159 | '<span class="reference-text">' + \ | 170 | + '<span class="reference-text">' |
160 | ref.content.format() + \ | 171 | + ref.content.format() |
161 | '</span>' + \ | 172 | + '</span>' |
162 | '</li>\n') % (n,n) | 173 | + '</li>\n') % (n,n) |
163 | s += '</ol>\n</div>\n' | 174 | s += '</ol>\n</div>\n' |
@@ -189,8 +200,16 @@ class HtmlIndNode(WikiIndNode): | |||
189 | 200 | ||
190 | class HtmlWikiMarkup (WikiMarkup): | 201 | class HtmlWikiMarkup(WikiMarkup): |
191 | """ | 202 | """A Wiki markup to HTML translator class. |
192 | A (hopefully) general-purpose Wiki->HTML translator class. | 203 | |
193 | FIXME: 1. See WikiMarkup for a list | 204 | Usage: |
194 | 2. [[official position]]s : final 's' gets after closing </a> tag. | 205 | |
195 | Should be before. | 206 | x = HtmlWikiMarkup(file="input.wiki") |
207 | # Parse the input: | ||
208 | x.parse() | ||
209 | # Print it as HTML: | ||
210 | print(str(x)) | ||
211 | |||
212 | Known bugs: | ||
213 | * [[official position]]s | ||
214 | Final 's' gets after closing </a> tag. Should be before. | ||
196 | """ | 215 | """ |
@@ -200,2 +219,26 @@ class HtmlWikiMarkup (WikiMarkup): | |||
200 | def __init__(self, *args, **kwargs): | 219 | def __init__(self, *args, **kwargs): |
220 | """Create a HtmlWikiMarkup object. | ||
221 | |||
222 | Arguments: | ||
223 | |||
224 | filename=FILE | ||
225 | Read Wiki material from the file named FILE. | ||
226 | file=FD | ||
227 | Read Wiki material from file object FD. | ||
228 | text=STRING | ||
229 | Read Wiki material from STRING. | ||
230 | lang=CODE | ||
231 | Specifies source language. Default is 'en'. This variable can be | ||
232 | referred to as '%(lang)s' in the keyword arguments below. | ||
233 | html_base=URL | ||
234 | Base URL for cross-references. Default is | ||
235 | 'http://%(lang)s.wiktionary.org/wiki/' | ||
236 | image_base=URL | ||
237 | Base URL for images. Default is | ||
238 | 'http://upload.wikimedia.org/wikipedia/commons/thumb/a/bf' | ||
239 | media_base=URL | ||
240 | Base URL for media files. Default is | ||
241 | 'http://www.mediawiki.org/xml/export-0.3' | ||
242 | """ | ||
243 | |||
201 | super(HtmlWikiMarkup, self).__init__(*args, **kwargs) | 244 | super(HtmlWikiMarkup, self).__init__(*args, **kwargs) |
@@ -272,28 +315,6 @@ class HtmlWikiMarkup (WikiMarkup): | |||
272 | 315 | ||
273 | class HtmlWiktionaryMarkup (HtmlWikiMarkup): | 316 | class HtmlWiktionaryMarkup(HtmlWikiMarkup): |
274 | """ | 317 | """A class for translating Wiktionary articles into HTML. |
275 | A class for translating Wiktionary articles into HTML. | ||
276 | This version does not do much, except that it tries to correctly | ||
277 | format templates. But "tries" does not mean "does". The heuristics | ||
278 | used here is clearly not enough to cope with it. | ||
279 | |||
280 | 1. FIXME: | ||
281 | The right solution would be to have a database of templates with their | ||
282 | semantics and to decide on their rendering depending on that. E.g. | ||
283 | {{term}} in en.wiktionary means "replace this with the search term". | ||
284 | This, however, does not work in other wiktionaries. There are | ||
285 | also more complex templates, e.g.: {{t+|bg|врата|n|p|tr=vrata|sc=Cyrl}} | ||
286 | I don't know what it means. Couldn't find any documentation either. | ||
287 | Again, this template does not work in other dictionaries. | ||
288 | 318 | ||
289 | 2. Capitulation notice: | 319 | Reserved for future use. Currently does the same as HtmlWikiMarkup. |
290 | Given the: | ||
291 | 1. vast amount of wiktionaries available, | ||
292 | 2. abundance of various templates for each wictionary, | ||
293 | 3. apparent lack of documentation thereof, | ||
294 | 4. the lack of standardized language-independent templates, | ||
295 | I dont see any way to cope with the template-rendering task within a | ||
296 | reasonable amount of time. | ||
297 | |||
298 | Faeci quod potui, faciant meliora potentes. | ||
299 | """ | 320 | """ |
diff --git a/WikiTrans/wiki2texi.py b/wikitrans/wiki2texi.py index 7297195..d9e5f52 100644 --- a/WikiTrans/wiki2texi.py +++ b/wikitrans/wiki2texi.py | |||
@@ -17,5 +17,14 @@ | |||
17 | 17 | ||
18 | from WikiTrans.wikimarkup import * | 18 | """ |
19 | from WikiTrans.wikitoken import * | 19 | Wiki markup to Texinfo translator. |
20 | from WikiTrans.wikins import wiki_ns_re, wiki_ns | 20 | |
21 | Classes: | ||