o
    7d9                     @   s   d Z ddlZ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 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 g dZedZG dd dZ	 dd Zdd ZdS )a  
Python Markdown

A Python implementation of John Gruber's Markdown.

Documentation: https://python-markdown.github.io/
GitHub: https://github.com/Python-Markdown/markdown/
PyPI: https://pypi.org/project/Markdown/

Started by Manfred Stienstra (http://www.dwerg.net/).
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
Currently maintained by Waylan Limberg (https://github.com/waylan),
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).

Copyright 2007-2018 The Python Markdown Project (v. 1.7 and later)
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
Copyright 2004 Manfred Stienstra (the original version)

License: BSD (see LICENSE.md for details).
    N   )util)build_preprocessors)build_block_parser)build_treeprocessors)build_inlinepatterns)build_postprocessors)	Extension)to_html_stringto_xhtml_string)BLOCK_LEVEL_ELEMENTS)MarkdownmarkdownmarkdownFromFileMARKDOWNc                   @   sp   e Zd ZdZdZeedZdd Zdd Z	dd	 Z
d
d Zdd Zdd Zdd Zdd Zdd ZdddZdS )r   zConvert Markdown to HTML.div)htmlxhtmlc                 K   s   | dd| _g d| _t | _g | _d| _d| _| 	  i | _
t | _| j| dg | di d | | d	d
 |   dS )ay  
        Creates a new Markdown instance.

        Keyword arguments:

        * `extensions`: A list of extensions.
            If an item is an instance of a subclass of `markdown.extension.Extension`, the  instance will be used
            as-is. If an item is of type string, first an entry point will be loaded. If that fails, the string is
            assumed to use Python dot notation (`path.to.module:ClassName`) to load a `markdown.Extension` subclass. If
            no class is specified, then a `makeExtension` function is called within the specified module.
        * `extension_configs`: Configuration settings for extensions.
        * `output_format`: Format of output. Supported formats are:
            * `xhtml`: Outputs XHTML style tags. Default.
            * `html`: Outputs HTML style tags.
        * `tab_length`: Length of tabs in the source. Default: 4

        
