Mercurial > hg-stable
comparison mercurial/minirst.py @ 10282:08a0f04b56bd
many, many trivial check-code fixups
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 25 Jan 2010 00:05:27 -0600 |
parents | d6512b3e9ac0 |
children | 62d484a81dfe |
comparison
equal
deleted
inserted
replaced
10281:e7d3b509af8b | 10282:08a0f04b56bd |
---|---|
76 # +------------------------------+ | 76 # +------------------------------+ |
77 # +---------------------------+ | 77 # +---------------------------+ |
78 # | indented literal block | | 78 # | indented literal block | |
79 # +---------------------------+ | 79 # +---------------------------+ |
80 blocks[i]['type'] = 'paragraph' | 80 blocks[i]['type'] = 'paragraph' |
81 if blocks[i]['lines'][-1].endswith('::') and i+1 < len(blocks): | 81 if blocks[i]['lines'][-1].endswith('::') and i + 1 < len(blocks): |
82 indent = blocks[i]['indent'] | 82 indent = blocks[i]['indent'] |
83 adjustment = blocks[i+1]['indent'] - indent | 83 adjustment = blocks[i + 1]['indent'] - indent |
84 | 84 |
85 if blocks[i]['lines'] == ['::']: | 85 if blocks[i]['lines'] == ['::']: |
86 # Expanded form: remove block | 86 # Expanded form: remove block |
87 del blocks[i] | 87 del blocks[i] |
88 i -= 1 | 88 i -= 1 |
102 if m: | 102 if m: |
103 indent += m.end() | 103 indent += m.end() |
104 adjustment -= m.end() | 104 adjustment -= m.end() |
105 | 105 |
106 # Mark the following indented blocks. | 106 # Mark the following indented blocks. |
107 while i+1 < len(blocks) and blocks[i+1]['indent'] > indent: | 107 while i + 1 < len(blocks) and blocks[i + 1]['indent'] > indent: |
108 blocks[i+1]['type'] = 'literal' | 108 blocks[i + 1]['type'] = 'literal' |
109 blocks[i+1]['indent'] -= adjustment | 109 blocks[i + 1]['indent'] -= adjustment |
110 i += 1 | 110 i += 1 |
111 i += 1 | 111 i += 1 |
112 return blocks | 112 return blocks |
113 | 113 |
114 _bulletre = re.compile(r'(-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)) ') | 114 _bulletre = re.compile(r'(-|[0-9A-Za-z]+\.|\(?[0-9A-Za-z]+\)) ') |
131 | 131 |
132 A list item can be followed by an idented line or another list | 132 A list item can be followed by an idented line or another list |
133 item (but only if singleline is True). | 133 item (but only if singleline is True). |
134 """ | 134 """ |
135 line1 = lines[i] | 135 line1 = lines[i] |
136 line2 = i+1 < len(lines) and lines[i+1] or '' | 136 line2 = i + 1 < len(lines) and lines[i + 1] or '' |
137 if not itemre.match(line1): | 137 if not itemre.match(line1): |
138 return False | 138 return False |
139 if singleline: | 139 if singleline: |
140 return line2 == '' or line2[0] == ' ' or itemre.match(line2) | 140 return line2 == '' or line2[0] == ' ' or itemre.match(line2) |
141 else: | 141 else: |
151 for j, line in enumerate(lines): | 151 for j, line in enumerate(lines): |
152 if match(lines, j, itemre, singleline): | 152 if match(lines, j, itemre, singleline): |
153 items.append(dict(type=type, lines=[], | 153 items.append(dict(type=type, lines=[], |
154 indent=blocks[i]['indent'])) | 154 indent=blocks[i]['indent'])) |
155 items[-1]['lines'].append(line) | 155 items[-1]['lines'].append(line) |
156 blocks[i:i+1] = items | 156 blocks[i:i + 1] = items |
157 break | 157 break |
158 i += 1 | 158 i += 1 |
159 return blocks | 159 return blocks |
160 | 160 |
161 | 161 |
219 This groups bullets, options, and definitions together with no vertical | 219 This groups bullets, options, and definitions together with no vertical |
220 space between them, and adds an empty block between all other blocks. | 220 space between them, and adds an empty block between all other blocks. |
221 """ | 221 """ |
222 i = 1 | 222 i = 1 |
223 while i < len(blocks): | 223 while i < len(blocks): |
224 if (blocks[i]['type'] == blocks[i-1]['type'] and | 224 if (blocks[i]['type'] == blocks[i - 1]['type'] and |
225 blocks[i]['type'] in ('bullet', 'option', 'field', 'definition')): | 225 blocks[i]['type'] in ('bullet', 'option', 'field', 'definition')): |
226 i += 1 | 226 i += 1 |
227 else: | 227 else: |
228 blocks.insert(i, dict(lines=[''], indent=0, type='margin')) | 228 blocks.insert(i, dict(lines=[''], indent=0, type='margin')) |
229 i += 2 | 229 i += 2 |