changeset 31132:bbdd712e9adb

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 15 Feb 2017 11:49:12 -0800
parents 50a49ead4db4
children 23080c03a604
files mercurial/minirst.py
diffstat 1 files changed, 6 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/minirst.py	Wed Feb 15 11:47:14 2017 -0800
+++ b/mercurial/minirst.py	Wed Feb 15 11:49:12 2017 -0800
@@ -425,12 +425,14 @@
     '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 @@
 
     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 @@
     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