
    bfW               
          d dl Zd dlmZmZmZ ddlmZ d ej        	                                D             Z
dedefdZd	edeeef         fd
Zdedeeeeef         f         fdZdeeee         f         deeeeef         f         deeef         deeef         fdZd	eeef         defdZd	eeef         defdZd	eeef         dee         fdZd	eeef         defdZdeeee         f         defdZdededededef
dZdedefdZd$dededefdZd ee         d!edee         fd"Zd%ded!edefd#ZdS )&    N)DictListOptional   )configc                 P    i | ]#\  }}|d k    t           j        j        |         |$S )nbsp)htmlentitiesname2codepoint).0kvs      ]/home/feoh/.local/pipx/venvs/mastodon-archive/lib/python3.11/site-packages/html2text/utils.py
<dictcomp>r      s9       1F{{ 	M #Q{{    tagreturnc                     | d         dk    r:t          |           dk    r'| d         }d|cxk     rdk    rn nt          |          S dS )Nr   h   r   09)lenint)r   ns     r   hnr      sO    
1v}}SQF>>>>c>>>>>q66M1r   stylec                 T    d d |                      d          D             D             S )z,
    :returns: A hash of css attributes
    c                     i | ]P\  }}|                                                                 |                                                                 QS  )striplower)r   xys      r   r   z&dumb_property_dict.<locals>.<dictcomp>   sR       Aq 	
		17799??,,  r   c                 B    g | ]}d |v |                     d d          S ):r   split)r   zs     r   
<listcomp>z&dumb_property_dict.<locals>.<listcomp>   s)    KKK#((QWWS!__(((r   ;r(   r   s    r   dumb_property_dictr.      s=     KKekk#.>.>KKK   r   datac                 R   | dz  } |                      d          }|dk    rG| d|         | |                      d|          dz   d         z   } |                      d          }|dk    Gd |                     d          D             }	 d	 |D             }n# t          $ r i }Y nw xY w|S )
z
    :type data: str

    :returns: A hash of css selectors, each of which contains a hash of
    css attributes.
    :rtype: dict
    r,   z@importr   r   Nc                 d    g | ]-}d |                                 v |                    d           .S ){)r"   r)   r   r$   s     r   r+   z#dumb_css_parser.<locals>.<listcomp>0   s4    GGGacQWWYY6F6FQWWS\\6F6F6Fr   }c                 X    i | ]'\  }}|                                 t          |          (S r!   )r"   r.   )r   abs      r   r   z#dumb_css_parser.<locals>.<dictcomp>2   s/    GGGAAGGII1!44GGGr   )findr)   
ValueError)r/   importIndexpairselementss       r   dumb_css_parserr>      s     	CKD))I&&K


AkM"T$))C*E*E*I*K*K%LLii	** 

 HG4::c??GGGEGGGGG    Os   B B$#B$attrs	style_defparent_stylec                 P   |                                 }d| v rU| d         J | d                                         D ]0}|                    d|z   i           }|                    |           1d| v r4| d         J 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.   )r?   r@   rA   r   	css_class	css_styleimmediate_styles          r   element_stylerK   9   s     E%W~)))w--// 	$ 	$I!cIor::ILL####%W~))),U7^<<_%%%Lr   c                 *    d| v r| d         }|dv rdS dS )zh
    Finds out whether this is an ordered or unordered list

    :type style: dict

    :rtype: str
    zlist-style-type)disccirclesquarenoneulolr!   )r   
list_styles     r   google_list_stylerT   T   s0     E!!,-
===44r   c                 
    d| v S )z
    Check if the style of the element has the 'height' attribute
    explicitly defined

    :type style: dict

    :rtype: bool
    heightr!   r-   s    r   google_has_heightrW   d   s     ur   c                     g }d| v r|                     | d                    d| v r|                     | d                    d| v r|                     | d                    |S )zk
    :type style: dict

    :returns: A list of all emphasis modifiers of the element
    :rtype: list
    ztext-decorationz
