Hatta Devel
changeset 646:f2bf456191d9
add priorities to mablock rules, back to dict, allow disabling indentation
| author | sheep@ghostwheel |
|---|---|
| date | Tue Dec 15 20:56:30 2009 +0100 (2009-12-15) |
| parents | cb8af576f8aa |
| children | 7bcdbb517c4a |
| files | hatta.py |
line diff
1.1 --- a/hatta.py Tue Dec 15 20:48:19 2009 +0100 1.2 +++ b/hatta.py Tue Dec 15 20:56:30 2009 +0100 1.3 @@ -179,6 +179,8 @@ 1.4 help='Enable hgweb access to the repository', action="store_true") 1.5 add('-W', '--wiki-words', dest='wiki_words', default=False, 1.6 help='Enable WikiWord links', action="store_true") 1.7 + add('-I', '--ignore-indent', dest='ignore_indent', default=False, 1.8 + help='Treat indented lines as normal text', action="store_true") 1.9 1.10 options, args = parser.parse_args() 1.11 for option, value in options.__dict__.iteritems(): 1.12 @@ -655,19 +657,20 @@ 1.13 bullets_pat = ur"^\s*[*]+\s+" 1.14 heading_pat = ur"^\s*=+" 1.15 quote_pat = ur"^[>]+\s+" 1.16 - block = [ 1.17 - ("bullets", bullets_pat), 1.18 - ("code", ur"^[{][{][{]+\s*$"), 1.19 - ("conflict", ur"^<<<<<<< local\s*$"), 1.20 - ("empty", ur"^\s*$"), 1.21 - ("heading", heading_pat), 1.22 - ("indent", ur"^[ \t]+"), 1.23 - ("macro", ur"^<<\w+\s*$"), 1.24 - ("quote", quote_pat), 1.25 - ("rule", ur"^\s*---+\s*$"), 1.26 - ("syntax", ur"^\{\{\{\#![\w+#.-]+\s*$"), 1.27 - ("table", ur"^\|"), 1.28 - ] 1.29 + block = { 1.30 + # "name": (priority, ur"pattern"), 1.31 + "bullets": (10, bullets_pat), 1.32 + "code": (20, ur"^[{][{][{]+\s*$"), 1.33 + "conflict": (30, ur"^<<<<<<< local\s*$"), 1.34 + "empty": (40, ur"^\s*$"), 1.35 + "heading": (50, heading_pat), 1.36 + "indent": (60, ur"^[ \t]+"), 1.37 + "macro":(70, ur"^<<\w+\s*$"), 1.38 + "quote": (80, quote_pat), 1.39 + "rule": (90, ur"^\s*---+\s*$"), 1.40 + "syntax": (100, ur"^\{\{\{\#![\w+#.-]+\s*$"), 1.41 + "table": (110, ur"^\|"), 1.42 + } 1.43 image_pat = (ur"\{\{(?P<image_target>([^|}]|}[^|}])*)" 1.44 ur"(\|(?P<image_text>([^}]|}[^}])*))?}}") 1.45 smilies = { 1.46 @@ -736,8 +739,10 @@ 1.47 self.quote_re = re.compile(self.quote_pat, re.U) 1.48 self.heading_re = re.compile(self.heading_pat, re.U) 1.49 self.bullets_re = re.compile(self.bullets_pat, re.U) 1.50 - self.block_re = re.compile(ur"|".join("(?P<%s>%s)" % kv 1.51 - for kv in self.block), re.U) 1.52 + patterns = ((k, p) for (k, (x, p)) in 1.53 + sorted(self.block.iteritems(), key=lambda x: x[1][0])) 1.54 + self.block_re = re.compile(ur"|".join("(?P<%s>%s)" % pat 1.55 + for pat in patterns), re.U) 1.56 self.code_close_re = re.compile(ur"^\}\}\}\s*$", re.U) 1.57 self.macro_close_re = re.compile(ur"^>>\s*$", re.U) 1.58 self.conflict_close_re = re.compile(ur"^>>>>>>> other\s*$", re.U) 1.59 @@ -2009,6 +2014,11 @@ 1.60 self.parser = WikiWikiParser 1.61 else: 1.62 self.parser = WikiParser 1.63 + if self.config.get_bool('ignore_indent', False): 1.64 + try: 1.65 + del self.parser.block['indent'] 1.66 + except KeyError: 1.67 + pass 1.68 1.69 def extract_links(self, text=None): 1.70 """Extract all links from the page."""
