summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2008-11-29 11:39:55 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2008-11-29 11:39:55 (GMT)
commit88befee77fdaacc2e0dc92beffd1c6a68f86a8b7 (patch) (side-by-side diff)
treec0cc395d493b44f1a3bfae313e04176b55a8ecfc
parentf7a8c1c22c8e362e94768d3e93d74a85f82a3b1a (diff)
downloadwikitrans-88befee77fdaacc2e0dc92beffd1c6a68f86a8b7.tar.gz
wikitrans-88befee77fdaacc2e0dc92beffd1c6a68f86a8b7.tar.bz2
Handle links inside link texts
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--wikimarkup.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/wikimarkup.py b/wikimarkup.py
index 46aa839..429a02a 100644
--- a/wikimarkup.py
+++ b/wikimarkup.py
@@ -26,8 +26,8 @@ eltre = re.compile("(\\[\\[)|(\\{\\{)|\\[|(\\'\\'\\'?)")
delims = { "[[" : re.compile("\\||(\\]\\])"),
"{{" : re.compile("\\||(\\}\\})") }
term = { "[[" : "]]" , "{{" : "}}" }
-ends = { "[[" : re.compile("\\]\\]"),
- "{{" : re.compile("\\}\\}") }
+ends = { "[[" : re.compile("(\\[\\[)|(\\]\\])"),
+ "{{" : re.compile("(\\{\\{)|(\\}\\})") }
itend = re.compile("\\'\\'($|[^\\'])")
boend = re.compile("\\'\\'\\'($|[^\\'])")
@@ -115,6 +115,21 @@ It handles:
else:
pos = d.start(0) + 1
+ def linkend(self, paren, line, pos):
+ r = ends[paren]
+ count = 1
+ while count > 0:
+ m = r.search(line, pos);
+ if not m:
+ return len(line), len(line)
+ else:
+ pos = m.end(0)
+ if m.group(0) == paren:
+ count += 1
+ else:
+ count -= 1
+ return m.start(0), m.end(0)
+
la = None
def putback(self, line):
self.la = line
@@ -172,8 +187,7 @@ It handles:
self.putback(line)
break
yield(self.getkn(line))
-
-
+
def getkn(self, line):
pos = 0
while 1:
@@ -189,10 +203,9 @@ It handles:
if m.group(0) == "[[" or m.group(0) == "{{":
d = delims[m.group(0)].search(line, pos)
if d.group(0) == "|":
- e = ends[m.group(0)].search(line, d.end(0))
target = (self.TEXT, line[pos:d.start(0)])
- text = (self.SEQ, self.getkn(line[d.end(0):e.start(0)]))
- pos = e.end(0)
+ (start,pos) = self.linkend(m.group(0), line, m.end(0))
+ text = (self.SEQ, self.getkn(line[d.end(0):start]))
elif d.group(0) == term[m.group(0)]:
target = (self.TEXT, line[pos:d.start(0)])
text = (self.NIL,)

Return to:

Send suggestions and report system problems to the System administrator.