U
    uh                     @   s   d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZmZmZ d dlmZ G dd dZ dS )    )groupby)
attrgetter)ListOptionalTuple)Command)render_decoratorsshould_render_decorators)	BLOCK_MAP	STYLE_MAP)DOM)EntityState)Options)
StyleState)BlockConfigContentStateElement	EntityMap)WrapperStatec                   @   s   e Zd ZdZdZdee ddddZdee e	ddd	Z
eeeed
ddZeeee	ee f  dddZeee dddZdS )HTMLzu
    Entry point of the exporter. Combines entity, wrapper and style state
    to generate the right HTML nodes.
    )composite_decoratorsentity_optionsblock_optionsstyle_optionsN)configreturnc                 C   sn   |d kri }| dg | _t| di | _t| dt| _t| dt	| _
t| dtj d S )Nr   Zentity_decoratorsZ	block_map	style_mapZengine)getr   r   Zmap_entitiesr   Z
map_blocksr
   r   Z
map_stylesr   r   r   ZuseSTRING)selfr    r!   ]/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/draftjs_exporter/html.py__init__&   s    zHTML.__init__)content_stater   c           
      C   s   |dkri }| dg }t| j|}t }| di }d}|D ]F}d|krT|d nd}| |||}	||krr|}|dkr@t||	 q@|dkr|j dkrt||j	 j
 t|S )zN
        Starts the export process on a given piece of content state.
        NblocksZ	entityMapr   depth)r   r   r   r   create_elementrender_blockappend_childstacklengthtaileltrender)
r    r$   r%   wrapper_stateZdocument
entity_mapZ	min_depthblockr&   r-   r!   r!   r"   r.   2   s"    zHTML.render)r1   r0   r/   r   c                 C   sH  d|ko|d }d|ko|d }t | j|d }|s:|rt }t| j|}|r\t| jnd }	| |D ]\}
}|D ]}|	| |	rv|		| qv|r|
 rt| j|
||j}n|
}|	r|	|||j}n|}||||j}|d k	rjt|| ||krj|
 rjt|| qjn&|r4t| j|d ||j}n|d }|||S )NZinlineStyleRangesZentityRangestext)r	   r   r   r'   r   r   r   r   build_command_groupsapplyZhas_no_entityr   r%   Zrender_stylesZrender_entitiesr)   Zelement_for)r    r1   r0   r/   Z
has_stylesZhas_entitiesZhas_decoratorscontentZentity_stateZstyle_stater2   commandscommandZdecorated_nodeZstyled_nodeZentity_noder!   r!   r"   r(   Q   s`     

    zHTML.render_block)r1   r   c                 C   s   |d }|  |}t|td}tt|td}g }d}|D ]^\}}	|t|d k r||d  d }
||||
 t|	f n|dt|	f |d7 }q>|S )zv
        Creates block modification commands, grouped by start index,
        with the text to apply them on.
        r2   indexr       )build_commandsr   r   listlenappend)r    r1   r2   r6   groupedZlistedZslicedistart_indexZcomms
stop_indexr!   r!   r"   r3      s    

zHTML.build_command_groupsc                 C   sP   t |}t |}|| }|jtdd t ddg| t dt|d g S )z
        Build all of the manipulation commands for a given block.
        - One pair to set the text.
        - Multiple pairs for styles.
        - Multiple pairs for entities.
        r8   )key
start_textr   Z	stop_textr2   )r   Zfrom_style_rangesZfrom_entity_rangessortr   r=   )r    r1   Zstyle_commandsZentity_commandsZstyles_and_entitiesr!   r!   r"   r;      s    


zHTML.build_commands)N)N)__name__
__module____qualname____doc__	__slots__r   r   r#   r   strr.   r   r   r   r   r(   r   r   r   r3   r;   r!   r!   r!   r"   r      s      < r   N)!	itertoolsr   operatorr   typingr   r   r   Zdraftjs_exporter.commandr   Z%draftjs_exporter.composite_decoratorsr   r	   Zdraftjs_exporter.defaultsr
   r   Zdraftjs_exporter.domr   Zdraftjs_exporter.entity_stater   Zdraftjs_exporter.optionsr   Zdraftjs_exporter.style_stater   Zdraftjs_exporter.typesr   r   r   r   r   Zdraftjs_exporter.wrapper_stater   r   r!   r!   r!   r"   <module>   s   