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) (side-by-side diff)
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 @@
from wikimarkup import *
from types import TupleType
from wikins import wiki_ns_re, wiki_ns
+import re
import urllib
class TextWikiMarkup (WikiMarkup):
@@ -67,9 +68,17 @@ class TextWikiMarkup (WikiMarkup):
def fmtlink(self, elt, istmpl):
arg = self.format(elt[1][0])
if len(elt[1]) > 1:
- text = self.format(elt[1][1])
+ s = map(self.format, elt[1])
+ text = s[1]
else:
+ s = None
text = None
+
+ if s:
+ if s[0] == 'disambigR':
+ return ""
+ if len(s) > 1 and s[1] == 'thumb':
+ return ""
(qual,sep,tgt) = arg.partition(':')
if tgt != '':
ns = self.wiki_ns_name(qual)
@@ -143,7 +152,7 @@ class TextWikiMarkup (WikiMarkup):
string += " "
else:
string += " "
- string += s.rstrip(" ")
+ string += s
else:
string = elt[1]
elif elt[0] == PARA:
@@ -156,7 +165,7 @@ class TextWikiMarkup (WikiMarkup):
for x in elt[1]:
s = self.format(x)
if s:
- string += " " + s.rstrip(" ")
+ string += " " + s
string = "_" + string.lstrip(" ") + "_"
elif elt[0] == BOLD:
string = ""
@@ -167,12 +176,16 @@ class TextWikiMarkup (WikiMarkup):
string += " "
else:
string += " "
- string += s.rstrip(" ")
+ string += s
string = string.upper()
elif elt[0] == LINK:
string = self.fmtlink(elt, False)
elif elt[0] == TMPL:
- string = '[' + self.fmtlink(elt, True) + ']'
+ s = self.fmtlink(elt, True)
+ if s:
+ string = '[' + s + ']'
+ else:
+ string = s
elif elt[0] == BAR:
w = self.width
if w < 5:
@@ -196,9 +209,9 @@ class TextWikiMarkup (WikiMarkup):
string += "\n"
x = self.format(s)
if type == ENVUNNUM:
- string += self.indent(lev, "- " + x.lstrip(" "))
+ string += self.fmtpara(self.indent(lev, "- " + x.lstrip(" ")))
elif type == ENVNUM:
- string += self.indent(lev, "%d. %s" % (n, x))
+ string += self.fmtpara(self.indent(lev, "%d. %s" % (n, x)))
n += 1
if not string.endswith("\n"):
string += "\n"

Return to:

Send suggestions and report system problems to the System administrator.