| Server IP : 93.86.61.54 / Your IP : 216.73.216.156 Web Server : Apache/2.4.62 (Ubuntu) System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64 User : www-data ( 33) PHP Version : 8.4.22 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/lib/python3/dist-packages/reportlab/lib/__pycache__/ |
Upload File : |
o
Neb� � @ sz d Z dZddlZddlmZ dd� Zddd �Zd
d� Zedkr;ddl Z e j
d
d� Zes5ed� e �
d� ee� dS dS )a� Helps you output colourised code snippets in ReportLab documents.
Platypus has an 'XPreformatted' flowable for handling preformatted
text, with variations in fonts and colors. If Pygments is installed,
calling 'pygments2xpre' will return content suitable for display in
an XPreformatted object. If it's not installed, you won't get colours.
For a list of available lexers see http://pygments.org/docs/
)�
pygments2xpre� N)�StringIOc C s� | � dd�} | � dd�} | � dd�} | � dd�} |g d� D ]\}}| � d| d| �} t�d | d| | �} qt�d
d| �} | S )z<Helper to transform Pygments HTML output to ReportLab markupz<div class="highlight">� z</div>z<pre>z</pre>))�p�#000000)�nr )�errr z<span class="%s">z<span color="%s">z<span class="%s\s+.*">z<span class=".*">z<span color="#0f0f0f">)�replace�re�sub)�s�styles�k�c� r �=/usr/lib/python3/dist-packages/reportlab/lib/pygments2xpre.py�_2xpre s r �pythonc
C s� zddl m} ddlm} W n ty | Y S w ddlm} dd� }t� }||�}|� }|| |||� dd� |j� � D �} |t
|�� | ��S ) z(Return markup suitable for XPreformattedr )� highlight)�
HtmlFormatter)�get_lexer_by_namec S s | S )Nr )�xr r r �<lambda>$ s zpygments2xpre.<locals>.<lambda>c S sH g | ] \}\}}}|r|r|� d �r||�d�d �d�d �� f�qS )zcolor:�;r �:� )�
startswith�split�strip)�.0�cls�style�ttype�levelr r r �
<listcomp>+ s ��&�z!pygments2xpre.<locals>.<listcomp>)�pygmentsr �pygments.formattersr �ImportError�pygments.lexersr r �class2style�itemsr �getvalue)
r �languager r r �rconv�out�l�hr
r r r r s ��r c C s� ddl m}m}m} ddlm} |� d }|� d }|d�}g j}| D ]} ||| |d�� t| d��� }
t |
�}||||d�� q#|�
|j� td � d
S )z,Helper function - makes minimal PDF documentr )� Paragraph�SimpleDocTemplate�
XPreformatted)�getSampleStyleSheet�Title�Codezpygments2xpre.pdf)r! �rzsaved pygments2xpre.pdfN)
�reportlab.platypusr1 r2 r3 �reportlab.lib.stylesr4 �append�open�readr �build�__self__�print)� filenamesr1 r2 r3 r4 �styT�styC�doc�S�filename�src�fmtr r r �convertSourceFiles0 s
rH �__main__r z2usage: pygments2xpre.py file1.py [file2.py] [...])r )�__doc__�__all__r
�ior r r rH �__name__�sys�argvr@ r? �exitr r r r �<module> s
