3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
17 lambda m, f: f.addCode(m.group(1))
20 lambda m, f: f.addCode(m.group(1))
22 (
r'((( {2})+)(\S.*)(\n\s*\n|\n))+',
23 lambda m, f: f.addCode(m.group(0))
26 lambda m, f: f.addRaw(
'{c} '.format(c=m.group(1)))
or True 29 lambda m, f: f.addCode(m.group(1),
True)
32 (
'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]' 33 r'|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
34 lambda m, f: f.addLink(m.group(0), m.group(0))
37 lambda m, f: f.addEmphasis(m.group(1), 2)
40 lambda m, f: f.addEmphasis(m.group(1), 1)
44 def __init__(self, text, formatter):
52 parsed_block = [(UNPARSED, self.
text)]
53 for regex, func
in self.
regexes:
55 while index < len(parsed_block):
56 label, text = parsed_block[index]
63 match = re.search(regex, text)
65 parsed_block.pop(index)
66 start = match.start(0)
69 f = self.formatter.clone()
70 merge = func(match, f)
73 merged = text[:start] + f.dump() + text[end:]
74 parsed_block.insert(index, (UNPARSED, merged))
77 parsed_block.insert(index,
78 (UNPARSED, text[:start]))
81 parsed_block.insert(index, (PARSED, f.dump()))
85 parsed_block.insert(index,
86 (UNPARSED, text[end:]))
91 self.
lines += [i
for _, i
in parsed_block]