3 v:U](ã@s ddlZddlmZdd„ejjƒDƒZdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd#dd„Zdd„Zd$d!d"„ZdS)%éN)ÚconfigcCs&i|]\}}|dkr|tjj|“qS)Znbsp)ÚhtmlZentitiesZname2codepoint)Ú.0ÚkÚv©rú/usr/lib/python3.6/utils.pyú sr cCsD|ddkr@t|ƒdkr@|d}d|ko2dknr@t|ƒSdS)NrÚhééÚ0Ú9)ÚlenÚint)ÚtagÚnrrrÚhn s rcCsdd„dd„|jdƒDƒDƒS)z, :returns: A hash of css attributes cSs&i|]\}}|jƒjƒ|jƒjƒ“qSr)ÚstripÚlower)rÚxÚyrrrr sz&dumb_property_dict..cSs g|]}d|kr|jddƒ‘qS)ú:r )Úsplit)rÚzrrrú sz&dumb_property_dict..ú;)r)ÚstylerrrÚdumb_property_dictsrc Cs’|d7}|jdƒ}x:|d krL|d|…||jd|ƒdd…}|jdƒ}qWdd„|jdƒDƒ}yd d „|Dƒ}Wntk rŒi}YnX|S) z‡ :type data: str :returns: A hash of css selectors, each of which contains a hash of css attributes. :rtype: dict rz@importr rNcSs"g|]}d|jƒkr|jdƒ‘qS)ú{)rr)rrrrrr/sz#dumb_css_parser..ú}cSsi|]\}}t|ƒ|jƒ“qSr)rr)rÚaÚbrrrr 1sz#dumb_css_parser..éÿÿÿÿ)ÚfindrÚ ValueError)ÚdataZ importIndexÚelementsrrrÚdumb_css_parsers   $ r(cCsb|jƒ}d|kr@x.|djƒD]}|jd|iƒ}|j|ƒqWd|kr^t|dƒ}|j|ƒ|S)z¥ :type attrs: dict :type style_def: dict :type style_def: dict :returns: A hash of the 'final' style attributes of the element :rtype: dict ÚclassÚ.r)ÚcopyrÚgetÚupdater)ÚattrsZ style_defZ parent_stylerZ css_classZ css_styleZimmediate_stylerrrÚ element_style8s   r/cCs d|kr|d}|dkrdSdS) zh Finds out whether this is an ordered or unordered list :type style: dict :rtype: str zlist-style-typeÚdiscÚcircleÚsquareÚnoneZulZol)r0r1r2r3r)rZ list_stylerrrÚgoogle_list_styleMs r4cCsd|kS)z† Check if the style of the element has the 'height' attribute explicitly defined :type style: dict :rtype: bool Zheightr)rrrrÚgoogle_has_height]s r5cCsJg}d|kr|j|dƒd|kr0|j|dƒd|krF|j|dƒ|S)zk :type style: dict :returns: A list of all emphasis modifiers of the element :rtype: list ztext-decorationz font-stylez font-weight)Úappend)rZemphasisrrrÚgoogle_text_emphasisisr7cCs$d}d|kr|d}d|kp"d|kS)zu Check if the css of the current element defines a fixed width font :type style: dict :rtype: bool Úz font-familyz courier newZconsolasr)rZ font_familyrrrÚgoogle_fixed_width_font{sr9c Cs2d|kr.yt|dƒdStk r,YnXdS)zh Extract numbering from list element attributes :type attrs: dict :rtype: int or None Ústartr r)rr%)r.rrrÚlist_numbering_start‰s r;cCs¶ttjj|ƒƒdkr| rdS|dd…dks:|ddkr>dS|jƒ}|dd…dkrrt|ƒdkrr|ddkrrd S|dd …d krš|dd…d k rš| Sttjj|ƒp²tjj|ƒƒS)NrTéz ú r z--ú-Fr Ú*z**)r>r?) rrZRE_LINKÚfindallÚlstripÚboolZRE_ORDERED_LIST_MATCHERÚmatchZRE_UNORDERED_LIST_MATCHER)ZparaZ wrap_linksZwrap_list_itemsÚstrippedrrrÚskipwrapšs(" rEcCstjjd|ƒS)zU Escapes markdown-sensitive characters within other markdown constructs. z\\\1)rZRE_MD_CHARS_MATCHERÚsub)ÚtextrrrÚ escape_md¹srHFcCsNtjjd|ƒ}|r tjjd|ƒ}tjjd|ƒ}tjjd|ƒ}tjjd|ƒ}|S)zO Escapes markdown-sensitive characters across whole document sections. z\\\1z\1\\\2)rZRE_MD_BACKSLASH_MATCHERrFZRE_MD_CHARS_MATCHER_ALLZRE_MD_DOT_MATCHERZRE_MD_PLUS_MATCHERZRE_MD_DASH_MATCHER)rGZsnobrrrÚescape_md_sectionÁsrIc s<‡fdd„|djdƒDƒ}t|ƒ}xŒ|D]„}dd„|jdƒDƒ}t|ƒ}||krf|dg||7}n0||kr–|‡fdd„||| d…Dƒ7}|}‡fd d„t||ƒDƒ}q*Wg}x€|D]x}d d„|jdƒDƒ}t|jƒƒtd ƒkrd ‰‡fd d„t||ƒDƒ}nd‰‡fdd„t||ƒDƒ}|jdj|ƒƒq¼W|S)zR Given the lines of a table padds the cells and returns the new lines csg|]}t|jƒƒˆ‘qSr)rÚrstrip)rr)Ú right_marginrrr×sz"reformat_table..rú|cSsg|] }|jƒ‘qSr)rJ)rrrrrrÚsr8csg|]}t|ƒˆ‘qSr)r)rr)rKrrrásNcs"g|]\}}tt|ƒˆ|ƒ‘qSr)Úmaxr)rrZold_len)rKrrråscSsg|] }|jƒ‘qSr)rJ)rrrrrrësz-|r>cs,g|]$\}}|jƒˆ|t|jƒƒ‘qSr)rJr)rrÚM)Úfillerrrrïsú cs,g|]$\}}|jƒˆ|t|jƒƒ‘qSr)rJr)rrrN)rOrrrõs)rrÚzipÚsetrr6Újoin) ÚlinesrKZ max_widthZmax_colsÚlineZcolsZnum_colsÚ new_linesZnew_colsr)rOrKrÚreformat_tableÑs. $   rWr cCs‚|jdƒ}gd}}g}x^|D]V}tj|krZ| }|st||ƒ}|j|ƒg}|jdƒq|rj|j|ƒq|j|ƒqWdj|ƒS)z0 Provide padding for tables in the text Ú Fr8)rrZTABLE_MARKER_FOR_PADrWÚextendr6rS)rGrKrTZ table_bufferZ table_startedrVrUÚtablerrrÚpad_tables_in_textüs         r[)F)r )Z html.entitiesrZ html2textrZ UNIFIABLEÚitemsZ unifiable_nrrr(r/r4r5r7r9r;rErHrIrWr[rrrrÚs"    +