OLD | NEW |
(Empty) | |
| 1 """ |
| 2 Sane List Extension for Python-Markdown |
| 3 ======================================= |
| 4 |
| 5 Modify the behavior of Lists in Python-Markdown t act in a sane manor. |
| 6 |
| 7 In standard Markdown sytex, the following would constitute a single |
| 8 ordered list. However, with this extension, the output would include |
| 9 two lists, the first an ordered list and the second and unordered list. |
| 10 |
| 11 1. ordered |
| 12 2. list |
| 13 |
| 14 * unordered |
| 15 * list |
| 16 |
| 17 Copyright 2011 - [Waylan Limberg](http://achinghead.com) |
| 18 |
| 19 """ |
| 20 |
| 21 from __future__ import absolute_import |
| 22 from __future__ import unicode_literals |
| 23 from . import Extension |
| 24 from ..blockprocessors import OListProcessor, UListProcessor |
| 25 import re |
| 26 |
| 27 |
| 28 class SaneOListProcessor(OListProcessor): |
| 29 |
| 30 CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.))[ ]+(.*)') |
| 31 SIBLING_TAGS = ['ol'] |
| 32 |
| 33 |
| 34 class SaneUListProcessor(UListProcessor): |
| 35 |
| 36 CHILD_RE = re.compile(r'^[ ]{0,3}(([*+-]))[ ]+(.*)') |
| 37 SIBLING_TAGS = ['ul'] |
| 38 |
| 39 |
| 40 class SaneListExtension(Extension): |
| 41 """ Add sane lists to Markdown. """ |
| 42 |
| 43 def extendMarkdown(self, md, md_globals): |
| 44 """ Override existing Processors. """ |
| 45 md.parser.blockprocessors['olist'] = SaneOListProcessor(md.parser) |
| 46 md.parser.blockprocessors['ulist'] = SaneUListProcessor(md.parser) |
| 47 |
| 48 |
| 49 def makeExtension(configs={}): |
| 50 return SaneListExtension(configs=configs) |
| 51 |
OLD | NEW |