font-stylezfont-weight)append)r   emphasiss     r   google_text_emphasisr[   p   su     HE!!/0111ul+,,,m,---Or   c                 6    d}d| v r| d         }d|k    pd|k    S )zu
    Check if the css of the current element defines a fixed width font

    :type style: dict

    :rtype: bool
     zfont-familyzcourier newconsolasr!   )r   font_familys     r   google_fixed_width_fontr`      s3     KM*K'D:+DDr   c                 t    d| v r3| d         J 	 t          | d                   dz
  S # t          $ r Y nw xY wdS )zh
    Extract numbering from list element attributes

    :type attrs: dict

    :rtype: int or None
    startNr   r   )r   r:   )r?   s    r   list_numbering_startrc      sb     %W~)))	uW~&&** 	 	 	D	 1s   ( 
55para
wrap_linkswrap_list_itemswrap_tablesc                    |s!t           j                            |           rdS | dd         dk    s| d         dk    rdS |                                 }|dd         dk    r!t	          |          dk    r|d         dk    rd	S |dd
         dv r|dd         dk    s| S |s!t           j                            |           rdS t          t           j                            |          pt           j	                            |                    S )NTr      z    	r   z---Fr   )rk   *z**)
r   RE_LINKsearchlstripr   RE_TABLEboolRE_ORDERED_LIST_MATCHERmatchRE_UNORDERED_LIST_MATCHER)rd   re   rf   rg   strippeds        r   skipwraprv      s*   
  &.//55 t AaCyFd1goot {{}}H!}X!2!2x{c7I7Iu
 !}
""8AaC=D+@+@"""  6?11$77 t
 &,,X66 	<+11(;;  r   textc                 B    t           j                            d|           S )zU
    Escapes markdown-sensitive characters within other markdown
    constructs.
    \\\1)r   RE_MD_CHARS_MATCHERsub)rw   s    r   	escape_mdr|      s    
 %))'4888r   Fsnobc                 J   t           j                            d|           } |r t           j                            d|           } t           j                            d|           } t           j                            d|           } t           j                            d|           } | S )zO
    Escapes markdown-sensitive characters across whole document sections.
    ry   z\1\\\2)r   RE_MD_BACKSLASH_MATCHERr{   RE_MD_CHARS_MATCHER_ALLRE_MD_DOT_MATCHERRE_MD_PLUS_MATCHERRE_MD_DASH_MATCHER)rw   r}   s     r   escape_md_sectionr      s     )--gt<<D A-11'4@@#''	488D$((D99D$((D99DKr   linesright_marginc                 f  	 fd| d                              d          D             }t          |          }| D ]}d |                     d          D             }t          |          }||k     r|dg||z
  z  z  }n%||k     r|fd|||z
   d         D             z  }|}fdt          ||          D             }g }| D ]}d	 |                     d          D             }t          |                                          t          d
          k    rMd		fdt          ||          D             }|                    dd                    |          z   dz              d		fdt          ||          D             }|                    dd                    |          z   dz              |S )zR
    Given the lines of a table
    padds the cells and returns the new lines
    c                 X    g | ]&}t          |                                          z   'S r!   )r   rstripr   r$   r   s     r   r+   z"reformat_table.<locals>.<listcomp>   s,    MMMAQXXZZ</MMMr   r   |c                 6    g | ]}|                                 S r!   r   r4   s     r   r+   z"reformat_table.<locals>.<listcomp>        444q

444r   r]   c                 4    g | ]}t          |          z   S r!   )r   r   s     r   r+   z"reformat_table.<locals>.<listcomp>   s$    XXXA#a&&</XXXr   Nc                 V    g | ]%\  }}t          t          |          z   |          &S r!   )maxr   )r   r$   old_lenr   s      r   r+   z"reformat_table.<locals>.<listcomp>   s?     
 
 
4>AwCA%w//
 
 
r   c                 6    g | ]}|                                 S r!   r   r4   s     r   r+   z"reformat_table.<locals>.<listcomp>   r   r   z-|rk   c           	          g | ]A\  }}|                                 |t          |                                           z
  z  z   BS r!   r   r   r   r$   Mfillers      r   r+   z"reformat_table.<locals>.<listcomp>   R       Aq 

fC

OO(;<=  r   z|- c           	          g | ]A\  }}|                                 |t          |                                           z
  z  z   BS r!   r   r   s      r   r+   z"reformat_table.<locals>.<listcomp>  r   r   z| )r)   r   zipsetr"   rY   join)
r   r   	max_widthmax_colslinecolsnum_cols	new_linesnew_colsr   s
    `       @r   reformat_tabler      s3    NMMMq9L9LMMMI9~~H 
 
44DJJsOO444t99 hRDHx/00DD  XXXX8@S>T>V>V9WXXXXIH
 
 
 
BEdIBVBV
 
 
		
 I > >44DJJsOO444tzz||D		))F   i00  H TCHHX$6$66<====F   i00  H TCHHX$6$66<====r   c                 f   |                      d          }g }d}g }|D ]}t          j        |v rB| }|s<t          ||          }|                    |           g }|                    d           R|r|                    |           j|                    |           d                    |          S )z0
    Provide padding for tables in the text
    
Fr]   )r)   r   TABLE_MARKER_FOR_PADr   extendrY   r   )rw   r   r   table_buffertable_startedr   r   tables           r   pad_tables_in_textr     s     JJtELMI # #&$.. --M  %&|\BB  '''!  $$$ 	#%%%%T""""99Yr   )F)r   )html.entitiesr
   typingr   r   r   r]   r   	UNIFIABLEitemsunifiable_nstrr   r   r.   r>   rK   rT   rq   rW   r[   r`   rc   rv   r|   r   r   r   r!   r   r   <module>r      s/       ' ' ' ' ' ' ' ' ' '        &&((  C C    c d38n    # $sDcN':";    4Xc]"#Cc3h'( sCx. 
#s(^	   6T#s(^      	T#s(^ 	 	 	 	 	S#X 49    $E4S> Ed E E E ES(3-%7 8 S    $"
""26"EI"	" " " "J9C 9C 9 9 9 9 C t      )$s) )3 )49 ) ) ) )X   S    C            r   