# HG changeset patch # User Martin Geisler # Date 1271923493 -7200 # Node ID 0a2c6948f5f4607826411bfcc7043ef69a0de194 # Parent cbe400a8e2179963299acc11bf85c0e59e9b0f33 doc, minirst: support hg interpreted text role diff -r cbe400a8e217 -r 0a2c6948f5f4 doc/runrst --- a/doc/runrst Thu Apr 22 09:57:04 2010 +0200 +++ b/doc/runrst Thu Apr 22 10:04:53 2010 +0200 @@ -13,7 +13,16 @@ """ import sys +from docutils.parsers.rst import roles from docutils.core import publish_cmdline +from docutils import nodes, utils + +def role_hg(name, rawtext, text, lineno, inliner, + options={}, content=[]): + node = nodes.literal(rawtext, "hg " + utils.unescape(text, True)) + return [node], [] + +roles.register_local_role("hg", role_hg) if __name__ == "__main__": if len(sys.argv) < 2: diff -r cbe400a8e217 -r 0a2c6948f5f4 mercurial/minirst.py --- a/mercurial/minirst.py Thu Apr 22 09:57:04 2010 +0200 +++ b/mercurial/minirst.py Thu Apr 22 10:04:53 2010 +0200 @@ -252,6 +252,15 @@ return blocks +_hgrolere = re.compile(r':hg:`([^`]+)`') + +def hgrole(blocks): + for b in blocks: + if b['type'] == 'paragraph': + b['lines'] = [_hgrolere.sub(r'"hg \1"', l) for l in b['lines']] + return blocks + + def addmargins(blocks): """Adds empty blocks for vertical spacing. @@ -333,6 +342,7 @@ blocks = findliteralblocks(blocks) blocks, pruned = prunecontainers(blocks, keep or []) blocks = inlineliterals(blocks) + blocks = hgrole(blocks) blocks = splitparagraphs(blocks) blocks = updatefieldlists(blocks) blocks = findsections(blocks) diff -r cbe400a8e217 -r 0a2c6948f5f4 tests/test-minirst.py --- a/tests/test-minirst.py Thu Apr 22 09:57:04 2010 +0200 +++ b/tests/test-minirst.py Thu Apr 22 10:04:53 2010 +0200 @@ -178,3 +178,6 @@ debugformat('containers (debug)', containers, 60, keep=['debug']) debugformat('containers (verbose debug)', containers, 60, keep=['verbose', 'debug']) + +roles = """Please see :hg:`add`.""" +debugformat('roles', roles, 60) diff -r cbe400a8e217 -r 0a2c6948f5f4 tests/test-minirst.py.out --- a/tests/test-minirst.py.out Thu Apr 22 09:57:04 2010 +0200 +++ b/tests/test-minirst.py.out Thu Apr 22 10:04:53 2010 +0200 @@ -298,3 +298,8 @@ [] ---------------------------------------------------------------------- +roles formatted to fit within 60 characters: +---------------------------------------------------------------------- +Please see "hg add". +---------------------------------------------------------------------- +