U
    {h?                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ	 d dl
mZmZ d dlmZ d dlmZ dd	 Zd
d Zdd Zdd Zdd Zdd ZG dd dZdS )    N)render_children)DOM)HTML)BLOCK_KEY_NAMEHtmlToContentStateHandler)features)	check_urlc                 C   sL   |  d}i }|dk	r(d|d< ||d< nt|  d|d< td|| d S )	z:
    <a linktype="page" id="1">internal page link</a>
    idNpagelinktypeurlhrefachildren)getr   r   create_element)propsZid_Z
link_props r   w/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/admin/rich_text/converters/contentstate.pylink_entity   s    

r   c                 C   s"   | d d dkr| d S t dS )Nblocktypez
code-blockr   br)r   r   )r   r   r   r   r   !   s    r   c                 C   s   | d d }t d|  d S )Nr   r   z(Missing config for "%s". Deleting block.)loggingerrorr   type_r   r   r   block_fallback(   s    r   c                 C   s   | d d }t d|  d S )Nentityr   z(Missing config for "%s". Deleting entityr   warningr   r   r   r   entity_fallback.   s    r!   c                 C   s"   | d d }t d|  | d S )NZinline_style_rangestylez(Missing config for "%s". Deleting style.r   r   r   r   r   r   style_fallback4   s    r#   c                    sZ   t | tr4dd |  D }| d | di ni }i |   fdd}||d< |S )Nc                 S   s   i | ]\}}|d kr||qS )>   wrapperwrapper_propsr   ).0keyvaluer   r   r   
<dictcomp>?   s    z)persist_key_for_block.<locals>.<dictcomp>elementr   c              	      sj   t | d di}z" | }|d k	r0|j| |W S  tk
rd   | t || d  Y S X d S )Nr   r'   r   )r   r   attrupdate	TypeErrorr   r   )r   Zadded_propseltr*   Zelement_propsr   r   element_with_uuidL   s    
z0persist_key_for_block.<locals>.element_with_uuid)
isinstancedictitemsr   )configZ
new_configr0   r   r/   r   persist_key_for_block:   s    

r5   c                   @   s&   e Zd ZdddZdd Zdd ZdS )	ContentstateConverterNc                 C   s   || _ t|| _tdttddtidtit	dt
dgtjd}| j D ]p}td|}|d k	rJ|d }|d	 d
d |d	i  D  |d |di  |d |di  qJt|| _d S )Np)ZunstyledZatomicfallbackZFALLBACKz\n)Zstrategy	component)	block_map	style_mapentity_decoratorsZcomposite_decoratorsZenginecontentstateto_database_formatr:   c                 S   s   i | ]\}}|t |qS r   )r5   )r&   Z
block_typer4   r   r   r   r)   }   s    z2ContentstateConverter.__init__.<locals>.<dictcomp>r;   r<   )r   r   html_to_contentstate_handlerr5   r   r   r#   r!   recompiler   r   STRINGfeature_registryZget_converter_ruler,   r   r3   HTMLExporterexporter)selfr   Zexporter_configfeatureruleZfeature_configr   r   r   __init___   sF    
  
 
zContentstateConverter.__init__c                 C   s2   | j   | j | | j   | j jjdddS )N   ),z: )indent
separators)r?   resetfeedcloser=   Zas_json)rF   htmlr   r   r   from_database_format   s    

 z*ContentstateConverter.from_database_formatc                 C   s   | j t|S )N)rE   renderjsonloads)rF   Zcontentstate_jsonr   r   r   r>      s    z(ContentstateConverter.to_database_format)N)__name__
__module____qualname__rI   rR   r>   r   r   r   r   r6   ^   s   
,	r6   )rT   r   r@   Zdraftjs_exporter.defaultsr   Zdraftjs_exporter.domr   Zdraftjs_exporter.htmlr   rD   Z7wagtail.admin.rich_text.converters.html_to_contentstater   r   Zwagtail.rich_textr   rC   Zwagtail.whitelistr   r   r   r   r!   r#   r5   r6   r   r   r   r   <module>   s   $