# HG changeset patch # User Gregory Szorc <gregory.sz...@gmail.com> # Date 1487188152 28800 # Wed Feb 15 11:49:12 2017 -0800 # Node ID 9ab3ad4934aedc649d28f74dd70207c6c6e88596 # Parent 197ba3e5885366038d453b9b22fa2910a0792988 minirst: support passing admonitions into findadmonitions() and parse()
This will allow consumers to declare a custom list of admonitions to parse. Without this patch, custom admonitions would get removed when prunecomments() is run. We could add an argument controlling whether prunecomments() is run. However, it is better to convert the "paragraph" block to an "admonition" block so consumers don't have to parse for custom admonitions. diff --git a/mercurial/minirst.py b/mercurial/minirst.py --- a/mercurial/minirst.py +++ b/mercurial/minirst.py @@ -425,12 +425,14 @@ def prunecomments(blocks): 'warning', ]) -def findadmonitions(blocks): +def findadmonitions(blocks, admonitions=None): """ Makes the type of the block an admonition block if the first line is an admonition directive """ - admonitionre = re.compile(r'\.\. (%s)::' % '|'.join(sorted(_admonitions)), + admonitions = admonitions or _admonitions + + admonitionre = re.compile(r'\.\. (%s)::' % '|'.join(sorted(admonitions)), flags=re.IGNORECASE) i = 0 @@ -642,7 +644,7 @@ def formathtml(blocks): return ''.join(out) -def parse(text, indent=0, keep=None): +def parse(text, indent=0, keep=None, admonitions=None): """Parse text into a list of blocks""" pruned = [] blocks = findblocks(text) @@ -657,7 +659,7 @@ def parse(text, indent=0, keep=None): blocks = splitparagraphs(blocks) blocks = updatefieldlists(blocks) blocks = updateoptionlists(blocks) - blocks = findadmonitions(blocks) + blocks = findadmonitions(blocks, admonitions=admonitions) blocks = addmargins(blocks) blocks = prunecomments(blocks) return blocks, pruned _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel