
    Q                     b    S r SSKJr  SSKJr  SSKJr  SSKJr   " S S\R                  5      rg)	z5Cloud SDK markdown document man page format renderer.    )absolute_import)division)unicode_literals)rendererc                      ^  \ rS rSrSrSrSSS.rSrU 4S jrS	 r	S
 r
S rS rS rSS jrS rS rSS jrSS jrS rSrU =r$ )ManRenderer   a  Renders markdown to man(1) input.

Attributes:
  _BULLET: A list of bullet characters indexed by list level modulo #bullets.
  _ESCAPE: Character element code string dict indexed by input character.
  _FONT_TAG: Font embellishment tag string list indexed by font attribute.
  _example: True if currently rendering an example.
  _fill: The number of characters in the current output line.
  _level: The section or list level counting from 0.
  _th_emitted: True if .TH already emitted.
)z\(buz\(emz\ez\-)\-)z\fBz\fIz\f5c                 f   > [         [        U ]
  " U0 UD6  SU l        SU l        SU l        SU l        g )NFr   )superr   __init___example_fill_level_th_emitted)selfargskwargs	__class__s      :lib/googlecloudsdk/core/document_renderers/man_renderer.pyr   ManRenderer.__init__)   s4    	+t%t6v6DMDJDKD    c                     U R                   (       a"  SU l         U R                  R                  S5        U R                  (       a#  SU l        U R                  R                  S5        gg)z/Flushes the current collection of Fill() lines.r   
F.RE
N)r   _outwriter   r   s    r   _FlushManRenderer._Flush0   sC    zzdj
iiood}}dm
iioog r   c                 :   ^  SR                  U 4S jU 5       5      $ )zEscapes special characters in normal text.

Args:
  buf: The normal text that may contain special characters.

Returns:
  The escaped string.
 c              3   Z   >#    U  H   nTR                   R                  X5      v   M"     g 7f)N)_ESCAPEget).0cr   s     r   	<genexpr>%ManRenderer.Escape.<locals>.<genexpr>B   s#     73a4<<##A))3s   (+)join)r   bufs   ` r   EscapeManRenderer.Escape9   s     7773777r   c                     U R                   (       d"  SU l         U R                  R                  S5        U R                  R                  US-   5        g)zNDisplays line as an indented example.

Args:
  line: The example line string.
T.RS 2m
r   N)r   r   r   )r   lines     r   ExampleManRenderer.ExampleD   s6     ==dm
iiooj!IIOOD4K r   c                 ^   SnUR                  5        GH  n[        U5      nU R                  U-   U-   U R                  :  aL  U R                  R                  S5        SU l        US   S:X  a  U R                  R                  S5        SnOnSnOkU R                  (       a1  U =R                  S-  sl        U R                  R                  S5        O)US   S:X  a  U R                  R                  S5        SnOSnU =R                  U-  sl        U R                  R                  U5        GM     g)zfAdds a line to the output, splitting to stay within the output width.

Args:
  line: The line string.
r   r   'r
       N)splitlenr   _widthr   r   )r   r1   escapeswordns        r   FillManRenderer.FillO   s     G


d)a	a'	!T[[	0		
7c>
))//$
''::

a
		7c>		
jjAoj
iiood' r   c                 X    U R                  U R                  S9  U R                  S5        g)z'Finishes all output document rendering.outr   N)Fontr   Listr   s    r   FinishManRenderer.Finishk   s    II$))IIIaLr   c                 
   Uc  U R                   (       a
  SU l         SnOBSnO?SU-  nU =R                   U-  sl         U R                   U-  (       a  U R                  U   OSnU(       a  U(       a  UR                  US-   5        U$ )a  Returns the font embellishment string for attr.

Args:
  attr: None to reset to the default font, otherwise one of renderer.BOLD,
    renderer.ITALIC, or renderer.CODE.
  out: Writes tags line to this stream if not None.

Returns:
  The font embellishment string.
r   z\fRr#   r6   r   )_font	_FONT_TAGr   )r   attrrB   tagsmasks        r   rC   ManRenderer.Fontp   sm     |	
$Yd
jjDj&*jj4&7T^^D!fd
t	iitKr   c                    U R                  5         U R                  U R                  S9  U R                  S5        US:X  a?  UR	                  S5      (       a)  U R                  R                  SUSS -  5        SU l        gU R                  (       d8  U R                  R                  S	U R                  =(       d    S
-  5        SU l        U R                  R                  SU-  5        g)zcRenders a heading.

Args:
  level: The heading level counting from 1.
  heading: The heading text.
rA   r   r6   z(1)z
.TH "%s" 1
NTz
.TH "%s" ""
NOTESz

.SH "%s"
)r    rC   r   rD   endswithr   r   _title)r   levelheadings      r   HeadingManRenderer.Heading   s     	KKMII$))IIIaLzg&&u--
iioo&"56d		)T[[-CGDE
iioonw./r   c                 Z    U R                  5         U R                  R                  S5        g)z$Renders a paragraph separating line.r   N)r    r   r   r   s    r   LineManRenderer.Line   s    KKMIIOODr   c                    U R                  5         SnU R                  (       ae  U R                  U:  aU  U R                  R                  S5        U =R                  S-  sl        SnU R                  (       a  U R                  U:  a  MU  U(       a  U R                  R                  S5        U(       d  U(       d  gU R                  U:  a0  U =R                  S-  sl        U R                  R                  S5        Ub"  U R                  R                  SU-   S	-   5        gU R                  R                  S
U R                  US-
  [        U R                  5      -     -  5        g)zRenders a bullet or definition markdown list item.

Args:
  level: The markdown list nesting level.
  definition: Bullet markdown list if None, definition markdown list
    otherwise.
  end: End of markdown list if True.
Fr   r6   Tz.sp
Nr0   z.TP 2m
r   z.IP "%s" 2m
)r    r   r   r   _BULLETr9   )r   rS   
definitionendneed_sps        r   rD   ManRenderer.List   s     	KKMG
++$++-
iioog
kkQkg ++$++- 
iioog
%{{U
kkQk
iiooj!
iiooj:-45 iiooollEAIT\\1B#BCD Er   c                 
   U R                   R                  S5        SnU HE  nUS;   a  US-  nOUS;   a  US-  nOUS:X  a	  U(       a  SnU R                   R                  U5        MG     U R                   R                  S5        g	)
zRenders NAME and SYNOPSIS lines as a hanging indent.

Does not split top-level [...] or (...) groups.

Args:
  line: The synopsis text.
  is_synopsis: if it is the synopsis section
z.HP
r   z[(r6   z)]r7   z\ r   N)r   r   )r   r1   is_synopsisnestr(   s        r   SynopsisManRenderer.Synopsis   ss     	IIOOGD	
d	9	8
iiooa  	IIOODr   c                 T   U R                   R                  S5        SnSnUR                   H  nUSUR                  S   -   -  nUSUR                  S   -   -  nUR                  (       a<  USR                  UR                  5      -  nUSR                  UR                  5      -  nUS-  nM     UR                  (       a!  U R                   R                  USS S	-   5        U R                   R                  USS S
-   5        U R                   R                  SR                  UR                   Vs/ s H  ofR                  PM     sn5      S	-   5        U H0  nU R                   R                  SR                  U5      S	-   5        M2     U R                   R                  S5        gs  snf )zRenders a table.

Nested tables are not supported.

Args:
  table: renderer.TableAttributes object.
  rows: A list of rows, each row is a list of column strings.
z
.TS
tab(	);
r#   r7   r   z({})Br6   Nr   z.
	z.TE
)	r   r   columnsalignwidthformatrT   r+   label)r   tablerows	head_attr	data_attrcolumnr(   rows           r   TableManRenderer.Table   sN    	IIOO'( II--3a((i3a((i	V]]6<<00	V]]6<<00	3i   }}
iiooimd*+IIOOIabME)*IIOODII>1ww>?$FG 
iioodiint+, 
 	IIOOG ?s   0F%)r   r   rH   r   r   )NN)NF)F)__name__
__module____qualname____firstlineno____doc__r[   r%   rI   r   r    r-   r2   r>   rE   rC   rU   rX   rD   rc   rs   __static_attributes____classcell__)r   s   @r   r   r      sa    
 'u%'&)	8	!8
20&
E@*$ $r   r   N)	ry   
__future__r   r   r   &googlecloudsdk.core.document_renderersr   Rendererr    r   r   <module>r      s*     < &  ' ;a(## ar   