Repository URL to install this package:
|
Version:
2.6.6 ▾
|
Markdown
/
blockprocessors.pyc
|
|---|
ó
ÂöWc @` s| d Z d d l m Z d d l m Z d d l m Z d d l Z d d l Z d d l m Z d d l m
Z
e j d Z d
Z
d e f d YZ d
e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d e f d YZ d S(! uë
CORE MARKDOWN BLOCKPARSER
===========================================================================
This parser handles basic parsing of Markdown blocks. It doesn't concern
itself with inline elements such as **bold** or *italics*, but rather just
catches blocks, lists, quotes, etc.
The BlockParser is made up of a bunch of BlockProssors, each handling a
different type of block. Extensions may add/replace/remove BlockProcessors
as they need to alter how markdown blocks are parsed.
i ( t absolute_import( t division( t unicode_literalsNi ( t util( t BlockParseru MARKDOWNc K` sÎ t | } t | | j d <t | | j d <t | | j d <t | | j d <t | | j d <t | | j d <t | | j d <t | | j d <t
| | j d <t | | j d
<| S( u2 Build the default block parser used by Markdown. u emptyu indentu codeu
hashheaderu setextheaderu hru olistu ulistu quoteu paragraph( R t EmptyBlockProcessort blockprocessorst ListIndentProcessort CodeBlockProcessort HashHeaderProcessort SetextHeaderProcessort HRProcessort OListProcessort UListProcessort BlockQuoteProcessort ParagraphProcessor( t md_instancet kwargst parser( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt build_block_parser s t BlockProcessorc B` sG e Z d Z d Z d Z d Z d d Z d Z d Z RS( u Base class for block processors.
Each subclass will provide the methods below to work with the source and
tree. Each processor will need to define it's own ``test`` and ``run``
methods. The ``test`` method should return True or False, to indicate
whether the current block should be processed by this processor. If the
test passes, the parser will call the processors ``run`` method.
c C` s | | _ | j j | _ d S( N( R t markdownt
tab_length( t selfR ( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt __init__4 s c C` s t | r | d Sd Sd S( u, Return the last child of an etree element. iÿÿÿÿN( t lent None( R t parent( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt lastChild8 s c C` s g } | j d } xX | D]P } | j d | j rO | j | | j q | j sk | j d q Pq Wd j | d j | t | f S( u= Remove a tab from the front of each line of the given text. u
u u ( t splitt
startswithR t appendt stript joinR ( R t textt newtextt linest line( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt detab? s
i c C` ss | j d } xT t t | D]@ } | | j d | j | r" | | | j | | | <q" q" Wd j | S( u? Remove a tab from front of lines but allowing dedented lines. u
u ( R t rangeR R R R! ( R R" t levelR$ t i( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt
looseDetabL s
c C` s d S( ue Test for block type. Must be overridden by subclasses.
As the parser loops through processors, it will call the ``test``
method on each to determine if the given block of text is of that
type. This method must return a boolean ``True`` or ``False``. The
actual method of testing is left to the needs of that particular
block type. It could be as simple as ``block.startswith(some_string)``
or a complex regular expression. As the block type may be different
depending on the parent of the block (i.e. inside a list), the parent
etree element is also provided and may be used as part of the test.
Keywords:
* ``parent``: A etree element which will be the parent of the block.
* ``block``: A block of text from the source which has been split at
blank lines.
N( ( R R t block( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt testT s c C` s d S( u½ Run processor. Must be overridden by subclasses.
When the parser determines the appropriate type of a block, the parser
will call the corresponding processor's ``run`` method. This method
should parse the individual lines of the block and append them to
the etree.
Note that both the ``parent`` and ``etree`` keywords are pointers
to instances of the objects which should be edited in place. Each
processor must make changes to the existing objects as there is no
mechanism to return new/different objects to replace them.
This means that this method should be adding SubElements or adding text
to the parent, and should remove (``pop``) or add (``insert``) items to
the list of blocks.
Keywords:
* ``parent``: A etree element which is the parent of the current block.
* ``blocks``: A list of all remaining blocks of the document.
N( ( R R t blocks( ( s6 build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt runh s ( t __name__t
__module__t __doc__R R R&