Hatta Numbered Lists Branch
changeset 642:4fe8d9070a6e
First version of the ordered-list patch
| author | Ben |
|---|---|
| date | Wed Dec 02 19:50:16 2009 +0100 (2009-12-02) |
| parents | 050b1a23cf9b |
| children | 870e7b10afda |
| files | hatta.py |
line diff
1.1 --- a/hatta.py Sun Nov 15 09:34:17 2009 +0100 1.2 +++ b/hatta.py Wed Dec 02 19:50:16 2009 +0100 1.3 @@ -646,10 +646,12 @@ 1.4 """ 1.5 1.6 bullets_pat = ur"^\s*[*]+\s+" 1.7 + list_pat = ur"^\s*[#]+\s+" 1.8 heading_pat = ur"^\s*=+" 1.9 quote_pat = ur"^[>]+\s+" 1.10 block = { 1.11 "bullets": bullets_pat, 1.12 + "list": list_pat, 1.13 "code": ur"^[{][{][{]+\s*$", 1.14 "conflict": ur"^<<<<<<< local\s*$", 1.15 "empty": ur"^\s*$", 1.16 @@ -727,6 +729,7 @@ 1.17 self.quote_re = re.compile(self.quote_pat, re.U) 1.18 self.heading_re = re.compile(self.heading_pat, re.U) 1.19 self.bullets_re = re.compile(self.bullets_pat, re.U) 1.20 + self.list_re = re.compile(self.list_pat, re.U) 1.21 self.block_re = re.compile(ur"|".join("(?P<%s>%s)" % kv 1.22 for kv in sorted(self.block.iteritems()))) 1.23 self.code_close_re = re.compile(ur"^\}\}\}\s*$", re.U) 1.24 @@ -1035,6 +1038,29 @@ 1.25 in_ul = False 1.26 yield '</li></ul>'*level 1.27 1.28 + def _block_list(self, block): 1.29 + level = 0 1.30 + in_ol = False 1.31 + for self.line_no, line in block: 1.32 + nest = len(self.list_re.match(line).group(0).strip()) 1.33 + while nest > level: 1.34 + if in_ol: 1.35 + yield '<ol>' 1.36 + yield '<ol id="line_%d">' % self.line_no 1.37 + in_ol = True 1.38 + level += 1 1.39 + while nest < level: 1.40 + yield '</li></ol>' 1.41 + in_ol = False 1.42 + level -= 1 1.43 + if nest == level and not in_ol: 1.44 + yield '</li>' 1.45 + content = line.lstrip().lstrip('#').strip() 1.46 + yield '<li>%s%s' % (u"".join(self.parse_line(content)), 1.47 + self.pop_to("")) 1.48 + in_ol = False 1.49 + yield '</li></ol>'*level 1.50 + 1.51 def _block_quote(self, block): 1.52 level = 0 1.53 in_p = False
