summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_html.py8
-rw-r--r--tests/test_texi.py6
-rw-r--r--tests/test_text.py8
-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
4import unittest 4import unittest
5from WikiTrans.wiki2html import HtmlWiktionaryMarkup 5from wikitrans.wiki2html import HtmlWikiMarkup
6from WikiTest import populateMethods 6from wikitest import populate_methods
7 7
8class TestWiktionaryMarkup (unittest.TestCase): 8class TestWikiMarkup (unittest.TestCase):
9 pass 9 pass
10 10
11populateMethods(TestWiktionaryMarkup, HtmlWiktionaryMarkup, '.html') 11populate_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
4import unittest 4import unittest
5from WikiTrans.wiki2texi import TexiWikiMarkup 5from wikitrans.wiki2texi import TexiWikiMarkup
6from WikiTest import populateMethods 6from wikitest import populate_methods
7 7
@@ -10,3 +10,3 @@ class TestTexiWikiMarkup (unittest.TestCase):
10 10
11populateMethods(TestTexiWikiMarkup, TexiWikiMarkup, '.texi') 11populate_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
4import unittest 4import unittest
5from WikiTrans.wiki2text import TextWiktionaryMarkup 5from wikitrans.wiki2text import TextWikiMarkup
6from WikiTest import populateMethods 6from wikitest import populate_methods
7 7
8class TestTextWiktionaryMarkup (unittest.TestCase): 8class TestTextWikiMarkup (unittest.TestCase):
9 pass 9 pass
10 10
11populateMethods(TestTextWiktionaryMarkup, TextWiktionaryMarkup, '.text') 11populate_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
7def MarkupTest(classname, name_in, name_out): 7def 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
22def populateMethods(cls, wcls, suffix): 22def 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"""
19Wiki markup to HTML translator.
20
21Classes:
22
23HtmlWikiMarkup -- Converts Wiki material to HTML.
24HtmlWiktionaryMarkup -- Reserved for future use. Currently does the same as
25 HtmlWikiMarkup.
26
27"""
28
18from __future__ import print_function 29from __future__ import print_function
19from WikiTrans.wikimarkup import * 30from wikitrans.wikimarkup import *
20from WikiTrans.wikitoken import * 31from wikitrans.wikitoken import *
21from WikiTrans.wikins import wiki_ns_re, wiki_ns 32from wikitrans.wikins import wiki_ns_re, wiki_ns
22import re 33import 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
190class HtmlWikiMarkup (WikiMarkup): 201class 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
273class HtmlWiktionaryMarkup (HtmlWikiMarkup): 316class 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
18from WikiTrans.wikimarkup import * 18"""
19from WikiTrans.wikitoken import * 19Wiki markup to Texinfo translator.
20from WikiTrans.wikins import wiki_ns_re, wiki_ns 20
21Classes: