mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 15:57:43 +03:00
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.
This commit is contained in:
parent
006ef6abfb
commit
178fc087aa
@ -425,12 +425,14 @@ _admonitions = set([
|
|||||||
'warning',
|
'warning',
|
||||||
])
|
])
|
||||||
|
|
||||||
def findadmonitions(blocks):
|
def findadmonitions(blocks, admonitions=None):
|
||||||
"""
|
"""
|
||||||
Makes the type of the block an admonition block if
|
Makes the type of the block an admonition block if
|
||||||
the first line is an admonition directive
|
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)
|
flags=re.IGNORECASE)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
@ -642,7 +644,7 @@ def formathtml(blocks):
|
|||||||
|
|
||||||
return ''.join(out)
|
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"""
|
"""Parse text into a list of blocks"""
|
||||||
pruned = []
|
pruned = []
|
||||||
blocks = findblocks(text)
|
blocks = findblocks(text)
|
||||||
@ -657,7 +659,7 @@ def parse(text, indent=0, keep=None):
|
|||||||
blocks = splitparagraphs(blocks)
|
blocks = splitparagraphs(blocks)
|
||||||
blocks = updatefieldlists(blocks)
|
blocks = updatefieldlists(blocks)
|
||||||
blocks = updateoptionlists(blocks)
|
blocks = updateoptionlists(blocks)
|
||||||
blocks = findadmonitions(blocks)
|
blocks = findadmonitions(blocks, admonitions=admonitions)
|
||||||
blocks = addmargins(blocks)
|
blocks = addmargins(blocks)
|
||||||
blocks = prunecomments(blocks)
|
blocks = prunecomments(blocks)
|
||||||
return blocks, pruned
|
return blocks, pruned
|
||||||
|
Loading…
Reference in New Issue
Block a user