/usr/lib/python2.6/site-packages/markdown/extensions
NameSizeModeActions
abbr.py28990644editdlrm
abbr.pyc42940644editdlrm
abbr.pyo42940644editdlrm
codehilite.py76730644editdlrm
codehilite.pyc81290644editdlrm
codehilite.pyo81290644editdlrm
def_list.py31700644editdlrm
def_list.pyc40470644editdlrm
def_list.pyo40470644editdlrm
extra.py17390644editdlrm
extra.pyc23230644editdlrm
extra.pyo23230644editdlrm
fenced_code.py34230644editdlrm
fenced_code.pyc43710644editdlrm
fenced_code.pyo43710644editdlrm
footnotes.py100550644editdlrm
footnotes.pyc114330644editdlrm
footnotes.pyo114330644editdlrm
headerid.py63260644editdlrm
headerid.pyc74700644editdlrm
headerid.pyo74700644editdlrm
html_tidy.py20710644editdlrm
html_tidy.pyc27560644editdlrm
html_tidy.pyo27560644editdlrm
imagelinks.py34910644editdlrm
imagelinks.pyc33110644editdlrm
imagelinks.pyo33110644editdlrm
meta.py25900644editdlrm
meta.pyc32750644editdlrm
meta.pyo32750644editdlrm
rss.py36930644editdlrm
rss.pyc43370644editdlrm
rss.pyo43370644editdlrm
tables.py30790644editdlrm
tables.pyc38770644editdlrm
tables.pyo38770644editdlrm
toc.py50980644editdlrm
toc.pyc44660644editdlrm
toc.pyo44660644editdlrm
wikilinks.py52920644editdlrm
wikilinks.pyc62810644editdlrm
wikilinks.pyo62810644editdlrm
__init__.py00644editdlrm
__init__.pyc1510644editdlrm
__init__.pyo1510644editdlrm
Edit: /usr/lib/python2.6/site-packages/markdown/extensions/abbr.py (2899B)
''' 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 ... """ >>> markdown.markdown(text, ['abbr']) u'

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/) ''' import markdown, re from markdown import etree # Global Vars ABBR_REF_RE = re.compile(r'[*]\[(?P[^\]]*)\][ ]?:\s*(?P.*)') class AbbrExtension(markdown.Extension): """ Abbreviation Extension for Python-Markdown. """ def extendMarkdown(self, md, md_globals): """ Insert AbbrPreprocessor before ReferencePreprocessor. """ md.preprocessors.add('abbr', AbbrPreprocessor(md), '<reference') class AbbrPreprocessor(markdown.preprocessors.Preprocessor): """ Abbreviation Preprocessor - parse text for abbr references. """ def run(self, lines): ''' Find and remove all Abbreviation references from the text. Each reference is set as a new AbbrPattern in the markdown instance. ''' new_text = [] for line in lines: m = ABBR_REF_RE.match(line) if m: abbr = m.group('abbr').strip() title = m.group('title').strip() self.markdown.inlinePatterns['abbr-%s'%abbr] = \ AbbrPattern(self._generate_pattern(abbr), title) else: new_text.append(line) return new_text def _generate_pattern(self, text): ''' 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. ''' chars = list(text) for i in range(len(chars)): chars[i] = r'[%s]' % chars[i] return r'(?P<abbr>\b%s\b)' % (r''.join(chars)) class AbbrPattern(markdown.inlinepatterns.Pattern): """ Abbreviation inline pattern. """ def __init__(self, pattern, title): markdown.inlinepatterns.Pattern.__init__(self, pattern) self.title = title def handleMatch(self, m): abbr = etree.Element('abbr') abbr.text = m.group('abbr') abbr.set('title', self.title) return abbr def makeExtension(configs=None): return AbbrExtension(configs=configs) if __name__ == "__main__": import doctest doctest.testmod()