Completed
Push — master ( 32cfa8...ec62d3 )
by Dongxin
48s
created

SaneListExtension   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 10
wmc 1

1 Method

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