Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Markdown / blockprocessors.pyc
Size: Mime:
ó
Âö™Wc@`s|dZddlmZddlmZddlmZddlZddlZddlmZddl	m
Z
ejd	ƒZd
„Z
defd„ƒYZd
efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd „ƒYZdS(!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(tabsolute_import(tdivision(tunicode_literalsNi(tutil(tBlockParseruMARKDOWNcK`sÎt|ƒ}t|ƒ|jd<t|ƒ|jd<t|ƒ|jd<t|ƒ|jd<t|ƒ|jd<t|ƒ|jd<t|ƒ|jd<t	|ƒ|jd<t
|ƒ|jd	<t|ƒ|jd
<|S(u2 Build the default block parser used by Markdown. uemptyuindentucodeu
hashheaderusetextheaderuhruolistuulistuquoteu	paragraph(RtEmptyBlockProcessortblockprocessorstListIndentProcessortCodeBlockProcessortHashHeaderProcessortSetextHeaderProcessortHRProcessortOListProcessortUListProcessortBlockQuoteProcessortParagraphProcessor(tmd_instancetkwargstparser((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pytbuild_block_parserstBlockProcessorcB`sGeZdZd„Zd„Zd„Zdd„Zd„Zd„ZRS(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.

    cC`s||_|jj|_dS(N(Rtmarkdownt
tab_length(tselfR((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt__init__4s	cC`st|ƒr|dSdSdS(u, Return the last child of an etree element. iÿÿÿÿN(tlentNone(Rtparent((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt	lastChild8scC`s–g}|jdƒ}xX|D]P}|jd|jƒrO|j||jƒq|jƒsk|jdƒqPqWdj|ƒdj|t|ƒƒfS(u= Remove a tab from the front of each line of the given text. u
u u(tsplitt
startswithRtappendtstriptjoinR(Rttexttnewtexttlinestline((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pytdetab?s
icC`ss|jdƒ}xTtt|ƒƒD]@}||jd|j|ƒr"|||j|||<q"q"Wdj|ƒS(u? Remove a tab from front of lines but allowing dedented lines. u
u (RtrangeRRRR!(RR"tlevelR$ti((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt
looseDetabLs
 cC`sdS(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((RRtblock((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyttestTscC`sdS(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((RRtblocks((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pytrunhs(	t__name__t
__module__t__doc__RRR&R*R,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR)s				
	RcB`sPeZdZdgZddgZd„Zd„Zd„Zd„Zd„Z	RS(	u‚ Process children of list items.

    Example:
        * a list item
            process this part

            or this part

    uliuuluolcG`s3tt|ƒj|Œtjd|jƒ|_dS(Nu
^(([ ]{%s})+)(tsuperRRtretcompileRt	INDENT_RE(Rtargs((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRscC`sn|jd|jƒom|jjjdƒom|j|jkpmt|ƒom|ddk	om|dj|j	kS(Nu udetabbediÿÿÿÿ(
RRRtstatetisstatettagt
ITEM_TYPESRRt
LIST_TYPES(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,“s
cC`s”|jdƒ}|j||ƒ\}}|j||ƒ}|jjjdƒ|j|jkr¶t|ƒr|dj|j	kr|jj
|d|gƒq€|jj
||gƒnÊ|j|jkrá|jj
||gƒnŸt|ƒrp|dj|jkrp|djrVtj
jdƒ}|dj|_d|d_|djd|ƒn|jj|d|ƒn|j||ƒ|jjjƒdS(Niudetabbediÿÿÿÿupu(tpopt	get_levelR*RR7tsetR9R:RR;tparseBlocksR"RtetreetElementtinsertt
parseChunktcreate_itemtreset(RRR-R+R(tsiblingtp((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.šs&""

cC`s/tjj|dƒ}|jj||gƒdS(u< Create a new li and parse the block with it as the parent. uliN(RR@t
SubElementRR?(RRR+tli((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRD¾scC`sæ|jj|ƒ}|r7t|jdƒƒ|j}nd}|jjjdƒr[d}nd}xx||krÛ|j|ƒ}|dk	r×|j
|jks¯|j
|jkr×|j
|jkrÎ|d7}n|}qdPqdW||fS(u* Get level of indent based on list level. iiulistN(
R5tmatchRtgroupRRR7R8RRR9R;R:(RRR+tmtindent_levelR(tchild((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR=Ãs 	$
	(
R/R0R1R:R;RR,R.RDR=(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRs					$	RcB`s eZdZd„Zd„ZRS(u Process code blocks. cC`s|jd|jƒS(Nu (RR(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,ãscC`s|j|ƒ}|jdƒ}d}|dk	r¥|jdkr¥t|ƒr¥|djdkr¥|d}|j|ƒ\}}tjd|j|j	ƒfƒ|_n[tj
j|dƒ}tj
j|dƒ}|j|ƒ\}}tjd|j	ƒƒ|_|r|jd|ƒndS(Niuupreucodeu%s
%s
u%s
(
RR<RR9RR&RtAtomicStringR"trstripR@RHRB(RRR-RFR+ttheResttcodetpre((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.æs
"(R/R0R1R,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRàs	RcB`s2eZejdƒZd„Zd„Zd„ZRS(u(^|\n)[ ]{0,3}>[ ]?(.*)cC`st|jj|ƒƒS(N(tbooltREtsearch(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,sc	C`s|jdƒ}|jj|ƒ}|rŽ||jƒ }|jj||gƒdjg||jƒjdƒD]}|j|ƒ^qmƒ}n|j	|ƒ}|dk	rÁ|jdkrÁ|}ntj
j|dƒ}|jjjdƒ|jj||ƒ|jjjƒdS(Niu
u
blockquote(R<RURVtstartRR?R!RtcleanRRR9RR@RHR7R>RCRE(	RRR-R+RLtbeforeR%RFtquote((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.s;	cC`sC|jj|ƒ}|jƒdkr(dS|r;|jdƒS|SdS(u( Remove ``>`` from beginning of a line. u>uiN(RURJR RK(RR%RL((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRX s
(R/R0R3R4RUR,R.RX(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRs		RcB`sJeZdZdZdZddgZd„Zd„Zd„Zd„Z	RS(u Process ordered list blocks. uolu1uulcC`s~tt|ƒj|ƒtjd|jdƒ|_tjd|jdƒ|_tjd|j|jddfƒ|_dS(Nu^[ ]{0,%d}\d+\.[ ]+(.*)iu!^[ ]{0,%d}((\d+\.)|[*+-])[ ]+(.*)u ^[ ]{%d,%d}((\d+\.)|[*+-])[ ]+.*i(	R2RRR3R4RRUtCHILD_RER5(RR((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR7s		cC`st|jj|ƒƒS(N(RTRURJ(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,BscC`sU|j|jdƒƒ}|j|ƒ}|dk	r]|j|jkr]|}|djržtjj	dƒ}|dj|_d|d_|dj
d|ƒn|j|dƒ}|dk	rý|jrýtjj|ddƒ}|jj
ƒ|_d|_ntjj|dƒ}|jjjdƒ|jdƒ}	|jj||	gƒ|jjjƒnb|jd
kru|}nJtjj||jƒ}|jjjr¿|jd	kr¿|j|jd
<n|jjjdƒxl|D]d}
|
jd|jƒr|jj|d|
gƒqÙtjj|dƒ}|jj||
gƒqÙW|jjjƒdS(Niiÿÿÿÿupuuliu	looselistuoluulu1ustartulistu (uoluul(t	get_itemsR<RRR9tSIBLING_TAGSR"RR@RARBttailRHtlstripRR7R>R?REtTAGRtlazy_olt
STARTSWITHtattribRR(RRR-titemsRFtlstRGtlchRIt	firstitemtitem((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.Es>

	
cC`s
g}x|jdƒD]ï}|jj|ƒ}|r–|r}|jdkr}tjdƒ}|j|jdƒƒjƒ|_n|j|jdƒƒq|j	j|ƒrí|dj
d|jƒrÝd|d|f|d<q|j|ƒqd|d|f|d<qW|S(	u  Break a block into list items. u
uolu(\d+)iiiÿÿÿÿu u%s
%s(RR[RJR`R3R4RKRbRR5RR(RR+RdR%RLt
INTEGER_RE((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR\€s$(
R/R0R1R`RbR]RR,R.R\(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR+s			;R
cB`seZdZdZd„ZRS(u  Process unordered list blocks. uulcC`s7tt|ƒj|ƒtjd|jdƒ|_dS(Nu^[ ]{0,%d}[*+-][ ]+(.*)i(R2R
RR3R4RRU(RR((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR s(R/R0R1R`R(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR
›sR	cB`s/eZdZejdƒZd„Zd„ZRS(u Process Hash Headers. u.(^|\n)(?P<level>#{1,6})(?P<header>.*?)#*(\n|$)cC`st|jj|ƒƒS(N(RTRURV(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,¬scC`s×|jdƒ}|jj|ƒ}|rÂ||jƒ }||jƒ}|rf|jj||gƒntjj	|dt
|jdƒƒƒ}|jdƒjƒ|_
|rÓ|jd|ƒqÓntjd|ƒdS(Niuh%duleveluheaderuWe've got a problem header: %r(R<RURVRWtendRR?RR@RHRRKR R"RBtloggertwarn(RRR-R+RLRYtafterth((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.¯s((R/R0R1R3R4RUR,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR	¦s	R
cB`s5eZdZejdejƒZd„Zd„ZRS(u Process Setext-style Headers. u^.*?\n[=-]+[ ]*(\n|$)cC`st|jj|ƒƒS(N(RTRURJ(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,ËscC`sœ|jdƒjdƒ}|djdƒr4d}nd}tjj|d|ƒ}|djƒ|_t|ƒdkr˜|j	ddj
|dƒƒndS(Niu
iu=iuh%d(R<RRRR@RHR R"RRBR!(RRR-R$R(Rn((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.Îs	(	R/R0R1R3R4t	MULTILINERUR,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR
Ås	RcB`s;eZdZdZejeejƒZd„Zd„Z	RS(u Process Horizontal Rules. uB^[ ]{0,3}((-+[ ]{0,2}){3,}|(_+[ ]{0,2}){3,}|(\*+[ ]{0,2}){3,})[ ]*cC`sW|jj|ƒ}|rS|jƒt|ƒksF||jƒdkrS||_tStS(Nu
(t	SEARCH_RERVRjRRJtTruetFalse(RRR+RL((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,ãs
4	cC`s–|jdƒ}||jjƒ jdƒ}|rJ|jj||gƒntjj|dƒ||jj	ƒj
dƒ}|r’|jd|ƒndS(Niu
uhr(R<RJRWRPRR?RR@RHRjR_RB(RRR-R+tprelinest	postlines((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.îs(
R/R0R1RUR3R4RoRpR,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRÜs
	RcB`s eZdZd„Zd„ZRS(u< Process blocks that are empty or start with an empty line. cC`s|p|jdƒS(Nu
(R(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,scC`s¾|jdƒ}d}|rGd}|d}|rG|jd|ƒqGn|j|ƒ}|dk	rº|jdkrºt|ƒrº|djdkrºtjd|dj|fƒ|d_ndS(Niu

u
iupreucodeu%s%s(	R<RBRRR9RRROR"(RRR-R+tfillerRQRF((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.s
(R/R0R1R,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRþs	RcB`s eZdZd„Zd„ZRS(u Process Paragraph blocks. cC`stS(N(Rq(RRR+((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR,scC`sÜ|jdƒ}|jƒrØ|jjjdƒr±|j|ƒ}|dk	r}|jrmd|j|f|_q®d||_qÕ|jrŸd|j|f|_qÕ|j	ƒ|_qØt
jj|dƒ}|j	ƒ|_ndS(Niulistu%s
%su
%sup(
R<R RR7R8RRR^R"R_RR@RH(RRR-R+RFRG((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyR.s			(R/R0R1R,R.(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyRs	(R1t
__future__RRRtloggingR3tRtblockparserRt	getLoggerRkRtobjectRRRRRR
R	R
RRR(((s6build/lib.linux-x86_64-2.7/markdown/blockprocessors.pyt<module>s(	X_!*p"