OLD | NEW |
(Empty) | |
| 1 # markdown is released under the BSD license |
| 2 # Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later) |
| 3 # Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b) |
| 4 # Copyright 2004 Manfred Stienstra (the original version) |
| 5 # |
| 6 # All rights reserved. |
| 7 # |
| 8 # Redistribution and use in source and binary forms, with or without |
| 9 # modification, are permitted provided that the following conditions are met: |
| 10 # |
| 11 # * Redistributions of source code must retain the above copyright |
| 12 # notice, this list of conditions and the following disclaimer. |
| 13 # * Redistributions in binary form must reproduce the above copyright |
| 14 # notice, this list of conditions and the following disclaimer in the |
| 15 # documentation and/or other materials provided with the distribution. |
| 16 # * Neither the name of the <organization> nor the |
| 17 # names of its contributors may be used to endorse or promote products |
| 18 # derived from this software without specific prior written permission. |
| 19 # |
| 20 # THIS SOFTWARE IS PROVIDED BY THE PYTHON MARKDOWN PROJECT ''AS IS'' AND ANY |
| 21 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 23 # DISCLAIMED. IN NO EVENT SHALL ANY CONTRIBUTORS TO THE PYTHON MARKDOWN PROJECT |
| 24 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 # POSSIBILITY OF SUCH DAMAGE. |
| 31 |
| 32 |
| 33 """ |
| 34 Sane List Extension for Python-Markdown |
| 35 ======================================= |
| 36 |
| 37 Modify the behavior of Lists in Python-Markdown t act in a sane manor. |
| 38 |
| 39 In standard Markdown sytex, the following would constitute a single |
| 40 ordered list. However, with this extension, the output would include |
| 41 two lists, the first an ordered list and the second and unordered list. |
| 42 |
| 43 1. ordered |
| 44 2. list |
| 45 |
| 46 * unordered |
| 47 * list |
| 48 |
| 49 Copyright 2011 - [Waylan Limberg](http://achinghead.com) |
| 50 |
| 51 """ |
| 52 |
| 53 from __future__ import absolute_import |
| 54 from __future__ import unicode_literals |
| 55 from . import Extension |
| 56 from ..blockprocessors import OListProcessor, UListProcessor |
| 57 import re |
| 58 |
| 59 |
| 60 class SaneOListProcessor(OListProcessor): |
| 61 |
| 62 CHILD_RE = re.compile(r'^[ ]{0,3}((\d+\.))[ ]+(.*)') |
| 63 SIBLING_TAGS = ['ol'] |
| 64 |
| 65 |
| 66 class SaneUListProcessor(UListProcessor): |
| 67 |
| 68 CHILD_RE = re.compile(r'^[ ]{0,3}(([*+-]))[ ]+(.*)') |
| 69 SIBLING_TAGS = ['ul'] |
| 70 |
| 71 |
| 72 class SaneListExtension(Extension): |
| 73 """ Add sane lists to Markdown. """ |
| 74 |
| 75 def extendMarkdown(self, md, md_globals): |
| 76 """ Override existing Processors. """ |
| 77 md.parser.blockprocessors['olist'] = SaneOListProcessor(md.parser) |
| 78 md.parser.blockprocessors['ulist'] = SaneUListProcessor(md.parser) |
| 79 |
| 80 |
| 81 def makeExtension(configs={}): |
| 82 return SaneListExtension(configs=configs) |
| 83 |
OLD | NEW |