[PATCH 3 of 3] help: support 'hg help topic:section' (issue2804)

Martin Geisler mg at lazybytes.net
Mon May 30 04:31:22 CDT 2011


Yun Lee <yun.lee.bj at gmail.com> writes:

Hi Yun Lee,

It's starting to look good! I have some comments below.

> # HG changeset patch
> # User Yun Lee <yun.lee.bj at gmail.com>
> # Date 1306583669 -28800
> # Node ID d24e00381f8dfcfa3f371ce0f926ddd0a5fec1b8
> # Parent  cca76ef2ae3333badd5d553a5c12f8bef7797eee
> help: support 'hg help topic:section' (issue2804)

You should expand the commit message to explain how this is done and how
the new help output looks like. Always give examples, we love them :-)

> diff -r cca76ef2ae33 -r d24e00381f8d mercurial/commands.py
> --- a/mercurial/commands.py	Sat May 28 19:51:32 2011 +0800
> +++ b/mercurial/commands.py	Sat May 28 19:54:29 2011 +0800
> @@ -2711,8 +2711,59 @@
>              addglobalopts(True)
>  
>      def helptopic(name):
> +        def fetchsectionblocks(text, sectionname, indent):
> +            blocks = minirst.findblocks(text)
> +            for b in blocks:
> +                b['indent'] += indent
> +            blocks = minirst.findliteralblocks(blocks)
> +            blocks, pruned = minirst.prunecontainers(blocks, [])
> +            blocks = minirst.findsections(blocks)
> +            blocks = minirst.inlineliterals(blocks)
> +            blocks = minirst.hgrole(blocks)
> +            blocks = minirst.splitparagraphs(blocks)
> +            blocks = minirst.updatefieldlists(blocks)
> +            blocks = minirst.updateoptionlists(blocks)
> +            blocks = minirst.addmargins(blocks)
> +            blocks = minirst.prunecomments(blocks)
> +            blocks = minirst.findadmonitions(blocks)

This looks like something that should be internal to minirst. The parse
steps were never intended to be seen outside of minirst.

Please don't just copy-paste code blocks around -- think about how we
can refactor the code instead to avoid the duplication.

> +        def searchsection(text, sectionname, width, indent=0):
> +            sectionblocks = fetchsectionblocks(text, sectionname, indent)
> +
> +            if not sectionblocks:
> +                return (None, None)
> +
> +            firstparagraph = ''.join(sectionblocks[2]['lines'])
> +            header = firstparagraph.split('.')[0]

You'll need to render the first block, it could be a list item even
though it is poor style to start a section with a list.

> +            description = '\n'.join(minirst.formatblock(b, width) \
> +                                    for b in sectionblocks[2:])

It looks like minirst needs a function that will take some blocks and
format them?

-- 
Martin Geisler

Mercurial links: http://mercurial.ch/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20110530/3f644507/attachment.pgp>


More information about the Mercurial-devel mailing list