1.1 --- a/parser.py Sun Apr 22 21:06:35 2012 +0200
1.2 +++ b/parser.py Sun Apr 22 23:22:05 2012 +0200
1.3 @@ -35,7 +35,7 @@
1.4
1.5 # Section extraction.
1.6
1.7 -sections_regexp_str = r"(?<!{)(?P<section>{(?P<type>[^{}\n]+)}.*?{(?P=type)})"
1.8 +sections_regexp_str = r"(?<!{){(?P<type>[^{}\n:]+)(:[^}\n]+)?}.*?{(?P=type)}"
1.9 sections_regexp = re.compile(sections_regexp_str, re.DOTALL | re.MULTILINE)
1.10
1.11 def get_regions(s):
1.12 @@ -57,7 +57,7 @@
1.13
1.14 # Section inspection.
1.15
1.16 -section_regexp_str = r"{(?P<sectiontype>[^\n]*?)}(?P<section>.*){(?P=sectiontype)}"
1.17 +section_regexp_str = r"{(?P<sectiontype>[^\n:]*?)(?::(?P<options>.*?))?}(?P<section>.*){(?P=sectiontype)}"
1.18 section_regexp = re.compile(section_regexp_str, re.DOTALL | re.MULTILINE)
1.19
1.20 def get_section_details(s):
1.21 @@ -66,7 +66,7 @@
1.22
1.23 match = section_regexp.match(s)
1.24 if match:
1.25 - return match.group("sectiontype"), match.group("section")
1.26 + return (match.group("sectiontype"), match.group("options")), match.group("section")
1.27 else:
1.28 return None, s
1.29
1.30 @@ -201,7 +201,7 @@
1.31
1.32 return rows
1.33
1.34 -# General parsing and translation.
1.35 +# Translation helpers.
1.36
1.37 blocktypes = {
1.38 "h1" : "= %s =",
1.39 @@ -247,6 +247,18 @@
1.40
1.41 return cellextra[cellsep] + text + cellextra[cellsep]
1.42
1.43 +sectiontypes = {
1.44 + "code" : "",
1.45 + "noformat" : "",
1.46 + "quote" : "",
1.47 + "info" : "wiki important",
1.48 + "note" : "wiki caution",
1.49 + "tip" : "wiki tip",
1.50 + "warning" : "wiki warning",
1.51 + }
1.52 +
1.53 +# General parsing.
1.54 +
1.55 def parse(s, out):
1.56
1.57 "Parse the content in the string 's', writing a translation to 'out'."
1.58 @@ -286,7 +298,17 @@
1.59 # Handle sections.
1.60
1.61 else:
1.62 - print >>out, "{{{",
1.63 + sectiontype, options = type
1.64 +
1.65 + # Direct translations of sections.
1.66 +
1.67 + mointype = sectiontypes.get(sectiontype)
1.68 + if mointype:
1.69 + print >>out, "{{{#!%s" % mointype
1.70 + if options:
1.71 + print >>out, "##", options
1.72 + else:
1.73 + print >>out, "{{{",
1.74 print >>out, text,
1.75 print >>out, "}}}"
1.76 print >>out