
                            S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSKrSSKJr  \" \" S	5      5      u  rrr " S
 S\5      r " S S\5      r\R*                  " \R,                  5       " S S\5      5       rg)z0Cloud SDK markdown document renderer base class.    )absolute_import)division)unicode_literalsN)log)resource_printer)range   c                   "    \ rS rSrSrSS jrSrg)TableColumnAttributes#   zMarkdown table column attributes.

Attributes:
  align: Column alignment, one of {'left', 'center', 'right'}.
  label: Column heading label string.
  width: Minimum column width.
Nc                 (    Xl         X l        X0l        g Nalignlabelwidthselfr   r   r   s       6lib/googlecloudsdk/core/document_renderers/renderer.py__init__TableColumnAttributes.__init__,   s    JJJ    r   )leftNr   )__name__
__module____qualname____firstlineno____doc__r   __static_attributes__ r   r   r   r   #   s    r   r   c                   6    \ rS rSrSrSS jrS	S jrS
S jrSrg)TableAttributes2   zMarkdown table attributes.

Attributes:
  box: True if table and rows framed by box.
  columns: The list of column attributes.
  heading: The number of non-empty headings.
  margin: Extra margin to handle post-processing indent.
c                 ,    Xl         SU l        / U l        g )Nr   )boxheadingcolumns)r   r%   s     r   r   TableAttributes.__init__<   s    HDLDLr   c                     U(       a  U =R                   S-  sl         U R                  R                  [        XUS95        g)z-Adds the next column attributes to the table.   r   N)r&   r'   appendr   r   s       r   	AddColumnTableAttributes.AddColumnA   s/    
llalLLEeDr   c           
         S/n/ nU R                   (       a  UR                  S5        U R                  (       d  UR                  S5        U(       a   UR                  SR                  U5      5        U(       a   UR                  SR                  U5      5        U(       a&  UR                  SSR	                  U5      -   S-   5        UR                  S	5        [        U R                  5       H  u  pVU(       a  UR                  S5        UR                  S
R                  U[        UR                  =(       d    S5      R                  S5      UR                  5      5        UR                  (       d  M  UR                  SR                  UR                  5      5        M     U(       a  UR                  S5        UR                  S5        SR	                  U5      $ )zConstructs and returns a resource_printer print format.

Args:
  margin: Right hand side padding when one or more columns are wrapped.
  width: The table width.

Returns:
  The resource printer format string.
tabler%   z
no-headingz	margin={}zwidth={}[,](z[{}]:label={}:align={} uz	:width={}z:wrap))r%   r+   r&   formatjoin	enumerater'   reprr   lstripr   r   )r   marginr   fmtattrindexcolumns          r   GetPrintFormatTableAttributes.GetPrintFormatI   sG    )CDxx
kk%<<
kk,
kk+$$V,-
kk*##E*+	jjsxx~%+,JJsO"4<<0	

3	jj
"
)
)T&,,,"-44S96<<
 


;%%fll34 1 	jjJJsO773<r   )r%   r'   r&   N)F)r   r4   r   )r   r   )	r   r   r   r   r   r   r,   rA   r   r    r   r   r"   r"   2   s    
$r   r"   c                       \ rS rSrSr     SS jr\S 5       rS rS r	S r
S	 rS
 rS rSS jrS rS rS rS rS rSS jrS rSrg)Rendererp   a[  Markdown renderer base class.

The member functions provide an abstract document model that matches markdown
entities to output document renderings.

Attributes:
  _blank: True if the output already contains a blank line. Used to avoid
    sequences of 2 or more blank lines in the output.
  _command: The command split into component names.
  _font: The font attribute bitmask.
  _indent: List of left indentations in characters indexed by _level.
  _lang: ```lang\n...\n``` code block language. None if not in code block, ''
    if in code block with no explicit lang specified.
  _level: The section or list level counting from 0.
  _out: The output stream.
  _title: The document title.
  _width: The output width in characters.
  command_metadata: Optional metadata of command.
  command_node: The command object that the document is being rendered for.
Nc                     SU l         S/U l        SU l        / U l        S U l        SU l        U=(       d    [        R                  U l        X l	        X0l
        X@l        XPl        g )NTgcloudr   )_blank_command_font_indent_lang_levelr   out_out_title_widthcommand_metadatacommand_node)r   rN   titler   rR   rS   s         r   r   Renderer.__init__   sU     DKJDMDJDLDJDKswwDIKK,$r   c                     U R                   $ )z/Returns the command split into component names.rI   r   s    r   commandRenderer.command   s     ==r   c                     SU l         g)zThe last output line is blank.TNrH   rX   s    r   BlankRenderer.Blank   s	    DKr   c                     SU l         g)z4Some non-blank line content was added to the output.FNr\   rX   s    r   ContentRenderer.Content   s	    DKr   c                     U R                   $ )z.Returns True if the last output line is blank.r\   rX   s    r   	HaveBlankRenderer.HaveBlank   s    ;;r   c                     U$ )zConverts special characters to their entity tags.

This is applied after font embellishments.

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

Returns:
  The escaped string.
r    r   bufs     r   EntitiesRenderer.Entities   	     Jr   c                     U$ )zEscapes special characters in normal text.

This is applied before font embellishments.

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

Returns:
  The escaped string.
r    rf   s     r   EscapeRenderer.Escape   rj   r   c                     g)z'Finishes all output document rendering.Nr    rX   s    r   FinishRenderer.Finish   s    r   c                     g)zReturns the font embellishment string for attr.

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

Returns:
  The font embellishment string.
r4   r    )r   unused_attr
unused_outs      r   FontRenderer.Font   s     r   c                     Xl         g)zZSets the document command name.

Args:
  command: The command split into component names.
NrW   )r   rY   s     r   
SetCommandRenderer.SetCommand   s	     Mr   c                     Xl         g)zSets the ```...``` code block language.

Args:
  lang: The language name, None if not in a code block, '' is no explicit
    language specified.
N)rL   )r   langs     r   SetLangRenderer.SetLang   s	     Jr   c                     g)z$Renders a paragraph separating line.Nr    rX   s    r   LineRenderer.Line   s    r   c                 d    U(       a   U(       a  SU;   a  SR                  X!5      $ U$ U(       a  U$ g)zRenders an anchor.

Args:
  target: The link target URL.
  text: The text to be displayed instead of the link.

Returns:
  The rendered link anchor and text.
z://z	{0} ({1})z[]())r7   )r   targettexts      r   LinkRenderer.Link   s1     	EVO!!$//kmr   c                     U$ )zvAdd global flags links to line if any.

Args:
  line: The text line.

Returns:
  line with annoted global flag links.
r    )r   lines     r   LinkGlobalFlagsRenderer.LinkGlobalFlags   s	     Kr   c                 L    U R                   R                  US-  U-   S-   5        g)zAdds an indented table line to the output.

Args:
  line: The line to add. A newline will be added.
  indent: The number of characters to indent the table.
 
N)rO   write)r   r   indents      r   	TableLineRenderer.TableLine
  s"     	IIOOFSL4'$./r   c                    U R                  5         U R                  U R                     R                  S-   n[	        U Vs/ s H  nSUS   ;   d  M  SPM     sn5      (       a  UOSn[
        R                  " 5       n[        R                  " X!R                  XPR                  S9US9  UR                  5       R                  S5      S	S  H  nU R                  XsS
9  M     U R                  5         U R                  5         g	s  snf )zRenders a table.

Nested tables are not supported.

Args:
  table: A TableAttributes object.
  rows: A list of rows where each row is a list of column strings.
   r   Tr   )r<   r   )rN   r   N)r   )r~   rK   rM   r   anyioStringIOr   PrintrA   rQ   getvaluesplitr   r`   )r   r/   rowsr   rr<   rg   r   s           r   TableRenderer.Table  s     	IIK\\$++&--1F$?$Q#2,D$?@@VaF
++-C""&"D# $$T*3B/
nnTn) 0LLNIIK @s    DD)rH   rI   rJ   rK   rL   rM   rO   rP   rQ   rR   rS   )NNP   NNr   )r   )r   r   r   r   r   r   propertyrY   r]   r`   rc   rh   rl   ro   rt   rw   r{   r~   r   r   r   r   r   r    r   r   rD   rD   p   sw    . %(  	&	0r   rD   )r   
__future__r   r   r   abcr   googlecloudsdk.corer   googlecloudsdk.core.resourcer   six	six.movesr   listBOLDITALICCODEobjectr   r"   add_metaclassABCMetarD   r    r   r   <module>r      s     7 &  ' 
 	 # 9 
  %(^ fdF ;f ;| 3;;uv u  ur   