aboutsummaryrefslogtreecommitdiff
path: root/wiki2text.py
diff options
context:
space:
mode:
Diffstat (limited to 'wiki2text.py')
-rw-r--r--wiki2text.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/wiki2text.py b/wiki2text.py
index 916391e..5041ea0 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -12,16 +12,20 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from wikimarkup import *
-from wikins import wiki_ns_re, wiki_ns
+from wit.wikimarkup import *
+from wit.wikins import wiki_ns_re, wiki_ns
import re
-import urllib
+try:
+ from urllib import quote as url_quote
+except ImportError:
+ from urllib.parse import quote as url_quote
+
class TextWikiMarkup (WikiMarkup):
"""
A (general-purpose Wiki->Text translator class.
"""
@@ -59,13 +63,13 @@ class TextWikiMarkup (WikiMarkup):
return elt[2]
return None
def mktgt(self, tgt, lang = None):
if not lang:
lang = self.lang
- return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
+ return self.html_base % { 'lang' : lang } + url_quote(tgt)
def fmtlink(self, elt, istmpl):
arg = self.format(elt['content'][0])
if len(elt['content']) > 1:
s = [x for x in map(self.format, elt['content'])]
text = s[1]
@@ -84,14 +88,14 @@ class TextWikiMarkup (WikiMarkup):
if ns:
if ns == 'NS_IMAGE':
if not self.references:
return ""
text = "[%s: %s]" % (qual, text if text else arg)
tgt = self.image_base + '/' + \
- urllib.quote(tgt) + \
- '/250px-' + urllib.quote(tgt)
+ url_quote(tgt) + \
+ '/250px-' + url_quote(tgt)
elif ns == 'NS_MEDIA':
text = "[%s]" % (qual)
else:
tgt = self.mktgt(tgt)
elif not istmpl and qual in self.langtab:
text = self.langtab[qual] + ": " + tgt
@@ -109,13 +113,13 @@ class TextWikiMarkup (WikiMarkup):
def indent (self, lev, text):
if text.find('\n') == -1:
s = (" " * lev) + text
else:
s = ""
- for elt in text.split('\n'):
+ for elt in text.decode("utf-8").split('\n'):
if elt:
s += (" " * lev) + elt + '\n'
if not text.endswith('\n'):
s = s.rstrip('\n')
# print "IN: '%s'" % (text)
# print "OUT: '%s'" % (s)

Return to:

Send suggestions and report system problems to the System administrator.