summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-03-05 20:25:52 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-03-05 20:25:52 +0200
commita8cd24f0f5cbefccdefd2a4a5166b89c6c8f7a54 (patch)
treef9dfb0da028c041fe06b1baa29a995fa90c2162a
parent7153f67c6ea71d684d412efd032c309cd273ed19 (diff)
downloadwikitrans-a8cd24f0f5cbefccdefd2a4a5166b89c6c8f7a54.tar.gz
wikitrans-a8cd24f0f5cbefccdefd2a4a5166b89c6c8f7a54.tar.bz2
Avoid losing newlines while parsing the input stream. Provide some rudimentary parsing for wiktionary templates
-rw-r--r--wiki2html.py53
-rwxr-xr-x[-rw-r--r--]wikicvt.py0
-rw-r--r--wikimarkup.py6
3 files changed, 52 insertions, 7 deletions
diff --git a/wiki2html.py b/wiki2html.py
index 5a8fdcc..faab18b 100644
--- a/wiki2html.py
+++ b/wiki2html.py
@@ -20,2 +20,3 @@ from types import TupleType
from wikins import wiki_ns_re, wiki_ns
+import re
import urllib
@@ -47,2 +48,32 @@ class HtmlWikiMarkup (WikiMarkup):
return self.html_base % { 'lang' : lang } + urllib.quote(tgt)
+
+ def tmpl_term(self, s):
+ if len(s) == 2:
+ return s[1]
+ text = None
+ trans = None
+ for x in s[1:]:
+ m = re.match('(\w+)=', x)
+ if m:
+ if m.group(1) == "tr":
+ trans = x[m.end(1)+1:]
+ elif not text:
+ text = x
+ if text:
+ if trans:
+ text += ' <span class="trans">[' + trans + ']</span>'
+ return text
+
+ def tmpl_proto(self, s):
+ text = '<span class="proto-lang">Proto-' + s[1] + '</span>'
+ if len(s) >= 4:
+ n = 0
+ for x in s[2:-2]:
+ if n > 0:
+ text += ','
+ n += 1
+ text += ' <span class="proto">' + x + '</span>'
+ text += ' <span class="meaning">(' + s[-2] + ')</span>'
+ return text
+
@@ -50,6 +81,16 @@ class HtmlWikiMarkup (WikiMarkup):
arg = self.format(elt[1][0])
+ text = None
if len(elt[1]) > 1:
- text = self.format(elt[1][1])
- else:
- text = None
+ text = '<span class="template">' + self.format(elt[1][1]) + '</span>'
+ if istmpl:
+ s = map(self.format, elt[1])
+ if re.match("t[+-]$", s[0]):
+ if len(s) > 2:
+ text = s[2]
+ elif s[0] == "term":
+ text = self.tmpl_term(s)
+ elif s[0] == "proto":
+ text = self.tmpl_proto(s)
+ return text
+
(qual,sep,tgt) = arg.partition(':')
@@ -91,6 +132,6 @@ class HtmlWikiMarkup (WikiMarkup):
def str_link(self, elt):
- return self.fmtlink(elt, False) + " "
+ return self.fmtlink(elt, False)
def str_tmpl(self, elt):
- return self.fmtlink(elt, True) + " "
+ return self.fmtlink(elt, True)
@@ -106,3 +147,3 @@ class HtmlWikiMarkup (WikiMarkup):
for x in eltlist:
- string += " " + self.format(x)
+ string += self.format(x)
return string
diff --git a/wikicvt.py b/wikicvt.py
index a2e95e4..a2e95e4 100644..100755
--- a/wikicvt.py
+++ b/wikicvt.py
diff --git a/wikimarkup.py b/wikimarkup.py
index 716bc4a..a340628 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -185,2 +185,3 @@ class BaseWikiMarkup:
return None
+ seq.append((TEXT, '\n'))
else:
@@ -245,2 +246,3 @@ class BaseWikiMarkup:
elif tok[0] == NL:
+ list.append((TEXT, '\n'))
continue
@@ -301,2 +303,3 @@ class BaseWikiMarkup:
break
+ textlist.append('\n')
elif tok[0] == NIL:
@@ -433,3 +436,4 @@ class BaseWikiMarkup:
elif toktype == NL:
- return self.parse0()
+ return (TEXT, '\n')
+# return self.parse0()

Return to:

Send suggestions and report system problems to the System administrator.