tab_length   )\`*_{}[]()>#+-.! T
extensionsZextension_configs)r'   configsoutput_formatr   N)getr   ZESCAPED_CHARSr   copyblock_level_elementsregisteredExtensionsZdocTypestripTopLevelTagsbuild_parser
referencesr   Z	HtmlStash	htmlStashregisterExtensionsset_output_formatreset)selfkwargs r7   dC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\markdown/core.py__init__4   s   



zMarkdown.__init__c                 C   s6   t | | _t| | _t| | _t| | _t| | _	| S )z* Build the parser from the various parts. )
r   preprocessorsr   parserr   ZinlinePatternsr   treeprocessorsr   postprocessors)r5   r7   r7   r8   r/   [   s   




zMarkdown.build_parserc                 C   s   |D ]=}t |tr| |||i }t |tr+||  td|jj	|jj
f  q|dur?td|jj	|jj
tj	tj
q| S )a  
        Register extensions with this instance of Markdown.

        Keyword arguments:

        * `extensions`: A list of extensions, which can either
           be strings or objects.
        * `configs`: A dictionary mapping extension names to `configs` options.

        z&Successfully loaded extension "%s.%s".Nz*Extension "{}.{}" must be of type: "{}.{}")
isinstancestrbuild_extensionr*   r	   ZextendMarkdownloggerdebug	__class__
__module____name__	TypeErrorformat)r5   r'   r(   extr7   r7   r8   r2   d   s&   


zMarkdown.registerExtensionsc           	   
      s$  t |} fddt D }|r|d  }|di |S d v r( ddn df\ }zt }td   W n t	yX } zd  }|f|j
dd	  |_
 d	}~ww |ret||di |S z	|jdi |W S  ty } z|j
d }d
 |f }|f|j
dd	  |_
 d	}~ww )a  
        Build extension from a string name, then return an instance.

        First attempt to load an entry point. The string name must be registered as an entry point in the
        `markdown.extensions` group which points to a subclass of the `markdown.extensions.Extension` class.
        If multiple distributions have registered the same name, the first one found is returned.

        If no entry point is found, assume dot notation (`path.to.module:ClassName`). Load the specified class and
        return an instance. If no class is specified, import the module and call a `makeExtension` function and return
        the `Extension` instance returned by that function.
        c                    s   g | ]	}|j  kr|qS r7   )name).0epext_namer7   r8   
<listcomp>   s    z,Markdown.build_extension.<locals>.<listcomp>r   :r   r&   z,Successfully imported extension module "%s".zFailed loading extension "%s".Nz%Failed to initiate extension '%s': %sr7   )dictr   Zget_installed_extensionsloadsplit	importlibimport_modulerA   rB   ImportErrorargsgetattrZmakeExtensionAttributeError)	r5   rM   r(   Zentry_pointsrH   
class_namemoduleemessager7   rL   r8   r@      s<    

zMarkdown.build_extensionc                 C   s   | j | | S )z# This gets called by the extension )r-   appendr5   	extensionr7   r7   r8   registerExtension   s   zMarkdown.registerExtensionc                 C   s6   | j   | j  | jD ]}t|dr|  q| S )zR
        Resets all state variables so that we can start with a new text.
        r4   )r1   r4   r0   clearr-   hasattrr^   r7   r7   r8   r4      s   



zMarkdown.resetc              
   C   s   |  d| _z
| j| j | _W | S  tyC } z%t| j }|  d| jdd	| d f }|f|j
dd  |_
 d}~ww )z/ Set the output format for the class instance. Z145z+Invalid Output Format: "%s". Use one of %s."z", "r   N)lowerrstripr)   output_formats
serializerKeyErrorlistkeyssortjoinrV   )r5   rG   r[   Zvalid_formatsr\   r7   r7   r8   r3      s    	zMarkdown.set_output_formatc                 C   s"   t |tr| d| jv S dS )z+Check if the tag is a block level HTML tag./F)r>   r?   rd   re   r,   )r5   tagr7   r7   r8   is_block_level   s   
zMarkdown.is_block_levelc              
   C   s^  |  sdS zt|}W n ty  } z| jd7  _ d}~ww |d| _| jD ]	}|| j| _q*| j	| j
 }| jD ]}||}|durM|}q@| |}| jrz!|d| j t| j d }|d| j }	|||	   }W n( ty } z|  d| j rd}n	td	|   |W Y d}~nd}~ww | jD ]}
|
|}q|  S )
a  
        Convert markdown to serialized XHTML or HTML.

        Keyword arguments:

        * `source`: Source text as a Unicode string.

        Markdown processing takes place in five steps:

        1. A bunch of `preprocessors` munge the input text.
        2. `BlockParser()` parses the high-level structural elements of the
           pre-processed text into an `ElementTree`.
        3. A bunch of `treeprocessors` are run against the `ElementTree`. One
           such `treeprocessor` runs `InlinePatterns` against the `ElementTree`,
           detecting inline markup.
        4. Some post-processors are run against the text after the `ElementTree`
           has been serialized into text.
        5. The output is written to a string.

        r&   z/. -- Note: Markdown only accepts Unicode input!N
z<%s>   z</%s>z<%s />z4Markdown failed to strip top-level tags. Document=%r)stripr?   UnicodeDecodeErrorreasonrR   linesr:   runr;   ZparseDocumentgetrootr<   rg   r.   indexdoc_taglenrindex
ValueErrorendswithr=   )r5   sourcer[   preprootZtreeprocessorZnewRootoutputstartendppr7   r7   r8   convert   sX   





zMarkdown.convertNc           	      C   s  |pd}|r$t |trtj|d|d}nt||}| }|  ntj }t |ts3|	|}|
d}| |}|rjt |trXtj|d|dd}|| |  | S t|}||dd}|| | S ||d}z
tjj| W | S  ty   tj| Y | S w )	aM  Converts a markdown file and returns the HTML as a Unicode string.

        Decodes the file using the provided encoding (defaults to `utf-8`),
        passes the file content to markdown, and outputs the html to either
        the provided stream or the file with provided name, using the same
        encoding as the source file. The `xmlcharrefreplace` error handler is
        used when encoding the output.

        **Note:** This is the only place that decoding and encoding of Unicode
        takes place in Python-Markdown.  (All other code is Unicode-in /
        Unicode-out.)

        Keyword arguments:

        * `input`: File object or path. Reads from `stdin` if `None`.
        * `output`: File object or path. Writes to `stdout` if `None`.
        * `encoding`: Encoding of input and output files. Defaults to `utf-8`.

        zutf-8r)modeencodingu   ﻿wxmlcharrefreplace)r   errors)r   )r>   r?   codecsopen	getreaderreadclosesysstdindecodelstripr   write	getwriterencodestdoutbufferrX   )	r5   inputr   r   Z
input_filetextr   Zoutput_filewriterr7   r7   r8   convertFile  sB   










zMarkdown.convertFile)NNN)rE   rD   __qualname____doc__ry   r
   r   rf   r9   r/   r2   r@   r`   r4   r3   ro   r   r   r7   r7   r7   r8   r   *   s     '	.Fr   c                 K   s   t di |}|| S )a  Convert a markdown string to HTML and return HTML as a Unicode string.

    This is a shortcut function for `Markdown` class to cover the most
    basic use case.  It initializes an instance of `Markdown`, loads the
    necessary extensions and runs the parser on the given text.

    Keyword arguments:

    * `text`: Markdown formatted text as Unicode or ASCII string.
    * Any arguments accepted by the Markdown class.

    Returns: An HTML document as a string.

    Nr7   )r   r   )r   r6   mdr7   r7   r8   r   i  s   
r   c                  K   s8   t di | }|| dd| dd| dd dS )a  Read markdown code from a file and write it to a file or a stream.

    This is a shortcut function which initializes an instance of `Markdown`,
    and calls the `convertFile` method rather than `convert`.

    Keyword arguments:

    * `input`: a file name or readable object.
    * `output`: a file name or writable object.
    * `encoding`: Encoding of input and output.
    * Any arguments accepted by the `Markdown` class.

    r   Nr   r   r7   )r   r   r*   )r6   r   r7   r7   r8   r   |  s
   

r   )r   r   r   loggingrS   r&   r   r:   r   Zblockprocessorsr   r<   r   Zinlinepatternsr   r=   r   r'   r	   Zserializersr
   r   r   __all__	getLoggerrA   r   r   r   r7   r7   r7   r8   <module>   s,    
  8	