summaryrefslogtreecommitdiff
path: root/wiki2text.py
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-06 00:13:37 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-03-06 00:13:37 +0200
commit6b699b060de765112fa03435b4afbd258262d1fb (patch)
tree940b584e5618a73215bc0a269f0c0a4ac718a74f /wiki2text.py
parenta8cd24f0f5cbefccdefd2a4a5166b89c6c8f7a54 (diff)
downloadwikitrans-6b699b060de765112fa03435b4afbd258262d1fb.tar.gz
wikitrans-6b699b060de765112fa03435b4afbd258262d1fb.tar.bz2
Lots of formatting kludges
Diffstat (limited to 'wiki2text.py')
-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
@@ -15,12 +15,13 @@
# 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 types import TupleType
from wikins import wiki_ns_re, wiki_ns
+import re
import urllib
class TextWikiMarkup (WikiMarkup):
"""
A (general-purpose Wiki->Text translator class.
"""
@@ -64,15 +65,23 @@ class TextWikiMarkup (WikiMarkup):
lang = self.lang
return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
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)
if ns:
if ns == 'NS_IMAGE':
if not self.references:
@@ -140,42 +149,46 @@ class TextWikiMarkup (WikiMarkup):
for s in elt[1]:
if string:
if string.endswith("."):
string += " "
else:
string += " "
- string += s.rstrip(" ")
+ string += s
else:
string = elt[1]
elif elt[0] == PARA:
string = "";
for x in elt[1]:
string += self.format(x)
string = self.fmtpara(string) + '\n\n'
elif elt[0] == IT:
string = ""
for x in elt[1]:
s = self.format(x)
if s:
- string += " " + s.rstrip(" ")
+ string += " " + s
string = "_" + string.lstrip(" ") + "_"
elif elt[0] == BOLD:
string = ""
for x in elt[1]:
s = self.format(x)
if s:
if string.endswith("."):
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:
w = 5
string = "\n" + ("-" * (w - 5)).center(w - 1) + "\n"
elif elt[0] == HDR:
@@ -193,15 +206,15 @@ class TextWikiMarkup (WikiMarkup):
n = 1
for s in elt[3]:
if not string.endswith("\n"):
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"
elif elt[0] == IND:
string = (" " * elt[1]) + self.format(elt[2]) + '\n'
elif elt[0] == SEQ:

Return to:

Send suggestions and report system problems to the System administrator.