1.1 --- a/moinformat/__init__.py Mon May 01 18:24:22 2017 +0200
1.2 +++ b/moinformat/__init__.py Mon May 01 22:02:52 2017 +0200
1.3 @@ -20,7 +20,7 @@
1.4 """
1.5
1.6 from moinformat.tree import Block, Break, DefItem, DefTerm, FontStyle, Heading, \
1.7 - ListItem, Monospace, Region, Rule, Text
1.8 + ListItem, Monospace, Region, Rule, Text, Underline
1.9 import re
1.10
1.11 # Regular expressions.
1.12 @@ -57,9 +57,11 @@
1.13 "fontstyle" : r"('{2,6})",
1.14 "monospace" : r"`",
1.15 "rule" : r"(-----*)", # ----...
1.16 + "underline" : r"__",
1.17
1.18 # Inline contents:
1.19 "monospaceend" : r"`",
1.20 + "underlineend" : r"__",
1.21
1.22 # Heading contents:
1.23 "headingend" : r"(\s+)(=+)(\s*\n)", # ws... =... [ws...] nl
1.24 @@ -202,6 +204,7 @@
1.25 "monospace",
1.26 "regionstart", "regionend",
1.27 "rule",
1.28 + "underline",
1.29 ])
1.30
1.31 def parse_region_opaque(items, region):
1.32 @@ -323,7 +326,7 @@
1.33
1.34 span = FontStyle([], emphasis, strong)
1.35 if not double:
1.36 - parse_region_details(items, span, ["fontstyle", "monospace"])
1.37 + parse_region_details(items, span, ["fontstyle", "monospace", "underline"])
1.38 region.append_inline(span)
1.39
1.40 def parse_heading(items, region):
1.41 @@ -334,7 +337,7 @@
1.42 level = len(items.read_match(2))
1.43 start_pad = items.read_match(3)
1.44 heading = Heading([], level, start_extra, start_pad)
1.45 - parse_region_details(items, heading, ["headingend"])
1.46 + parse_region_details(items, heading, ["fontstyle", "headingend", "monospace", "underline"])
1.47 region.append(heading)
1.48 new_block(region)
1.49
1.50 @@ -365,7 +368,7 @@
1.51 "Handle monospace."
1.52
1.53 span = Monospace([])
1.54 - parse_region_details(items, span, ["fontstyle", "monospaceend"])
1.55 + parse_region_details(items, span, ["fontstyle", "monospaceend", "underline"])
1.56 region.append_inline(span)
1.57
1.58 def parse_rule(items, region):
1.59 @@ -398,6 +401,14 @@
1.60 else:
1.61 region.append_inline(Text(feature))
1.62
1.63 +def parse_underline(items, region):
1.64 +
1.65 + "Handle underline."
1.66 +
1.67 + span = Underline([])
1.68 + parse_region_details(items, span, ["fontstyle", "monospace", "underlineend"])
1.69 + region.append_inline(span)
1.70 +
1.71 # Pattern handlers.
1.72
1.73 handlers = {
1.74 @@ -421,6 +432,8 @@
1.75 "regionstart" : parse_section,
1.76 "regionend" : parse_section_end,
1.77 "rule" : parse_rule,
1.78 + "underline" : parse_underline,
1.79 + "underlineend" : end_region,
1.80 }
1.81
1.82 def new_block(region):
4.1 --- a/tests/test_parser.py Mon May 01 18:24:22 2017 +0200
4.2 +++ b/tests/test_parser.py Mon May 01 22:02:52 2017 +0200
4.3 @@ -90,6 +90,7 @@
4.4 == Not a heading == either
4.5 = Mismatched heading ==
4.6 == Another mismatched heading =
4.7 +=== Heading __Underlined__ ===
4.8 """)
4.9
4.10 sl.append("""\
4.11 @@ -101,7 +102,7 @@
4.12
4.13 '''Strong''''''text'''.
4.14
4.15 -Some `monospace` text. '''`Mono`, strong'''.
4.16 +Some `monospace` text. `Mono, '''strong'''`, __underlined__, __''under''lined__.
4.17 """)
4.18
4.19 dl = map(parse, sl)