aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wiki2html.py10
-rw-r--r--wiki2texi.py9
-rw-r--r--wiki2text.py3
-rwxr-xr-xwikicvt.py22
-rw-r--r--wikimarkup.py5
5 files changed, 27 insertions, 22 deletions
diff --git a/wiki2html.py b/wiki2html.py
index 0330b92..05d4642 100644
--- a/wiki2html.py
+++ b/wiki2html.py
@@ -13,16 +13,18 @@
13# GNU General Public License for more details. 13# GNU General Public License for more details.
14# 14#
15# You should have received a copy of the GNU General Public License 15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18from wikimarkup import * 18from wikimarkup import *
19from types import TupleType
20from wikins import wiki_ns_re, wiki_ns 19from wikins import wiki_ns_re, wiki_ns
21import re 20import re
22import urllib 21try:
22 from urllib import quote as url_quote
23except ImportError:
24 from urllib.parse import quote as url_quote
23 25
24class HtmlWikiMarkup (WikiMarkup): 26class HtmlWikiMarkup (WikiMarkup):
25 """ 27 """
26 A (hopefully) general-purpose Wiki->HTML translator class. 28 A (hopefully) general-purpose Wiki->HTML translator class.
27 FIXME: 1. See WikiMarkup for a list 29 FIXME: 1. See WikiMarkup for a list
28 2. [[official position]]s : final 's' gets after closing </a> tag. 30 2. [[official position]]s : final 's' gets after closing </a> tag.
@@ -45,13 +47,13 @@ class HtmlWikiMarkup (WikiMarkup):
45 "defn": { "hdr": "dl", 47 "defn": { "hdr": "dl",
46 "elt": ["dt","dd"] } } 48 "elt": ["dt","dd"] } }
47 49
48 def mktgt(self, tgt, lang = None): 50 def mktgt(self, tgt, lang = None):
49 if not lang: 51 if not lang:
50 lang = self.lang 52 lang = self.lang
51 return self.html_base % { 'lang' : lang } + urllib.quote(tgt) 53 return self.html_base % { 'lang' : lang } + url_quote(tgt)
52 54
53 def tmpl_term(self, s): 55 def tmpl_term(self, s):
54 if len(s) == 2: 56 if len(s) == 2:
55 return s[1] 57 return s[1]
56 text = None 58 text = None
57 trans = None 59 trans = None
@@ -81,13 +83,13 @@ class HtmlWikiMarkup (WikiMarkup):
81 83
82 84
83 def fmtlink(self, elt, istmpl): 85 def fmtlink(self, elt, istmpl):
84 arg = self.format(elt['content'][0]) 86 arg = self.format(elt['content'][0])
85 text = None 87 text = None
86 if len(elt['content']) > 1: 88 if len(elt['content']) > 1:
87 s = map(self.format, elt['content']) 89 s = [x for x in map(self.format, elt['content'])]
88 if s[0] == 'disambigR' or s[0] == 'wikiquote': 90 if s[0] == 'disambigR' or s[0] == 'wikiquote':
89 return "" 91 return ""
90 elif len(s) > 1 and s[1] == 'thumb': 92 elif len(s) > 1 and s[1] == 'thumb':
91 return "" 93 return ""
92 text = '<span class="template">' + s[1] + '</span>' 94 text = '<span class="template">' + s[1] + '</span>'
93 if istmpl: 95 if istmpl:
diff --git a/wiki2texi.py b/wiki2texi.py
index a7b5e92..6e32c56 100644
--- a/wiki2texi.py
+++ b/wiki2texi.py
@@ -13,13 +13,12 @@
13# GNU General Public License for more details. 13# GNU General Public License for more details.
14# 14#
15# You should have received a copy of the GNU General Public License 15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18from wikimarkup import * 18from wikimarkup import *
19from types import TupleType
20from wikins import wiki_ns_re, wiki_ns 19from wikins import wiki_ns_re, wiki_ns
21import re 20import re
22import urllib 21import urllib
23 22
24class TexiWikiMarkup (WikiMarkup): 23class TexiWikiMarkup (WikiMarkup):
25 sectcomm = { 24 sectcomm = {
@@ -55,19 +54,19 @@ class TexiWikiMarkup (WikiMarkup):
55 54
56 sectioning_model = 'numbered' 55 sectioning_model = 'numbered'
57 sectioning_start = 0 56 sectioning_start = 0
58 57
59 def __init__(self, *args, **keywords): 58 def __init__(self, *args, **keywords):
60 super(TexiWikiMarkup, self).__init__(*args, **keywords) 59 super(TexiWikiMarkup, self).__init__(*args, **keywords)
61 if keywords.has_key("sectioning-model"): 60 if "sectioning-model" in keywords:
62 val = keywords["sectioning-model"] 61 val = keywords["sectioning-model"]
63 if self.sectcomm.has_key(val): 62 if val in self.sectcomm:
64 self.sectioning_model = val 63 self.sectioning_model = val
65 else: 64 else:
66 raise ValueError("Invalid value for sectioning model: %s" % val) 65 raise ValueError("Invalid value for sectioning model: %s" % val)
67 if keywords.has_key("sectioning-start"): 66 if "sectioning-start" in keywords:
68 val = keywords["sectioning-start"] 67 val = keywords["sectioning-start"]
69 if val < 0 or val > 4: 68 if val < 0 or val > 4:
70 raise ValueError("Invalid value for sectioning start: %s" % val) 69 raise ValueError("Invalid value for sectioning start: %s" % val)
71 else: 70 else:
72 self.sectioning_start = val 71 self.sectioning_start = val
73 72
@@ -214,13 +213,13 @@ class TexiWikiMarkup (WikiMarkup):
214 return string 213 return string
215 214
216 def str_link(self, elt): 215 def str_link(self, elt):
217 # FIXME: A very crude version 216 # FIXME: A very crude version
218 arg = self.format(elt['content'][0]) 217 arg = self.format(elt['content'][0])
219 if len(elt['content']) > 1: 218 if len(elt['content']) > 1:
220 s = map(self.format, elt['content']) 219 s = [x for x in map(self.format, elt['content'])]
221 text = s[1] 220 text = s[1]
222 else: 221 else:
223 s = None 222 s = None
224 text = None 223 text = None
225 224
226 if s: 225 if s:
diff --git a/wiki2text.py b/wiki2text.py
index 6308da1..916391e 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -13,13 +13,12 @@
13# GNU General Public License for more details. 13# GNU General Public License for more details.
14# 14#
15# You should have received a copy of the GNU General Public License 15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18from wikimarkup import * 18from wikimarkup import *
19from types import TupleType
20from wikins import wiki_ns_re, wiki_ns 19from wikins import wiki_ns_re, wiki_ns
21import re 20import re
22import urllib 21import urllib
23 22
24class TextWikiMarkup (WikiMarkup): 23class TextWikiMarkup (WikiMarkup):
25 """ 24 """
@@ -65,13 +64,13 @@ class TextWikiMarkup (WikiMarkup):
65 lang = self.lang 64 lang = self.lang
66 return self.html_base % { 'lang' : lang } + urllib.quote(tgt) 65 return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
67 66
68 def fmtlink(self, elt, istmpl): 67 def fmtlink(self, elt, istmpl):
69 arg = self.format(elt['content'][0]) 68 arg = self.format(elt['content'][0])
70 if len(elt['content']) > 1: 69 if len(elt['content']) > 1:
71 s = map(self.format, elt['content']) 70 s = [x for x in map(self.format, elt['content'])]
72 text = s[1] 71 text = s[1]
73 else: 72 else:
74 s = None 73 s = None
75 text = None 74 text = None
76 75
77 if s: 76 if s:
diff --git a/wikicvt.py b/wikicvt.py
index c8ca887..41bba2f 100755
--- a/wikicvt.py
+++ b/wikicvt.py
@@ -12,33 +12,37 @@
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details. 13# GNU General Public License for more details.
14# 14#
15# You should have received a copy of the GNU General Public License 15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>. 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18from __future__ import print_function
18import sys 19import sys
19import getopt 20import getopt
20import StringIO 21try:
22 from StringIO import StringIO
23except ImportError:
24 from io import StringIO
21from wiki2html import * 25from wiki2html import *
22from wiki2text import * 26from wiki2text import *
23from wiki2texi import * 27from wiki2texi import *
24 28
25class DumpWikiMarkup (WikiMarkup): 29class DumpWikiMarkup (WikiMarkup):
26 def __str__(self): 30 def __str__(self):
27 if self.tree: 31 if self.tree:
28 s = StringIO.StringIO() 32 s = StringIO()
29 self.dump(self.tree, 0, s) 33 self.dump(self.tree, 0, s)
30 return s.getvalue() 34 return s.getvalue()
31 else: 35 else:
32 return "" 36 return ""
33 37
34def usage(code=0): 38def usage(code=0):
35 print """ 39 print("""usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang]
36usage: %s [-hvt] [-I INTYPE] [-l lang] [-o kw=val] [--lang=lang] [--option kw=val] 40 [--option kw=val] [--input-type=INTYPE] [--type=OUTTYPE] [--help]
37 [--input-type=INTYPE] [--type=OUTTYPE] [--help] [--verbose] file 41 [--verbose] file
38""" % (sys.argv[0]) 42""" % sys.argv[0])
39 sys.exit(code) 43 sys.exit(code)
40 44
41handlers = { 45handlers = {
42 'dump': { 46 'dump': {
43 'default': DumpWikiMarkup 47 'default': DumpWikiMarkup
44 }, 48 },
@@ -106,16 +110,16 @@ def main():
106 110
107 if otype in handlers: 111 if otype in handlers:
108 if itype in handlers[otype]: 112 if itype in handlers[otype]:
109 markup = handlers[otype][itype](**kwdict) 113 markup = handlers[otype][itype](**kwdict)
110 markup.debug_level = debug 114