Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/mercurial/minirst.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
�c@sydZddkZddkZddkZd�Zd�Zd�Zd�Zeid�Z	d�Z
eid	�Zd
�Zd�Z
d�Zd
�Zd�Zedjo�ddklZd�Zeeid�i�Zeee�Zeee�Zeee�Zeee�Zee
e�Zeee�Zee
e�Zeee�Zdid�eD��GHndS(s�simplified reStructuredText parser.

This parser knows just enough about reStructuredText to parse the
Mercurial docstrings.

It cheats in a major way: nested blocks are not really nested. They
are just indented blocks that look like they are nested. This relies
on the user to keep the right indentation for the blocks.

It only supports a small subset of reStructuredText:

- paragraphs

- definition lists (must use '  ' to indent definitions)

- lists (items must start with '-')

- field lists (colons cannot be escaped)

- literal blocks

- option lists (supports only long options without arguments)

- inline markup is not recognized at all.
i�Nc	Cs�gg}|i�}xL|D]D}|i�o|di|�q|do|ig�qqW|dp|d=nxht|�D]Z\}}td�|D��}td|dg}|D]}|||q�~�||<q�W|S(s�Find continuous blocks of lines in text.

    Returns a list of dictionaries representing the blocks. Each block
    has an 'indent' field and a 'lines' field.
    i�css/x(|]!}t|�t|i��VqWdS(N(tlentlstrip(t.0tl((s$/sys/lib/python/mercurial/minirst.pys	<genexpr>6stindenttlines(t
splitlineststriptappendt	enumeratetmintdict(	ttexttblocksRtlinetitblockRt_[1]R((s$/sys/lib/python/mercurial/minirst.pyt
findblocks%s	

<cCs�d}x�|t|�jo�d||d<||ddid�op|dt|�joY||d}||dd|}||ddgjo||=|d8}ne||ddid	�o&||ddd
 ||dd<n#||ddd ||dd<||ddid�o|d7}|d8}nxm|dt|�joQ||dd|jo8d
||dd<||ddc|8<|d7}qIWn|d7}q	W|S(s�Finds literal blocks and adds a 'type' field to the blocks.

    Literal blocks are given the type 'literal', all other blocks are
    given type the 'paragraph'.
    it	paragraphttypeRi�s::iRs ::i�s- itliteral(Rtendswitht
startswith(R
RRt
adjustment((s$/sys/lib/python/mercurial/minirst.pytfindliteralblocks;s*
3&"
3cCsrxk|D]c}|ddjoLt|d�djo5|dddt|dd�jod|d<qqW|S(	s�Finds sections.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    RRRiit-itsection(R(R
R((s$/sys/lib/python/mercurial/minirst.pytfindsectionsns'c
Csd}x�t|�jo�||ddjo�||ddid�o�g}xs||dD]c}|id�o8|itdddgd||d��|d}n|d	di|�qbW||||d
+|t|�d
7}n|d
7}q	W|S(s�Finds bullet lists.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    iRRRs- tbulletRii�i(RRRR(R
RtitemsR((s$/sys/lib/python/mercurial/minirst.pytfindbulletlists�s s-^(--[a-z-]+)((?:[ =][a-zA-Z][\w-]*)?  +)(.*)$c	Cs2d}x%|t|�jo||ddjo�ti||dd�o�g}x�||dD]�}ti|�}|o_|i�\}}}t|�t|�}|itdddgd||dd|��n|ddi|�qbW||||d	+|t|�d	7}n|d	7}q	W|S(
s�Finds option lists.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    iRRRtoptionRtwidthi�i(Rt	_optionretmatchtgroupsRR(	R
RtoptionsRtmR targtrestR!((s$/sys/lib/python/mercurial/minirst.pytfindoptionlists�s&s:(?![: ])([^:]*)(?<! ):( +)(.*)c
CsOd}xB|t|�jo.||ddjoti||dd�o�||d}g}x�||dD]�}ti|�}|on|i�\}}}dt|�t|�}	|itdddgd|d|	��d	|||f}n|d
di|�qpW||||d+|t|�d7}n|d7}q	W|S(s�Finds fields lists.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    iRRRRitfieldR!s%s  %s%si�i(Rt_fieldreR#R$RR(
R
RRtfieldsRR&tkeytspacesR(R!((s$/sys/lib/python/mercurial/minirst.pytfindfieldlists�s(	c
CsWd}xJ|t|�jo6||ddjot||d�djo�|ddid�o�||ddid�o�g}x�||dD]}}|id�p.|itdddgd||d��n|d	di|�t|�t|i��|d	d
<q�W||||d+|t|�d7}n|d7}q	W|S(s�Finds definition lists.

    The blocks must have a 'type' field, i.e., they should have been
    run through findliteralblocks first.
    iRRRis  t
definitionRi�thang(RRRRR(R
RtdefinitionsR((s$/sys/lib/python/mercurial/minirst.pytfinddefinitionlists�s$	(c	Cs�d}x�|t|�joz||d||ddjo#||dd
jo|d7}q	|i|tddgd	d
dd��|d7}q	W|S(s�Adds empty blocks for vertical spacing.

    This groups bullets, options, and definitions together with no vertical
    space between them, and adds an empty block between all other blocks.
    iRRR R*R0RtRitmargini(sbulletsoptionsfields
definition(RtinsertR(R
R((s$/sys/lib/python/mercurial/minirst.pyt
addmarginss!(cCs�d|d}|ddjodSn�|ddjo'|d7}|d|i|d	�SnL|dd
jo|d|i|d	�Sn|ddjot||d	d}||d
d}ditti|d	d��}d|ti|d|d|d|�fSn�|}}ditti|d	��}|ddjo|d}|d}n(|ddjo||dd}nti|d|d|d|�SdS(s"Format a block according to width.t RRR5R4Rs  s
RRR0iR1is%s
%sR!tinitial_indenttsubsequent_indentRs- R R*N(soptionsfield(tjointmaptstrRttextwraptfill(RR!Rttermt	defindentRt
initindentt	subindent((s$/sys/lib/python/mercurial/minirst.pytformatblocks2
#

cs}t|�}t|�}t|�}t|�}t|�}t|�}t|�}t|�}di�fd�|D��S(s-Parse and format the text according to width.s
c3s"x|]}t|��VqWdS(N(RD(Rtb(R!(s$/sys/lib/python/mercurial/minirst.pys	<genexpr>As(	RRRRR)R/R3R7R;(RR!R
((R!s$/sys/lib/python/mercurial/minirst.pytformat7st__main__(tpprintcCs'||�}d|iGHt|�H|S(Ns
*** after %s:(t__name__RH(tfuncR
((s$/sys/lib/python/mercurial/minirst.pytdebugGs

is
ccs"x|]}t|d�VqWdS(iN(RD(RRE((s$/sys/lib/python/mercurial/minirst.pys	<genexpr>Ws(t__doc__tretsysR>RRRRtcompileR"R)R+R/R3R7RDRFRIRHRKtopentargvtreadRR
R;(((s$/sys/lib/python/mercurial/minirst.pys<module> s4$		3			!	$	!			

	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.