a \n ^dã@s®ddlZddlmZmZmZddlmZdd„ej  ¡DƒZ e e dœdd „Z e ee e fd œd d „Ze ee ee e ffd œdd„Zee ee fee ee e ffee e fee e fdœdd„Zee e fe d œdd„Zee e fed œdd„Zee e fee d œdd„Zee e fed œdd„Zee ee fe dœdd„Ze eeedœdd „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)0éN)ÚDictÚListÚOptionalé)ÚconfigcCs&i|]\}}|dkrtjj||“qS)Znbsp)ÚhtmlZentitiesZname2codepoint)Ú.0ÚkÚv©r ú3/usr/lib/python3.9/site-packages/html2text/utils.pyÚ sþr )ÚtagÚreturncCsD|ddkr@t|ƒdkr@|d}d|kr4dkr@nnt|ƒSdS)NrÚhérÚ0Ú9)ÚlenÚint)rÚnr r r Úhn s r)ÚstylercCsdd„dd„| d¡DƒDƒS)z, :returns: A hash of css attributes cSs&i|]\}}| ¡ ¡| ¡ ¡“qSr )ÚstripÚlower)rÚxÚyr r r r sÿz&dumb_property_dict..cSs g|]}d|vr| dd¡‘qS)ú:r©Úsplit)rÚzr r r Ú óz&dumb_property_dict..ú;r©rr r r Údumb_property_dictsþr%)ÚdatarcCsŒ|d7}| d¡}|dkrJ|d|…|| d|¡dd…}| d¡}qdd„| d ¡Dƒ}zd d „|Dƒ}Wnty†i}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@importéÿÿÿÿrrNcSs"g|]}d| ¡vr| d¡‘qS)Ú{)rr©rrr r r r!0r"z#dumb_css_parser..Ú}cSsi|]\}}| ¡t|ƒ“qSr )rr%)rÚaÚbr r r r 2r"z#dumb_css_parser..)ÚfindrÚ ValueError)r&Z importIndexÚpairsÚelementsr r r Údumb_css_parsers  $   r1)ÚattrsÚ style_defÚ parent_stylercCs~| ¡}d|vrL|ddus J‚|d ¡D]}| d|i¡}| |¡q,d|vrz|ddusdJ‚t|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 ÚclassNÚ.r)ÚcopyrÚgetÚupdater%)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| |d¡d|vr0| |d¡d|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_font‚sr@)r2rcCsBd|vr>|ddusJ‚zt|dƒdWSty<Yn0dS)zh Extract numbering from list element attributes :type attrs: dict :rtype: int or None ÚstartNrr)rr.)r2r r r Úlist_numbering_starts rB)ÚparaÚ wrap_linksÚwrap_list_itemsrcCsª|stj |¡rdS|dd…dks0|ddkr4dS| ¡}|dd…dkrht|ƒdkrh|ddkrhd S|dd …d vrŽ|dd…d ksŽ| Sttj |¡p¦tj |¡ƒS) NTréz ú rz--ú-Fr)rHÚ*z**) rZRE_LINKÚsearchÚlstriprÚboolZRE_ORDERED_LIST_MATCHERÚmatchZRE_UNORDERED_LIST_MATCHER)rCrDrEÚstrippedr r r Úskipwrap¢s(   þrO)ÚtextrcCstj d|¡S)zU Escapes markdown-sensitive characters within other markdown constructs. ú\\\1)rZRE_MD_CHARS_MATCHERÚsub)rPr r r Ú escape_mdÁsrSF)rPÚsnobrcCsNtj d|¡}|r tj d|¡}tj d|¡}tj d|¡}tj d|¡}|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_sectionÉsrU)ÚlinesÚ right_marginrc s4‡fdd„|d d¡Dƒ}t|ƒ}|D]„}dd„| d¡Dƒ}t|ƒ}||krd|dg||7}n0||kr”|‡fdd„||| d…Dƒ7}|}‡fd d„t||ƒDƒ}q(g}|D]x}d d„| d¡Dƒ}t| ¡ƒtd ƒkrd ‰‡fd d„t||ƒDƒ}nd‰‡fdd„t||ƒDƒ}| d |¡¡q¶|S)zR Given the lines of a table padds the cells and returns the new lines csg|]}t| ¡ƒˆ‘qSr )rÚrstripr)©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 ©rXr©rrÚM©Úfillerr r r!ösÿú cs,g|]$\}}| ¡ˆ|t| ¡ƒ‘qSr r]r^r`r r r!üsÿ)rrÚzipÚsetrr=Újoin) rVrWZ max_widthZmax_colsÚlineZcolsZnum_colsÚ new_linesZnew_colsr )rarWr Úreformat_tableÙs6$ ÿ þ þrh)rPrWrcCs|| d¡}g}d}g}|D]V}tj|vrV| }|st||ƒ}| |¡g}| d¡q|rf| |¡q| |¡qd |¡S)z0 Provide padding for tables in the text Ú Fr?)rrZTABLE_MARKER_FOR_PADrhÚextendr=re)rPrWrVZ table_bufferZ table_startedrgrfÚtabler r r Úpad_tables_in_texts"       rl)F)r)Z html.entitiesrÚtypingrrrr?rZ UNIFIABLEÚitemsZ unifiable_nÚstrrrr%r1r:r;rLr<r>r@rBrOrSrUrhrlr r r r Ús. þ   ü  +