From 0fa2aff26753a2c993f246b83f56576fabe189c5 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 31 Aug 2020 21:25:54 -0700 Subject: [PATCH] Add block parser for ^-$ that splits otherwise same tags. This can be used to separate two blockquotes, code blocks, etc by forcing the close of the previous tag and beginning of a new one. --- voussoir.net/writing/vmarkdown.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/voussoir.net/writing/vmarkdown.py b/voussoir.net/writing/vmarkdown.py index 1bb37d7..172bb44 100644 --- a/voussoir.net/writing/vmarkdown.py +++ b/voussoir.net/writing/vmarkdown.py @@ -113,7 +113,7 @@ class VoussoirRenderer( ): pass -class VoussoirGrammar(mistune.InlineGrammar): +class VoussoirInlineGrammar(mistune.InlineGrammar): larr = re.compile(r'<--') rarr = re.compile(r'-->') mdash = re.compile(r'--') @@ -129,7 +129,7 @@ class VoussoirGrammar(mistune.InlineGrammar): # time we make a new rule. My additions so far are \- and \^. text = re.compile(r'^[\s\S]+?(?=[\\{m.group(0)}' +class VoussoirBlockGrammar(mistune.BlockGrammar): + dash_spacer = re.compile(r'^-$', re.MULTILINE) + +class VoussoirBlock(mistune.BlockLexer): + default_rules = copy.copy(mistune.BlockLexer.default_rules) + default_rules.insert(0, 'dash_spacer') + + def __init__(self, **kwargs): + rules = VoussoirBlockGrammar() + print(help(super().__init__)) + super().__init__(rules, **kwargs) + + def parse_dash_spacer(self, m): + return '' + footnote_link_index = 1 footnote_text_index = 1 renderer = VoussoirRenderer() -inline = VoussoirLexer(renderer) -VMARKDOWN = mistune.Markdown(renderer=renderer, inline=inline) +inline = VoussoirInline(renderer) +block = VoussoirBlock() +VMARKDOWN = mistune.Markdown(renderer=renderer, inline=inline, block=block) # GENERIC HELPERS ################################################################################