aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test.py2
-rw-r--r--wiki2html.py4
-rw-r--r--wiki2texi.py4
-rw-r--r--wiki2text.py20
-rw-r--r--wikimarkup.py2
5 files changed, 19 insertions, 13 deletions
diff --git a/test.py b/test.py
index 9c72832..a348bc1 100644
--- a/test.py
+++ b/test.py
@@ -7,24 +7,26 @@
7# the Free Software Foundation; either version 3, or (at your option) 7# the Free Software Foundation; either version 3, or (at your option)
8# any later version. 8# any later version.
9# 9#
10# This program is distributed in the hope that it will be useful, 10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
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 18from __future__ import print_function
19import sys, os
20sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
19import unittest 21import unittest
20import wiki2html 22import wiki2html
21 23
22class TestMarkupParserBasic (unittest.TestCase): 24class TestMarkupParserBasic (unittest.TestCase):
23 25
24 def test_colon(self): 26 def test_colon(self):
25 self.assertTrue(self.__test('colon')) 27 self.assertTrue(self.__test('colon'))
26 pass 28 pass
27 29
28 def test_headings(self): 30 def test_headings(self):
29 self.assertTrue(self.__test('headings')) 31 self.assertTrue(self.__test('headings'))
30 pass 32 pass
diff --git a/wiki2html.py b/wiki2html.py
index 05d4642..abf851a 100644
--- a/wiki2html.py
+++ b/wiki2html.py
@@ -6,26 +6,26 @@
6# it under the terms of the GNU General Public License as published by 6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3, or (at your option) 7# the Free Software Foundation; either version 3, or (at your option)
8# any later version. 8# any later version.
9# 9#
10# This program is distributed in the hope that it will be useful, 10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
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 wikimarkup import * 18from wit.wikimarkup import *
19from wikins import wiki_ns_re, wiki_ns 19from wit.wikins import wiki_ns_re, wiki_ns
20import re 20import re
21try: 21try:
22 from urllib import quote as url_quote 22 from urllib import quote as url_quote
23except ImportError: 23except ImportError:
24 from urllib.parse import quote as url_quote 24 from urllib.parse import quote as url_quote
25 25
26class HtmlWikiMarkup (WikiMarkup): 26class HtmlWikiMarkup (WikiMarkup):
27 """ 27 """
28 A (hopefully) general-purpose Wiki->HTML translator class. 28 A (hopefully) general-purpose Wiki->HTML translator class.
29 FIXME: 1. See WikiMarkup for a list 29 FIXME: 1. See WikiMarkup for a list
30 2. [[official position]]s : final 's' gets after closing </a> tag. 30 2. [[official position]]s : final 's' gets after closing </a> tag.
31 Should be before. 31 Should be before.
diff --git a/wiki2texi.py b/wiki2texi.py
index 6e32c56..4ce32f9 100644
--- a/wiki2texi.py
+++ b/wiki2texi.py
@@ -6,26 +6,26 @@
6# it under the terms of the GNU General Public License as published by 6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3, or (at your option) 7# the Free Software Foundation; either version 3, or (at your option)
8# any later version. 8# any later version.
9# 9#
10# This program is distributed in the hope that it will be useful, 10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
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 wikimarkup import * 18from wit.wikimarkup import *
19from wikins import wiki_ns_re, wiki_ns 19from wit.wikins import wiki_ns_re, wiki_ns
20import re 20import re
21import urllib 21import urllib
22 22
23class TexiWikiMarkup (WikiMarkup): 23class TexiWikiMarkup (WikiMarkup):
24 sectcomm = { 24 sectcomm = {
25 'numbered': [ 25 'numbered': [
26 '@top', 26 '@top',
27 '@chapter', 27 '@chapter',
28 '@section', 28 '@section',
29 '@subsection', 29 '@subsection',
30 '@subsubsection' 30 '@subsubsection'
31 ], 31 ],
diff --git a/wiki2text.py b/wiki2text.py
index 916391e..5041ea0 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -6,28 +6,32 @@
6# it under the terms of the GNU General Public License as published by 6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3, or (at your option) 7# the Free Software Foundation; either version 3, or (at your option)
8# any later version. 8# any later version.
9# 9#
10# This program is distributed in the hope that it will be useful, 10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
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 wikimarkup import * 18from wit.wikimarkup import *
19from wikins import wiki_ns_re, wiki_ns 19from wit.wikins import wiki_ns_re, wiki_ns
20import re 20import re
21import urllib 21try:
22 from urllib import quote as url_quote
23except ImportError:
24 from urllib.parse import quote as url_quote
25
22 26
23class TextWikiMarkup (WikiMarkup): 27class TextWikiMarkup (WikiMarkup):
24 """ 28 """
25 A (general-purpose Wiki->Text translator class. 29 A (general-purpose Wiki->Text translator class.
26 """ 30 """
27 31
28 # Output width 32 # Output width
29 width = 78 33 width = 78
30 # Do not show references. 34 # Do not show references.
31 references = False 35 references = False
32 # Provide a minimum markup 36 # Provide a minimum markup
33 markup = True 37 markup = True
@@ -49,79 +53,79 @@ class TextWikiMarkup (WikiMarkup):
49 return "%s (see %s) " % (text, target) 53 return "%s (see %s) " % (text, target)
50 else: 54 else:
51 return "see " + target 55 return "see " + target
52 56
53 def wiki_ns_name(self, str): 57 def wiki_ns_name(self, str):
54 if str in wiki_ns[self.lang]: 58 if str in wiki_ns[self.lang]:
55 return wiki_ns[self.lang][str] 59 return wiki_ns[self.lang][str]
56 elif str in wiki_ns_re[self.lang]: 60 elif str in wiki_ns_re[self.lang]:
57 for elt in wiki_ns_re[self.lang][str]: 61 for elt in wiki_ns_re[self.lang][str]:
58 if str.beginswith(elt[0]) and str.endswith(elt[1]): 62 if str.beginswith(elt[0]) and str.endswith(elt[1]):
59 return elt[2] 63 return elt[2]
60 return None 64 return None
61 65
62 def mktgt(self, tgt, lang = None): 66 def mktgt(self, tgt, lang = None):
63 if not lang: 67 if not lang:
64 lang = self.lang 68 lang = self.lang
65 return self.html_base % { 'lang' : lang } + urllib.quote(tgt) 69 return self.html_base % { 'lang' : lang } + url_quote(tgt)
66 70
67 def fmtlink(self, elt, istmpl): 71 def fmtlink(self, elt, istmpl):
68 arg = self.format(elt['content'][0]) 72 arg = self.format(elt['content'][0])
69 if len(elt['content']) > 1: 73 if len(elt['content']) > 1:
70 s = [x for x in map(self.format, elt['content'])] 74 s = [x for x in map(self.format, elt['content'])]
71 text = s[1] 75 text = s[1]
72 else: 76 else:
73 s = None 77 s = None
74 text = None 78 text = None
75 79
76 if s: 80 if s:
77 if s[0] == 'disambigR' or s[0] == 'wikiquote': 81 if s[0] == 'disambigR' or s[0] == 'wikiquote':
78 return "" 82 return ""
79 if len(s) > 1 and s[1] == 'thumb': 83 if len(s) > 1 and s[1] == 'thumb':
80 return "" 84 return ""
81 (qual,sep,tgt) = arg.partition(':') 85 (qual,sep,tgt) = arg.partition(':')
82 if tgt != '': 86 if tgt != '':
83 ns = self.wiki_ns_name(qual) 87 ns = self.wiki_ns_name(qual)
84 if ns: 88 if ns:
85 if ns == 'NS_IMAGE': 89 if ns == 'NS_IMAGE':
86 if not self.references: 90 if not self.references:
87 return "" 91 return ""
88 text = "[%s: %s]" % (qual, text if text else arg) 92 text = "[%s: %s]" % (qual, text if text else arg)
89 tgt = self.image_base + '/' + \ 93 tgt = self.image_base + '/' + \
90 urllib.quote(tgt) + \ 94 url_quote(tgt) + \
91 '/250px-' + urllib.quote(tgt) 95 '/250px-' + url_quote(tgt)
92 elif ns == 'NS_MEDIA': 96 elif ns == 'NS_MEDIA':
93 text = "[%s]" % (qual) 97 text = "[%s]" % (qual)
94 else: 98 else:
95 tgt = self.mktgt(tgt) 99 tgt = self.mktgt(tgt)
96 elif not istmpl and qual in self.langtab: