
    =                     r    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\R                  5      r
g)	z*Cloud SDK markdown document HTML renderer.    )absolute_import)division)unicode_literalsN)rendererc                      ^  \ rS rSrSrSrSSSS.rSrU 4S	 jrS
 r	S 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S jrS rSrU =r$ )HTMLRenderer   a@  Renders markdown to HTML.

Attributes:
  _BULLET: A list of bullet type names indexed by list level modulo #bullets.
  _ESCAPE: Character element code name dict indexed by input character.
  _FONT_TAG: A list of font embellishment tag names indexed by font attribute.
  _document_ids: The set of html ids unique in the current document.
  _example: True if currently rendering an example.
  _fill: The number of characters in the current output line.
  _heading: A string of HTML tags that closes out a heading section.
  _level: The section or list level counting from 0.
  _paragraph: True if the output already contains a paragraph tag. Used to
    avoid sequences of 2 or more paragraph tags in the output.
  _pop: A list of list element closing tag names indexed by _level.
  _section: Section heading but no section body yet.
)disccirclesquarez&amp;z&lt;z&gt;)&<>)code)r   varr   c                   > [         [        U ]
  " U0 UD6  [        5       U l        SU l        SU l        SU l        SU l        SU l	        SU l
        S/U l        SU l        U R                  5         U R                  R                  S5        g )NFr    a  <!--
        THIS DOC IS GENERATED.  DO NOT EDIT.
  -->
<style>
  dd {
    margin-bottom: 1ex;
  }
  li {
    margin-top: 1ex; margin-bottom: 1ex;
  }
  .flag {
    white-space: nowrap;
  }
  .hangingindent {
    padding-left: 1.5em;
    text-indent: -1.5em;
  }
  .normalfont {
    font-weight: normal;
  }
  .notopmargin {
    margin-top: 0em;
  }
  .sectionbody {
    margin-top: .2em;
  }
</style>
</head>
<body>
<dl>
)superr   __init__set_document_ids_example_fill_global_flags_heading_level
_paragraph_pop_section_Title_outwrite)selfargskwargs	__class__s      ;lib/googlecloudsdk/core/document_renderers/html_renderer.pyr   HTMLRenderer.__init__2   sz    	,&77DDMDJDDMDKDODIDMKKMIIOO      c                     U R                   R                  S5        U R                  (       a(  U R                   R                  SU R                  -  5        U R                   R                  S5        g)zRenders an HTML document title.z<html>
<head>
z<title>%s</title>
z<style>
  code { color: green; }
</style>
<script>
  window.onload = function() {
    if (parent.navigation.navigate) {
      parent.navigation.navigate(document.location.href);
    }
  }
</script>
N)r"   r#   _titler$   s    r(   r!   HTMLRenderer._Title_   sO    IIOO   {{
iioo+dkk9:IIOO  r*   c                    SU l         U R                  (       am  SU l        U R                  (       a"  SU l        U R                  R                  S5        SU l        U R                  R                  S5        U R                  5         gg)z/Flushes the current collection of Fill() lines.Fz</code>
r   
N)r   r   r    r   r"   r#   Contentr-   s    r(   _FlushHTMLRenderer._Flusht   sZ    DOzzdm			$dj
iiood
lln r*   c                 F   S n[         R                  " SU5      nU(       a  UR                  S5      nUR                  S5      R	                  SS5      nU" U5      nUnSn X@R
                  ;  a  U R
                  R                  U5        U$ US-  nSR                  XS	9nMB  )
z&Returns a unique document id for name.c                 2    [         R                  " SSU 5      $ )z=Returns singlularized name if name is 'COMMANDS' or 'GROUPS'.z(COMMAND|GROUP)S$z\1resub)names    r(   $SingularizeCommandAndGroupDocumentIDHHTMLRenderer.GetDocumentID.<locals>.SingularizeCommandAndGroupDocumentID   s     VV(%66r*   zY(-- |\[)*(<[^>]*>)*(?P<anchor>-[-_a-z0-9\[\]]+|[_A-Za-z.0-9 ][-_A-Za-z.0-9 ]*|[-.0-9]+).*anchor -r      z{name}-{number})r9   number)r7   matchgroupstripreplacer   addformat)r$   r9   r:   mattemptr@   s         r(   GetDocumentIDHTMLRenderer.GetDocumentID   s     7 		
 		A 	WWXd::c?""3,D/5D GF
	**	*w'kf!((d(Bg r*   c                 V    [         R                  " SSU5      nUR                  SS5      $ )zEscapes special characters to their entity tags.

This is applied after font embellishments.

Args:
  buf: Normal text that may contain special characters.

Returns:
  The string with special characters converted to entity tags.
z(``[^`]*)''z\1&acute;&acute;z...z&hellip;)r7   r8   rD   )r$   bufescs      r(   EntitiesHTMLRenderer.Entities   s(     && 3S
9C;;uj))r*   c                 :   ^  SR                  U 4S jU 5       5      $ )zEscapes special characters in normal text.

This is applied before font embellishments.

Args:
  buf: Normal text that may contain special characters.

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

Args:
  line: The example line.
T   z
<p><code>
z&nbsp;z<br>
N)Blankr   r   r"   r#   lenlstrip)r$   lineindents      r(   ExampleHTMLRenderer.Example   s     	JJL==dmdj
iioom$YF;;=D
c$iFIIOOH

V 345IIOODIIOOHr*   c                    U R                   (       a"  SU l         U R                  R                  S5        U R                  5         U R                  (       a  SU l        U R                  U5      nUR                  5        H  n[        U5      nU R                  U-   U R                  :  a#  U R                  R                  S5        SU l        OAU R                  (       a0  U =R                  S-  sl        U R                  R                  S5        U =R                  U-  sl        U R                  R                  U5        M     g)zdAdds a line to the output, splitting to stay within the output width.

Args:
  line: The text line.
Fz<p>
r0   r   r?   r=   N)
r   r"   r#   r]   r   LinkGlobalFlagssplitr^   r   _width)r$   r`   wordns       r(   FillHTMLRenderer.Fill   s     do
iioogJJL d!!$'d


d)a	a4;;	&		
::

a
		
jjAoj
iiood r*   c                     U R                  U R                  S9  U R                  S5        U R                  (       a%  U R                  R	                  U R                  5        U R                  R	                  S5        g)z'Finishes all output document rendering.outr   z
</dl>
</body>
</html>
N)Fontr"   Listr   r#   r-   s    r(   FinishHTMLRenderer.Finish   sK    II$))IIIaL}}
iioodmm$IIOO12r*   c                    / nUc  [         R                  [         R                  [         R                  4 Hf  nSU-  nU R                  U-  (       d  M  U =R                  U-  sl        [        U R                  U   5       H  nUR                  SU-  5        M     Mh     OSU-  nU =R                  U-  sl        U R                  U-  (       a+  U R                  U    H  nUR                  SU-  5        M     O3[        U R                  U   5       H  nUR                  SU-  5        M     SR                  U5      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 HTML tag string.
r?   z</%s>z<%s>r   r0   )
r   BOLDITALICCODE_fontreversed	_FONT_TAGappendrX   r#   )r$   attrrn   tagsmasktagembellishments          r(   ro   HTMLRenderer.Font   s    D|==(//8==A$Dy::
**
*dnnT23cKK#& 4	 B $Yd
jjDj	d	>>$'C
++fsl
# ( DNN401C
++gm
$ 2GGDMM
}	ii$%r*   c                 l    SU l         US-  nUS:  a  SnU R                  R                  SXU4-  5        g)ziRenders an HTML heading.

Args:
  level: The heading level counting from 1.
  heading: The heading text.
</dd>
r\   	   z1
<dt><h%d>%s</h%d></dt>
<dd class="sectionbody">
N)r   r"   r#   r$   levelheadings      r(   _HeadingHTMLRenderer._Heading!  s@     DM	QJEqyeIIOO>5
!	"r*   c                    US:X  a  UR                  S5      (       a  gU R                  5         U R                  U R                  S9  U R	                  S5        U R
                  (       a%  U R                  R                  U R
                  5        U R                  X5        SU l        UR                  S5      (       a  SU l	        gg)zcRenders a heading.

Args:
  level: The heading level counting from 1.
  heading: The heading text.
r?   z(1)Nrm   r   Tz WIDE FLAGS)
endswithr2   ro   r"   rp   r   r#   r   r    r   r   s      r(   HeadingHTMLRenderer.Heading1  s     zg&&u--KKMII$))IIIaL}}
iioodmm$MM%!DM&&d 'r*   c                 ~    U R                  5         U R                  5       (       d  U R                  5         SU l        gg)z$Renders a paragraph separating line.TN)r2   	HaveBlankr]   r   r-   s    r(   LineHTMLRenderer.LineD  s-    KKM>>
jjldo r*   c                    SU;   d  UR                  S5      (       a  SR                  X=(       d    US9$ SU;   d  UR                  S5      (       a  SR                  X=(       d    US9$ U(       d  UR                  SS	5      nS
nUR                  U5      (       a  US[	        U5      *  nUR                  SS5      S-   nSR                  XS9$ )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www.z)<a href="{target}" target=_top>{text}</a>)targettext#z..z<a href="{target}">{text}</a>/r=   z/helpN_z.html)
startswithrF   r   rD   r^   )r$   r   r   tails       r(   LinkHTMLRenderer.LinkK  s     f}))&118??nf @   f}--,33nf 4   ^^C%dDtlT
#f^^C%/F*111KKr*   c                 2    [         R                  " SSU5      $ )zvAdd global flags links to line if any.

Args:
  line: The text line.

Returns:
  line with annoted global flag links.
z(--[-a-z]+)z<a href="/#\1">\1</a>r6   )r$   r`   s     r(   re   HTMLRenderer.LinkGlobalFlagse  s     66.":DAAr*   c                 B   U R                  5         U R                  (       az  U R                  U:  aj  U R                  R                  U R                  U R                     5        U =R                  S-  sl        U R                  (       a  U R                  U:  a  Mj  U(       d  U(       d  gUGb  U R                  U:  a  U =R                  S-  sl        U R                  [        U R                  5      :  a  U R                  R                  S5        SU R                  U R                  '   U R                  (       a#  SU l        U R                  R                  S5        OU R                  R                  S5        OmSU R                  U R                     ;   a5  U R                  R                  S	5        SU R                  U R                  '   OU R                  R                  S
5        U(       a9  U R                  R                  SR                  U R                  U5      US95        gU R                  S:  a9  SU R                  U R                     ;   a  U R                  R                  S5        gU R                  R                  S5        SU R                  U R                  '   gU R                  U:  a  U =R                  S-  sl        U R                  [        U R                  5      :  a  U R                  R                  S5        SU R                  U R                  '   U R                  R                  SU R                  US-
  [        U R                  5      -     -   S-   5        OU R                  R                  S5        U R                  R                  S5        g)zRenders a bullet or definition list item.

Args:
  level: The list nesting level.
  definition: Bullet list if None, definition list otherwise.
  end: End of list if True.
r?   Nr   z</dd>
</dl>
Fz<dl class="notopmargin">
z<dl>
dtz</dt>
r   zN<dt id="{document_id}"><span class="normalfont">{definition}</span></dt>
<dd>
)document_id
definitionz<dd>
z<dt><span class="normalfont">
z</span></dt>
</dl>
z</li>
</ul>
z<ul style="list-style-type:z">
z</li>
z<li>
)r2   r   r"   r#   r   r^   rz   r    rF   rI   _BULLET)r$   r   r   ends       r(   rp   HTMLRenderer.Listp  sx    	KKM
++$++-
iioodii,-
kkQk ++$++- % 
u	q;;#dii.(
))

2
!1		$++==$-
))//6
7
))//(
#499T[[))			"!1		$++			"			//5v ..z:% 06 0	
 ;;?ttyy'==		!		9:!8		$++ 
u	q;;#dii.(
))

2
!1		$++		)llEAIT\\)::;<	
 				"
iioohr*   c                 n   U R                   R                  S5        [        R                  " SSU5      n[        R                  " SSU5      n[        R                  " SSU5      n[        R                  " SSU5      nU(       a  [        R                  " S	S
U5      nU R                  S   R                  5       n[        R                  " SR                  US9SR                  US9U5      nSn[        R                  " U5      nU(       a  UR                  5       nUS;   a  US-  nUS:X  a  SU-   nOGUS;   a  US-  nU(       d  US-  nO/US:X  a)  US:X  a#  U(       a  US   S:X  a  SUR                  5       -   nU R                   R                  U5        U(       a  M  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 NAME or SYNOPSIS section text.
  is_synopsis: if it is the synopsis section
zL<dl class="notopmargin"><dt class="hangingindent"><span class="normalfont">
z!(<code>)([-a-z0-9\[\]]+)(</code>)z\1<a href="#\2">\2</a>\3zhref="#--no-z	href="#--z0([^[=]\[*<code><var>)([_A-Z0-9]+)(</var></code>)z=(<code><a href="#[-a-z0-9\[\]]+">[-a-z0-9\[\]]+(<[^>]*>|\S)*)z<span class="flag">\1</span>z(,)z\1</span><span class="flag">r   z>{root}_WIDE_FLAG )rootz3><a href="#{root}-WIDE-FLAGS">{root}_WIDE_FLAG</a> z[(r?   z<span>z)]z</span>r=   |z&</span> <span>&nbsp;&nbsp;&nbsp;&nbsp;z
</span></dt></dl>
N)
r"   r#   r7   r8   commandupperrF   collectionsdequepopleft)r$   r`   is_synopsisr   nestcharsrU   s          r(   SynopsisHTMLRenderer.Synopsis  s    	IIOO	& 66,.I4D 66.+t4D 66;#D 66L'D VVE:DAd <<?  "D66###.=DD$DOD Dd#E

--/a	
d	19l!9	
y.!19ceaC4u}}F
iiooa % 	IIOO+,r*   c           	      b   U R                   R                  S5        UR                  (       a  U R                   R                  S5        UR                   H@  nU R                   R                  SR	                  UR
                  =(       d    S5      5        MB     U R                   R                  S5        U H  nU R                   R                  S5        [        U5       H  u  pVSnSnU[        UR                  5      :  aG  UR                  U   nUR                  nUR                  (       a  SR	                  UR                  5      nU R                   R                  SR	                  XxU5      5        M     U R                   R                  S5        M     U R                   R                  S	5        g
)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
<blockquote>
<table>
z<tr>
z<th>{}</th>
r   z</tr>
leftz width={}emz<td align={}{}>{}</td>
z</table>
</blockquote>
N)
r"   r#   r   columnsrF   label	enumerater^   alignwidth)	r$   tablerowscolumnrowindexcolr   r   s	            r(   TableHTMLRenderer.Table  s,    	IIOO/0 }}
iioohMM&		..v||/ArBC "
iiooi  
iiooh!#*%3u}}%%=='&,,%\\!((6E		299%LM ' iiooi   	IIOO/0r*   )	r   r   r   r   r   r   r   r   r    )NN)NF)F)__name__
__module____qualname____firstlineno____doc__r   rR   ry   r   r!   r2   rI   rN   rY   rb   rj   rq   ro   r   r   r   r   re   rp   r   r   __static_attributes____classcell__)r'   s   @r(   r   r      s    " )'V4'5)+Z*
0Cd*8$03B  &L4	B= ~A-F'1 '1r*   r   )r   
__future__r   r   r   r   r7   &googlecloudsdk.core.document_renderersr   Rendererr    r*   r(   <module>r      s0     1 &  '  	 ;}18$$ }1r*   