3 \ @sdZddlmZddlmZddlmZddlmZddlm Z dd l m Z m Z dd l Z e jd ZGd d d eZGdddeZGddde ZdddZd S)a Abbreviation Extension for Python-Markdown ========================================== This extension adds abbreviation handling to Python-Markdown. Simple Usage: >>> import markdown >>> text = """ ... Some text with an ABBR and a REF. Ignore REFERENCE and ref. ... ... *[ABBR]: Abbreviation ... *[REF]: Abbreviation Reference ... """ >>> print markdown.markdown(text, ['abbr'])

Some text with an ABBR and a REF. Ignore REFERENCE and ref.

Copyright 2007-2008 * [Waylan Limberg](http://achinghead.com/) * [Seemant Kulleen](http://www.kulleen.org/) )absolute_import)unicode_literals) Extension) Preprocessor)Pattern)etree AtomicStringNz,[*]\[(?P[^\]]*)\][ ]?:\s*(?P.*)c���������������@���s���e�Zd�ZdZdd�ZdS�) AbbrExtensionz- Abbreviation Extension for Python-Markdown. c�������������C���s���|j�jdt|d�dS�)z7 Insert AbbrPreprocessor before ReferencePreprocessor. abbrz <referenceN) preprocessorsaddAbbrPreprocessor)selfmd md_globals�r���%build/lib/markdown/extensions/abbr.pyextendMarkdown(���s����zAbbrExtension.extendMarkdownN)__name__ __module__ __qualname____doc__r���r���r���r���r���r ���%���s���r ���c���������������@���s ���e�Zd�ZdZdd�Zdd�ZdS�)r���z= Abbreviation Preprocessor - parse text for abbr references. c�������������C���sh���g�}x^|D�]V}t�j|}|rV|jdj�}|jdj�}t|�j|||�jjd|�<�q |j|�q W�|S�)z Find and remove all Abbreviation references from the text. Each reference is set as a new AbbrPattern in the markdown instance. r ���titlezabbr-%s) ABBR_REF_REmatchgroupstrip AbbrPattern_generate_patternmarkdowninlinePatternsappend)r���linesnew_textlinemr ���r���r���r���r���run0���s����  zAbbrPreprocessor.runc�������������C���s<���t�|}x$tt|D�]}d||��||<�qW�ddj|�S�)a �� Given a string, returns an regex pattern to match that string. 'HTML' -> r'(?P<abbr>[H][T][M][L])' Note: we force each char as a literal match (in brackets) as we don't know what they will be beforehand. z[%s]z(?P<abbr>\b%s\b)�)listrangelenjoin)r���textcharsir���r���r���r ���B���s���� z"AbbrPreprocessor._generate_patternN)r���r���r���r���r(���r ���r���r���r���r���r���-���s���r���c�������������������s(���e�Zd�ZdZ�fddZdd�Z��ZS�)r���z Abbreviation inline pattern. c����������������s���t�t|�j|�||�_d�S�)N)superr���__init__r���)r���patternr���) __class__r���r���r2���U���s����zAbbrPattern.__init__c�������������C���s,���t�jd}t|jd|_|jd|�j�|S�)Nr ���r���)r ���Elementr ���r���r.���setr���)r���r'���r ���r���r���r��� handleMatchY���s���� zAbbrPattern.handleMatch)r���r���r���r���r2���r7��� __classcell__r���r���)r4���r���r���R���s��� r���c�������������C���s ���t�|�dS�)N)configs)r ���)r9���r���r���r��� makeExtension_���s����r:���)N)r��� __future__r���r���r)���r���r ���r���inlinepatternsr���utilr ���r ���recompiler���r ���r���r���r:���r���r���r���r���<module>���s���      %