tag_filter = HTMLTagFilter.HTMLTagFilter(HTMLTagFilter.DENY_ALLOW, alist, dlist)
path_to_index = "./_markup_index"
+down_arrow = "http://static.sourceforge.jp/crystal/22x22/actions/1downarrow.png"
class _InputStream(object):
"""InputStream base class."""
def __init__(self):
+ self._image_dir = ""
pass
def __iter__(self):
self.index_add("figs", [])
- anchor = ""
+ self._anchor = ""
for line in self.input_iter:
line = self._default_markup_rule(line)
# head-of-line rules
if re.search(ur"^☆{{{$", line):
self._inline(line)
continue
+ elif re.search(ur"^☆image_dir:", line):
+ self._image_dir = re.search(ur"^☆image_dir:\s*(.*)$", line).group(1)
+ continue
elif re.search(ur"^☆comment\s{{{$", line):
self._comment(line)
continue
self._call_tables(line)
continue
elif re.search(ur"^●", line):
- if anchor != "":
- line = re.sub(ur"^●(.*)$", ur'<h4 id="%s">\1</h4>' % anchor, line)
- anchor = ""
+ if self._anchor != "":
+ line = re.sub(ur"^●(.*)$", ur'<h4 id="%s">\1</h4>' % self._anchor, line)
+ self._anchor = ""
else:
line = re.sub(ur"^●(.*)$", ur"<h4>\1</h4>", line)
print line
continue
elif re.search(ur"^○", line):
- if anchor != "":
- line = re.sub(ur"^○(.*)$", ur'<b id="%s">\1</b>' % anchor, line)
- anchor = ""
+ if self._anchor != "":
+ line = re.sub(ur"^○(.*)$", ur'<b id="%s">\1</b>' % self._anchor, line)
+ self._anchor = ""
else:
line = re.sub(ur"^○(.*)$", ur"<b>\1</b>", line)
print line
elif re.search(ur"^☆リスト", line):
self._list(line)
continue
+ elif re.search(ur"^☆flow", line):
+ self._flow(line)
+ continue
if re.search(ur"^ ", line):
line = "<p>" + line + "</p>"
# end-of-loop
+ def _head4(self, line):
+ if self._anchor != "":
+ line = re.sub(ur"^●(.*)$", ur'<h4 id="%s">\1</h4>' % self._anchor, line)
+ self._anchor = ""
+ else:
+ line = re.sub(ur"^●(.*)$", ur"<h4>\1</h4>", line)
+ print line
def load_index(self, path_to_index):
"""
# apply filter
# line = tag_filter.apply(line)
- line = re.sub(ur"[★*](表[0-9~]+)", ur"<b>\1</b>", line)
- line = re.sub(ur"[★*](図[0-9~]+)", ur"<b>\1</b>", line)
- line = re.sub(ur"[★*](リスト[0-9~]+)", ur"<b>\1</b>", line)
+ line = re.sub(ur"[★*](表[0-9~、]+)", ur"<b>\1</b>", line)
+ line = re.sub(ur"[★*](図[0-9~、]+)", ur"<b>\1</b>", line)
+ line = re.sub(ur"[★*](リスト[0-9~、]+)", ur"<b>\1</b>", line)
line = re.sub(ur"[★*]b\[(.*?)\]", ur"<b>\1</b>", line)
line = re.sub(ur"[★*]b\{(.*?)\}", ur"<b>\1</b>", line)
line = re.sub(ur"[★*]\[(\S*) (.*?)\]", r'<a href="\1">\2</a>', line)
# line = line.strip()
if re.search(ur"^☆}}}", line):
break
- print line
+ print line,
def _comment(self, line):
def _space(self, line):
print "<br><br>"
+ def _flow(self, line):
+ flow_header = """<div style="text-align:center; border: 1px solid; background-color:#EFF2F0; width:90%; margin: 0 auto 1em;">
+"""
+ flow_title = """<div style="text-align:left; padding:4px 4px 4px 1em; margin-bottom: 1em; border-bottom: 1px solid; font-weight: bold; background-color:#BCD;">
+%s
+</div>"""
+ flow_footer = """</div>
+"""
+ flow_item = """<div>
+%s
+<p>%s</p>
+</div>
+
+"""
+
+ rex_title = re.compile(ur"^☆flow\s+(.*)$")
+ if rex_title.search(line):
+ title = rex_title.search(line).group(1)
+ else:
+ title = ""
+
+ rex_file = re.compile(ur"^([^:]*):(.*)$")
+ outputs = []
+ for line in self.input_iter:
+ if re.search(r"^\s*$", line):
+ break
+ match = rex_file.search(line)
+ if match:
+ file = os.path.join(self._image_dir, match.group(1))
+ cap = match.group(2)
+ else:
+ continue
+ fig = self._anchored_fig(file, cap)
+ outputs.append(flow_item % (fig, cap))
+
+ arrow = '<img src="%s">\n' % (down_arrow,)
+ print flow_header
+ print flow_title % (title,)
+ print arrow.join(outputs)
+ print flow_footer
+
def _fig_start(self, cap=""):
return """<table align="center" border="0" cellpadding="0" cellspacing="0">
if self._release == 1:
self._fig_release(line)
else:
- self._fig(line)
+ self._fig_org(line)
- def _fig(self, line):
+ def _fig_org(self, line):
try:
str_title = re.search(ur"^☆(図.*)$", line).group(1)
except AttributeError:
match_o2 = re.search(ur"<(.*?),\s*(.*?)>", line)
if not match_o1 == None:
imgname = match_o1.group(1)
- imgname_s = re.sub(r"(.[A-Za-z0-9_]+)$", r"_s\1", match_o1.group(1))
+ imgname = os.path.join(self._image_dir, imgname)
+ imgname_s = re.sub(r"(.[A-Za-z0-9_]+)$", r"_s\1", imgname)
elif not match_o2 == None:
imgname = match_o1.group(1)
+ imgname = os.path.join(self._image_dir, imgname)
imgname_s = match_o1.group(2)
- if not os.path.isfile(imgname_s):
- imgname_s = imgname
+ print self._anchored_fig(imgname, str_title, imgname_s)
- print """<a href="%s">
- <img src="%s" alt="%s">
-</a>
- """ % (imgname, imgname_s, str_title)
-
+# if not os.path.isfile(imgname_s):
+# imgname_s = imgname
+
+# print """<a href="%s">
+# <img src="%s" alt="%s">
+# </a>
+# """ % (imgname, imgname_s, str_title)
dic = self.index("figs")
dic.append(imgname)
dic.append(imgname_s)
print self._fig_end(str_title);
+
+ def _anchored_fig(self, file, alt, file_s=""):
+
+ if file_s == "":
+ file_s = re.sub(r"(.[A-Za-z0-9_]+)$", r"_s\1", file)
+
+ if not os.path.isfile(file_s):
+ file_s = file
+ return """<a href="%s">
+ <img src="%s" alt="%s">
+</a>
+""" % (file, file_s, alt)
+
def _fig_release(self, line):
try:
try:
str_title = re.search(ur"^☆(表.*)$", line).group(1)
- fig_name = re.search(ur"^☆(表[0-9A-Z]+)", line).group(1)
+ fig_name = re.search(ur"^☆(表[0-9A-Z]*)", line).group(1)
except AttributeError:
str_title = ""
fig_name = ""