
    Mi                        % S SK Jr  S SKJrJrJr  S SKrS SKrS SKJ	r	  S SK
Jr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  SS jrSrS\S'   SS/rS\S'   SS jr       S                 SS jjrg)    )annotations)IOAnyOptionalN)	Extension)Element)read_txt_file)FileType)exactly_one)get_last_modified_date)partition_htmlstrc                R    [        U [        5      (       a  U R                  S5      $ U $ )Nzutf-8)
isinstancebytesdecode)contentss    s/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/partition/md.pyoptional_decoder      s#    (E""w''O    mdDETECTION_ORIGINtablesfenced_codez	list[str]_DEFAULT_MARKDOWN_EXTENSIONSc                   [        U [        5      (       d"  [        S[        U 5      R                  < 35      eU  HC  n[        U[
        [        45      (       a  M   [        S[        U5      R                   SU< 35      e   U $ )a  Return ``extensions`` if it is a list of strings and/or ``Extension`` instances.

Python-Markdown accepts extension entry points as registered names (``str``) or configured
``Extension`` instances; both are supported here. Any other shape raises ``ValueError``.
zi'extensions' must be a list of extension names (str) and/or markdown.extensions.Extension instances, got zXEach entry in 'extensions' must be a str or markdown.extensions.Extension instance, got z: )r   list
ValueErrortype__name__r   r   )
extensionsitems     r   _validate_markdown_extensionsr#      s     j$''<<@<L<U<U;XZ
 	
 $i 011!!%d!4!4 5RxA   r   c                   Uc  Sn[        XX#S9  U (       a  [        U 5      OSnU b  [        U S9u  pOUb  [        US9u  pOUb  [        R                  " U5      n
U
R
                  (       d  [        SU
R                   35      eU
R                  R	                  SS5      nUR                  S5      (       d  [        S	U S
35      eU
R                  n[        UR                  S[        5      5      n[        R                  " X,S9nUU=(       d    U [        R                   U=(       d    U["        S.UEnUb  XnS'   [%        S0 UD6$ )a  Partitions a markdown file into its constituent elements

Parameters
----------
filename
    A string defining the target filename path.
file
    A file-like object using "rb" mode --> open(filename, "rb").
text
    The string representation of the markdown document.
url
    The URL of a webpage to parse. Only for URLs that return a markdown document.
metadata_last_modified
    The last modified date for the document.
languages
    The languages present in the document. Use ``["auto"]`` to detect (default when None).
    Use ``[""]`` to disable language detection.

Other keyword arguments are forwarded to ``partition_html``. In addition, ``extensions`` may be
passed to ``markdown.markdown()`` as a list of registered extension names (``str``) and/or
configured ``markdown.extensions.Extension`` instances. The default is
``["tables", "fenced_code"]``. Pass e.g. ``extensions=["tables"]`` if you need the legacy
behavior where ``#`` inside unfenced content is parsed as a heading (see #4006).
N )filenamefiletexturl)r&   )r'   zURL return an error: zContent-Typeztext/markdownz)Expected content type text/markdown. Got .r!   )r!   )r(   metadata_filenamemetadata_file_typemetadata_last_modifieddetection_origin	languages )r   r   r	   requestsgetokr   status_codeheaders
startswithr(   r#   popr   markdownr
   MDr   r   )r&   r'   r(   r)   r+   r-   r/   kwargslast_modified_responsecontent_typer!   htmlhtml_kwargss                  r   partition_mdrA   0   sN   D | 4A8@*84dM24		T*4	<<${{4X5I5I4JKLL''++NB?&&77;L>K  }} /

<!=>J T9D .:(&kk"8"IM,# #K #,K (K((r   )r   zstr | bytesreturnr   )r!   r   rB   z	list[Any])NNNNNNN)r&   
str | Noner'   zIO[bytes] | Noner(   rC   r)   rC   r+   rC   r-   rC   r/   zOptional[list[str]]r:   r   rB   zlist[Element])
__future__r   typingr   r   r   r8   r1   markdown.extensionsr   unstructured.documents.elementsr    unstructured.file_utils.encodingr	   unstructured.file_utils.modelr
   $unstructured.partition.common.commonr   &unstructured.partition.common.metadatar   unstructured.partition.htmlr   r   r   __annotations__r   r#   rA   r0   r   r   <module>rN      s    " $ $   ) 3 : 2 < I 6  # +3]*C i C*  !$()-%)N)N)
N) N) 
	N)
 "N) 'N) #N) N) N)r   