summaryrefslogtreecommitdiffabout
path: root/wiki2text.py
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-05 22:13:37 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2009-03-05 22:13:37 (GMT)
commit6b699b060de765112fa03435b4afbd258262d1fb (patch) (unidiff)
tree940b584e5618a73215bc0a269f0c0a4ac718a74f /wiki2text.py
parenta8cd24f0f5cbefccdefd2a4a5166b89c6c8f7a54 (diff)
downloadwikitrans-6b699b060de765112fa03435b4afbd258262d1fb.tar.gz
wikitrans-6b699b060de765112fa03435b4afbd258262d1fb.tar.bz2
Lots of formatting kludges
Diffstat (limited to 'wiki2text.py') (more/less context) (ignore whitespace changes)
-rw-r--r--wiki2text.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/wiki2text.py b/wiki2text.py
index 09bd86a..5fcd718 100644
--- a/wiki2text.py
+++ b/wiki2text.py
@@ -18,6 +18,7 @@
18from wikimarkup import * 18from wikimarkup import *
19from types import TupleType 19from types import TupleType
20from wikins import wiki_ns_re, wiki_ns 20from wikins import wiki_ns_re, wiki_ns
21import re
21import urllib 22import urllib
22 23
23class TextWikiMarkup (WikiMarkup): 24class TextWikiMarkup (WikiMarkup):
@@ -67,9 +68,17 @@ class TextWikiMarkup (WikiMarkup):
67 def fmtlink(self, elt, istmpl): 68 def fmtlink(self, elt, istmpl):
68 arg = self.format(elt[1][0]) 69 arg = self.format(elt[1][0])
69 if len(elt[1]) > 1: 70 if len(elt[1]) > 1:
70 text = self.format(elt[1][1]) 71 s = map(self.format, elt[1])
72 text = s[1]
71 else: 73 else:
74 s = None
72 text = None 75 text = None
76
77 if s:
78 if s[0] == 'disambigR':
79 return ""
80 if len(s) > 1 and s[1] == 'thumb':
81 return ""
73 (qual,sep,tgt) = arg.partition(':') 82 (qual,sep,tgt) = arg.partition(':')
74 if tgt != '': 83 if tgt != '':
75 ns = self.wiki_ns_name(qual) 84 ns = self.wiki_ns_name(qual)
@@ -143,7 +152,7 @@ class TextWikiMarkup (WikiMarkup):
143 string += " " 152 string += " "
144 else: 153 else:
145 string += " " 154 string += " "
146 string += s.rstrip(" ") 155 string += s
147 else: 156 else:
148 string = elt[1] 157 string = elt[1]
149 elif elt[0] == PARA: 158 elif elt[0] == PARA:
@@ -156,7 +165,7 @@ class TextWikiMarkup (WikiMarkup):
156 for x in elt[1]: 165 for x in elt[1]:
157 s = self.format(x) 166 s = self.format(x)
158 if s: 167 if s:
159 string += " " + s.rstrip(" ") 168 string += " " + s
160 string = "_" + string.lstrip(" ") + "_" 169 string = "_" + string.lstrip(" ") + "_"
161 elif elt[0] == BOLD: 170 elif elt[0] == BOLD:
162 string = "" 171 string = ""
@@ -167,12 +176,16 @@ class TextWikiMarkup (WikiMarkup):
167 string += " " 176 string += " "
168 else: 177 else:
169 string += " " 178 string += " "
170 string += s.rstrip(" ") 179 string += s
171 string = string.upper() 180 string = string.upper()
172 elif elt[0] == LINK: 181 elif elt[0] == LINK:
173 string = self.fmtlink(elt, False) 182 string = self.fmtlink(elt, False)
174 elif elt[0] == TMPL: 183 elif elt[0] == TMPL:
175 string = '[' + self.fmtlink(elt, True) + ']' 184 s = self.fmtlink(elt, True)
185 if s:
186 string = '[' + s + ']'
187 else:
188 string = s
176 elif elt[0] == BAR: 189 elif elt[0] == BAR:
177 w = self.width 190 w = self.width
178 if w < 5: 191 if w < 5:
@@ -196,9 +209,9 @@ class TextWikiMarkup (WikiMarkup):
196 string += "\n" 209 string += "\n"
197 x = self.format(s) 210 x = self.format(s)
198 if type == ENVUNNUM: 211 if type == ENVUNNUM:
199 string += self.indent(lev, "- " + x.lstrip(" ")) 212 string += self.fmtpara(self.indent(lev, "- " + x.lstrip(" ")))
200 elif type == ENVNUM: 213 elif type == ENVNUM:
201 string += self.indent(lev, "%d. %s" % (n, x)) 214 string += self.fmtpara(self.indent(lev, "%d. %s" % (n, x)))
202 n += 1 215 n += 1
203 if not string.endswith("\n"): 216 if not string.endswith("\n"):
204 string += "\n" 217 string += "\n"

Return to:

Send suggestions and report system problems to the System administrator.