a \n ^d@sddlZddlmZmZmZddlmZddej DZ e e ddd Z e ee e fd d d Ze ee ee e ffd ddZee ee fee ee e ffee e fee e fdddZee e fe d ddZee e fed ddZee e fee d ddZee e fed ddZee ee fe dddZe eeeddd Ze e d!d"d#Zd.e ee d%d&d'Zee e ee d(d)d*Zd/e e e d+d,d-ZdS)0N)DictListOptional)configcCs&i|]\}}|dkrtjj||qS)Znbsp)htmlZentitiesZname2codepoint).0kvr 3/usr/lib/python3.9/site-packages/html2text/utils.py sr )tagreturncCsD|ddkr@t|dkr@|d}d|kr4dkr@nnt|SdS)Nrhr09)lenint)rnr r r hn s r)stylercCsdddd|dDDS)z, :returns: A hash of css attributes cSs&i|]\}}||qSr )striplower)rxyr r r r sz&dumb_property_dict..cSs g|]}d|vr|ddqS):rsplit)rzr r r z&dumb_property_dict..;rrr r r dumb_property_dictsr%)datarcCs|d7}|d}|dkrJ|d|||d|dd}|d}qdd|d D}zd d |D}Wntyi}Yn0|S) z :type data: str :returns: A hash of css selectors, each of which contains a hash of css attributes. :rtype: dict r#z@importrrNcSs"g|]}d|vr|dqS){)rrrrr r r r!0r"z#dumb_css_parser..}cSsi|]\}}|t|qSr )rr%)rabr r r r 2r"z#dumb_css_parser..)findr ValueError)r&Z importIndexpairselementsr r r dumb_css_parsers  $   r1)attrs style_def parent_stylercCs^|}d|vr<|dD]}|d|i}||qd|vrZt|d}|||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)copyrgetupdater%)r2r3r4rZ css_classZ css_styleZimmediate_styler r r element_style9s    r:cCs d|vr|d}|dvrdSdS)zh Finds out whether this is an ordered or unordered list :type style: dict :rtype: str zlist-style-type)ZdiscZcircleZsquareZnoneZulZolr )rZ list_styler r r google_list_styleTs r;cCsd|vS)z Check if the style of the element has the 'height' attribute explicitly defined :type style: dict :rtype: bool Zheightr r$r r r google_has_heightds r<cCsJg}d|vr||dd|vr0||dd|vrF||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)rZemphasisr r r google_text_emphasispsr>cCs$d}d|vr|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_familyr r r google_fixed_width_fontsr@)r2rcCs2d|vr.zt|ddWSty,Yn0dS)zh Extract numbering from list element attributes :type attrs: dict :rtype: int or None startrr)rr.)r2r r r list_numbering_starts  rB)para wrap_linkswrap_list_itemsrcCs|stj|rdS|dddks0|ddkr4dS|}|dddkrht|dkrh|ddkrhd S|dd d vr|ddd ks| Sttj|ptj|S) NTrz  rz---Fr)rH*z**) rZRE_LINKsearchlstriprboolZRE_ORDERED_LIST_MATCHERmatchZRE_UNORDERED_LIST_MATCHER)rCrDrEstrippedr r r skipwraps(   rO)textrcCstjd|S)zU Escapes markdown-sensitive characters within other markdown constructs. \\\1)rZRE_MD_CHARS_MATCHERsub)rPr r r escape_mdsrSF)rPsnobrcCsNtjd|}|r tjd|}tjd|}tjd|}tjd|}|S)zO Escapes markdown-sensitive characters across whole document sections. rQz\1\\\2)rZRE_MD_BACKSLASH_MATCHERrRZRE_MD_CHARS_MATCHER_ALLZRE_MD_DOT_MATCHERZRE_MD_PLUS_MATCHERZRE_MD_DASH_MATCHER)rPrTr r r escape_md_sectionsrU)lines right_marginrc s4fdd|ddD}t|}|D]}dd|dD}t|}||krd|dg||7}n0||kr|fdd||| dD7}|}fd dt||D}q(g}|D]x}d d|dD}t|td krd fd dt||D}ndfddt||D}|d|q|S)zR Given the lines of a table padds the cells and returns the new lines csg|]}t|qSr )rrstripr)rWr r r!r"z"reformat_table..r|cSsg|] }|qSr rXr)r r r r!r"r?csg|]}t|qSr )rr)rYr r r!r"Ncs"g|]\}}tt||qSr )maxr)rrZold_lenrYr r r!scSsg|] }|qSr r[r)r r r r!r"z-|rHcs,g|]$\}}||t|qSr rXrrrMfillerr r r!s cs,g|]$\}}||t|qSr r]r^r`r r r!s)rrzipsetrr=join) rVrWZ max_widthZmax_colslineZcolsZnum_cols new_linesZnew_colsr )rarWr reformat_tables6$   rh)rPrWrcCs||d}g}d}g}|D]V}tj|vrV| }|st||}||g}|dq|rf||q||qd|S)z0 Provide padding for tables in the text  Fr?)rrZTABLE_MARKER_FOR_PADrhextendr=re)rPrWrVZ table_bufferZ table_startedrgrftabler r r pad_tables_in_texts"       rl)F)r)Z html.entitiesrtypingrrrr?rZ UNIFIABLEitemsZ unifiable_nstrrrr%r1r:r;rLr<r>r@rBrOrSrUrhrlr r r r s.     +