Modified:
/trunk/rig3serv/misc/TaskList.txt
/trunk/rig3serv/src/rig/parser/izu_parser.py
/trunk/rig3serv/src/rig/version.py
/trunk/rig3serv/src/tests/parser/test_izu_parser.py
=======================================
--- /trunk/rig3serv/misc/TaskList.txt Sun Apr 4 12:11:03 2010
+++ /trunk/rig3serv/misc/TaskList.txt Sun Apr 4 15:59:00 2010
@@ -38,6 +38,7 @@
---- Done Version 0.4 ----
+20100404 Izu: Implement legacy Izumi [table] and [izu:image] tags
20100404 Engine: Add option to exclude some categories from the 'all
index' page
20100215 Template: Fix broken rounded borders on Chrome
=======================================
--- /trunk/rig3serv/src/rig/parser/izu_parser.py Thu Feb 11 23:42:04 2010
+++ /trunk/rig3serv/src/rig/parser/izu_parser.py Sun Apr 4 15:59:00 2010
@@ -177,12 +177,12 @@
self._rig_base = rig_base
# custom section handlers. Unlisted sections use the "default"
formatter
- self._escape_block = { "--": self._EscapeComment,
- "html:": self._EscapeRawHtml }
- self._formatters = { "images": self._ImagesSection,
- "html": self._HtmlSection }
- self._tag_handlers = { "cat": self._CatHandler,
- "date": self._DateHandler }
+ self._escape_block = { "--" : self._EscapeComment,
+ "html:" : self._EscapeRawHtml }
+ self._formatters = { "images": self._ImagesSection,
+ "html" : self._HtmlSection }
+ self._tag_handlers = { "cat" : self._CatHandler,
+ "date" : self._DateHandler }
def RenderFileToHtml(self, filestream):
"""
@@ -392,7 +392,15 @@
tag = m.group("tag")
value = m.group("value")
- if tag:
+
+ if tag == "image":
+ # izu:image is handled here for legacy reasons.
+ # In Izumi, this is an HTML tag formatter, not a meta
+ # processing tag. So we'll just rewrite it as izu_image
+ # and let _DefaultSection handle it.
+ line = start + "[izu_%s:%s]" % (tag, value) + end
+
+ elif tag:
self._tag_handlers.get(tag,
self._DefaultTagHandler)(state, tag, value)
else:
# log an error and ignore
@@ -443,8 +451,10 @@
line = self._FormatBoldItalicHtmlEmpty(line)
line = self._FormatSimpleTags(state, line)
line = self._FormatHtmlTags(state, line)
- line = self._FormatCenter(state, line)
+ line = self._FormatTableTags(state, line)
+ line = self._FormatIzuImage(state, line)
line = self._FormatYoutube(state, line)
+ line = self._FormatCenter(state, line)
line = self._FormatLinks(state, line)
line = self._FormatLists(state, line)
@@ -635,6 +645,104 @@
_RE_TAG_YOUTUBE =
re.compile(r"(?P<before>.*?)(?<!\[)\[youtube:(?P<id>[^:\"\'\<\>\]]+)(?::(?P<sx>[0-9]+)x(?P<sy>[0-9]+))?\](?P<after>.*)")
+ def _FormatTableTags(self, state, line):
+ """
+ Formats table tags:
+ [table:begin:100%:50px]
+ where first 100% or 100px is the table width and second
one is column width
+ and are both optional.
+ [col:50%]
+ [row:50%]
+ where 50% or 50px is the column width, optional.
+ [table:end]
+ """
+
+ for regexp, replace in [ ( self._RE_TAG_TABLE_BEGIN,
+ "<table border=\"0\" %s><tr
valign=\"top\"><td %s>" ),
+ ( self._RE_TAG_TABLE_COL,
+ "</td><td %s>" ),
+ ( self._RE_TAG_TABLE_ROW,
+ "</td></tr><tr valign=\"top\"><td %s>"
),
+ ( self._RE_TAG_TABLE_END,
+ "</td></tr></table>" )
+ ]:
+ m = True
+ while m:
+ m = regexp.match(line)
+ if m:
+ before = m.group("before") or ""
+ after = m.group("after") or ""
+
+ try:
+ # first width (table with for begin, column width
for row/col)
+ w1 = m.group("w1") or ""
+ if w1:
+ w1 = " width=\"" + w1 + "\""
+
+ # second width (column width for begin, none for
the others)
+ try:
+ w2 = m.group("w2") or ""
+ if w2:
+ w2 = " width=\"" + w2 + "\""
+ replace = replace % ( w1, w2 )
+ except IndexError:
+ # no w2 argument
+ replace = replace % ( w1 )
+ except IndexError:
+ pass # no w1 argument
+
+ line = "%s%s%s" % (before, replace, after)
+
+
+
+ return line
+
+ _RE_TAG_TABLE_BEGIN =
re.compile(r"(?P<before>.*?)(?<!\[)\[table:begin(?::(?P<w1>[0-9]+(?:%|
px))(?::(?P<w2>[0-9]+(?:%|px)))?)?\](?P<after>.*)")
+ _RE_TAG_TABLE_COL =
re.compile(r"(?P<before>.*?)(?<!\[)\[col(?::(?P<w1>[0-9]+(?:%|
px)))?\](?P<after>.*)")
+ _RE_TAG_TABLE_ROW =
re.compile(r"(?P<before>.*?)(?<!\[)\[row(?::(?P<w1>[0-9]+(?:%|
px)))?\](?P<after>.*)")
+ _RE_TAG_TABLE_END =
re.compile(r"(?P<before>.*?)(?<!\[)\[table:end\](?P<after>.*)")
+
+ def _FormatIzuImage(self, state, line):
+ """
+ Formats izu_image with optional align tag, optional link and
optional label
+ Syntax is [izu_image:url_img(,align=blah)(|url_link)(:label)]
+ If label is defined, it is used for <img title>.
+ If url_link is defined, it is used to wrap the img using an <a
href>.
+ Url_link must start with http. The link cannot contain " : or < >
+ """
+ m = True
+ while m:
+ m = self._RE_TAG_IZU_IMG.match(line)
+ if m:
+ before = m.group("before") or ""
+ after = m.group("after") or ""
+ img = m.group("img") or ""
+ tag = m.group("tag") or ""
+ value = m.group("value") or ""
+ link = m.group("link") or ""
+ label = m.group("label") or ""
+
+ if tag and value:
+ tag = "%s=%s" % (tag, value)
+ else:
+ tag = ""
+ if label:
+ tag = "%s title=\"%s\"" % (tag, label)
+
+ img = "<img src=\"%s\" %s />" % (img, tag)
+
+ if link:
+ link = "<a href=\"%s\">%s</a>" % (link, img)
+ else:
+ link = img
+
+ line = "%s%s%s" % (before, link, after)
+
+ return line
+
+ # Note: the [izu:image:..] tag is rewritten to [izu_image:..] by
_ParseIzuTags
+ _RE_TAG_IZU_IMG =
re.compile(r"(?i)(?P<before>.*?)(?<!\[)\[izu_image:(?P<img>https?://[^\],\"<>]+\.(?:gif|
jpe?g|png|svg))(?:,(?P<tag>[a-z]+)=(?P<value>[a-z]+))?(?:\|
(?P<link>(?:https?://|ftp://|
#)[^:\"<>\]]+))?(?::(?P<label>[^\]]+))?\](?P<after>.*)")
+
def _FormatLinks(self, state, line):
"""
Formats straight URLs and tags for URLs & images
=======================================
--- /trunk/rig3serv/src/rig/version.py Mon Feb 15 10:55:36 2010
+++ /trunk/rig3serv/src/rig/version.py Sun Apr 4 15:59:00 2010
@@ -13,7 +13,7 @@
To enable substitutions, do something like this:
$ svn propset svn:keywords "Date Author Revision HeadURL Id" version.py
-----
+-----
Part of Rig3.
Copyright (C) 2007-2009 ralfoide gmail com
=======================================
--- /trunk/rig3serv/src/tests/parser/test_izu_parser.py Thu Feb 11 23:42:04
2010
+++ /trunk/rig3serv/src/tests/parser/test_izu_parser.py Sun Apr 4 15:59:00
2010
@@ -221,6 +221,24 @@
'<span class="izu">\n[[raw youtube_html %
{ "id": "ab_CdefgGh", "sx": 640, "sy": 385 } ]].</span>',
self._Render("[youtube:ab_CdefgGh:640x385]."))
+ def testTable(self):
+ self.assertEquals(
+ '<span class="izu">\n<table border="0" width="100%"><tr
valign="top"><td width="50px">my column 1</td><td width="48px">my column
2</td></tr><tr valign="top"><td width="40%">second
row</td></tr></table></span>',
+ self._Render("[table:begin:100%:50px]my column 1[col:48px]my
column 2[row:40%]second row[table:end]"))
+
+ self.assertEquals(
+ '<span class="izu">\n<table border="0" width="100%"><tr
valign="top"><td >my column 1</td><td >my column 2</td></tr><tr
valign="top"><td >second row</td></tr></table></span>',
+ self._Render("[table:begin:100%]my column 1[col]my column
2[row]second row[table:end]"))
+
+ self.assertEquals(
+ '<span class="izu">\n<table border="0" ><tr valign="top"><td
>my column 1</td><td >my column 2</td></tr><tr valign="top"><td >second
row</td></tr></table></span>',
+ self._Render("[table:begin]my column 1[col]my column
2[row]second row[table:end]"))
+
+ def testIzuImage(self):
+ self.assertEquals(
+ '<span class="izu">\n<a
href="http://en.wikipedia.org/wiki/Apple_iic"><img
src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Apple_iicb.jpg/150px-Apple_iicb.jpg"
title="Apple IIc (Wikipedia)" /></a></span>',
+
self._Render("[izu:image:http://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Apple_iicb.jpg/150px-Apple_iicb.jpg|
http://en.wikipedia.org/wiki/Apple_iic:Apple IIc (Wikipedia)]"))
+
def testBold(self):
self.assertEquals(
'<span class="izu">\n<b>this</b> is <b>in bold</b> but not
<b>this</b></span>',