##// END OF EJS Templates
minirst: report pruned container types
Martin Geisler -
r10444:e99e0e07 default
parent child Browse files
Show More
@@ -192,6 +192,7 b' def prunecontainers(blocks, keep):'
192 The blocks must have a 'type' field, i.e., they should have been
192 The blocks must have a 'type' field, i.e., they should have been
193 run through findliteralblocks first.
193 run through findliteralblocks first.
194 """
194 """
195 pruned = []
195 i = 0
196 i = 0
196 while i + 1 < len(blocks):
197 while i + 1 < len(blocks):
197 # Searching for a block that looks like this:
198 # Searching for a block that looks like this:
@@ -207,6 +208,8 b' def prunecontainers(blocks, keep):'
207 adjustment = blocks[i + 1]['indent'] - indent
208 adjustment = blocks[i + 1]['indent'] - indent
208 containertype = blocks[i]['lines'][0][15:]
209 containertype = blocks[i]['lines'][0][15:]
209 prune = containertype not in keep
210 prune = containertype not in keep
211 if prune:
212 pruned.append(containertype)
210
213
211 # Always delete "..container:: type" block
214 # Always delete "..container:: type" block
212 del blocks[i]
215 del blocks[i]
@@ -219,7 +222,7 b' def prunecontainers(blocks, keep):'
219 blocks[j]['indent'] -= adjustment
222 blocks[j]['indent'] -= adjustment
220 j += 1
223 j += 1
221 i += 1
224 i += 1
222 return blocks
225 return blocks, pruned
223
226
224
227
225 def findsections(blocks):
228 def findsections(blocks):
@@ -317,19 +320,23 b' def formatblock(block, width):'
317 subsequent_indent=subindent)
320 subsequent_indent=subindent)
318
321
319
322
320 def format(text, width, indent=0, keep=[]):
323 def format(text, width, indent=0, keep=None):
321 """Parse and format the text according to width."""
324 """Parse and format the text according to width."""
322 blocks = findblocks(text)
325 blocks = findblocks(text)
323 for b in blocks:
326 for b in blocks:
324 b['indent'] += indent
327 b['indent'] += indent
325 blocks = findliteralblocks(blocks)
328 blocks = findliteralblocks(blocks)
326 blocks = prunecontainers(blocks, keep)
329 blocks, pruned = prunecontainers(blocks, keep or [])
327 blocks = inlineliterals(blocks)
330 blocks = inlineliterals(blocks)
328 blocks = splitparagraphs(blocks)
331 blocks = splitparagraphs(blocks)
329 blocks = updatefieldlists(blocks)
332 blocks = updatefieldlists(blocks)
330 blocks = findsections(blocks)
333 blocks = findsections(blocks)
331 blocks = addmargins(blocks)
334 blocks = addmargins(blocks)
332 return '\n'.join(formatblock(b, width) for b in blocks)
335 text = '\n'.join(formatblock(b, width) for b in blocks)
336 if keep is None:
337 return text
338 else:
339 return text, pruned
333
340
334
341
335 if __name__ == "__main__":
342 if __name__ == "__main__":
@@ -1,11 +1,18 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2
2
3 from pprint import pprint
3 from mercurial import minirst
4 from mercurial import minirst
4
5
5 def debugformat(title, text, width, **kwargs):
6 def debugformat(title, text, width, **kwargs):
6 print "%s formatted to fit within %d characters:" % (title, width)
7 print "%s formatted to fit within %d characters:" % (title, width)
7 print "-" * 70
8 print "-" * 70
8 print minirst.format(text, width, **kwargs)
9 formatted = minirst.format(text, width, **kwargs)
10 if type(formatted) == tuple:
11 print formatted[0]
12 print "-" * 70
13 pprint(formatted[1])
14 else:
15 print formatted
9 print "-" * 70
16 print "-" * 70
10 print
17 print
11
18
@@ -257,6 +257,8 b' Normal output.'
257
257
258 Verbose output.
258 Verbose output.
259 ----------------------------------------------------------------------
259 ----------------------------------------------------------------------
260 ['debug', 'debug']
261 ----------------------------------------------------------------------
260
262
261 containers (debug) formatted to fit within 60 characters:
263 containers (debug) formatted to fit within 60 characters:
262 ----------------------------------------------------------------------
264 ----------------------------------------------------------------------
@@ -264,6 +266,8 b' Normal output.'
264
266
265 Initial debug output.
267 Initial debug output.
266 ----------------------------------------------------------------------
268 ----------------------------------------------------------------------
269 ['verbose']
270 ----------------------------------------------------------------------
267
271
268 containers (verbose debug) formatted to fit within 60 characters:
272 containers (verbose debug) formatted to fit within 60 characters:
269 ----------------------------------------------------------------------
273 ----------------------------------------------------------------------
@@ -275,4 +279,6 b' Verbose output.'
275
279
276 Debug output.
280 Debug output.
277 ----------------------------------------------------------------------
281 ----------------------------------------------------------------------
282 []
283 ----------------------------------------------------------------------
278
284
General Comments 0
You need to be logged in to leave comments. Login now