1""" 2Sane List Extension for Python-Markdown 3======================================= 4 5Modify the behavior of Lists in Python-Markdown to act in a sane manor. 6 7See <https://Python-Markdown.github.io/extensions/sane_lists> 8for documentation. 9 10Original code Copyright 2011 [Waylan Limberg](http://achinghead.com) 11 12All changes Copyright 2011-2014 The Python Markdown Project 13 14License: [BSD](https://opensource.org/licenses/bsd-license.php) 15 16""" 17 18from . import Extension 19from ..blockprocessors import OListProcessor, UListProcessor 20import re 21 22 23class SaneOListProcessor(OListProcessor): 24 25 SIBLING_TAGS = ['ol'] 26 LAZY_OL = False 27 28 def __init__(self, parser): 29 super().__init__(parser) 30 self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.))[ ]+(.*)' % 31 (self.tab_length - 1)) 32 33 34class SaneUListProcessor(UListProcessor): 35 36 SIBLING_TAGS = ['ul'] 37 38 def __init__(self, parser): 39 super().__init__(parser) 40 self.CHILD_RE = re.compile(r'^[ ]{0,%d}(([*+-]))[ ]+(.*)' % 41 (self.tab_length - 1)) 42 43 44class SaneListExtension(Extension): 45 """ Add sane lists to Markdown. """ 46 47 def extendMarkdown(self, md): 48 """ Override existing Processors. """ 49 md.parser.blockprocessors.register(SaneOListProcessor(md.parser), 'olist', 40) 50 md.parser.blockprocessors.register(SaneUListProcessor(md.parser), 'ulist', 30) 51 52 53def makeExtension(**kwargs): # pragma: no cover 54 return SaneListExtension(**kwargs) 55