ó
Šç\c @@ sþ d 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 Z d d l Z d d l
Z
e j d
ƒ Z e j d ƒ Z d „ Z d
„ Z d „ Z d „ Z d e f d „ ƒ YZ d e f d „ ƒ YZ d d „ Z d S( uŽ
HeaderID Extension for Python-Markdown
======================================
Auto-generate id attributes for HTML headers.
Basic usage:
>>> import markdown
>>> text = "# Some Header #"
>>> md = markdown.markdown(text, ['headerid'])
>>> print md
All header IDs are unique:
>>> text = '''
... #Header
... #Header
... #Header'''
>>> md = markdown.markdown(text, ['headerid'])
>>> print md
To fit within a html template's hierarchy, set the header base level:
>>> text = '''
... #Some Header
... ## Next Level'''
>>> md = markdown.markdown(text, ['headerid(level=3)'])
>>> print md
Next Level
Works with inline markup.
>>> text = '#Some *Header* with [markup](http://example.com).'
>>> md = markdown.markdown(text, ['headerid'])
>>> print md
Turn off auto generated IDs:
>>> text = '''
... # Some Header
... # Another Header'''
>>> md = markdown.markdown(text, ['headerid(forceid=False)'])
>>> print md
Some Header
Another Header
Use with MetaData extension:
>>> text = '''header_level: 2
... header_forceid: Off
...
... # A Header'''
>>> md = markdown.markdown(text, ['headerid', 'meta'])
>>> print md
A Header
Copyright 2007-2011 [Waylan Limberg](http://achinghead.com/).
Project website:
Contact: markdown@freewisdom.org
License: BSD (see ../docs/LICENSE for details)
Dependencies:
* [Python 2.3+](http://python.org)
* [Markdown 2.0+](http://packages.python.org/Markdown/)
i ( t absolute_import( t unicode_literalsi ( t Extensioni ( t
Treeprocessor( t HTML_PLACEHOLDER_REt parseBoolValueNu MARKDOWNu ^(.*)_([0-9]+)$c C@ s_ t j d | ƒ j d d ƒ } t j d d | j d ƒ ƒ j ƒ j ƒ } t j d | | | ƒ S( u, Slugify a string, to make it URL friendly. u NFKDu asciiu ignoreu [^\w\s-]u u [%s\s]+( t unicodedatat normalizet encodet ret subt decodet stript lower( t valuet separator( ( s@ /usr/lib/python2.7/site-packages/markdown/extensions/headerid.pyt slugify[ s *c C@ s xk | | k s | rm t j | ƒ } | rZ d | j d ƒ t | j d ƒ ƒ d f } q d | d f } q W| j | ƒ | S( u@ Ensure id is unique in set of ids. Append '_1', '_2'... if not u %s_%di i ( t
IDCOUNT_REt matcht groupt intt add( t idt idst m( ( s@ /usr/lib/python2.7/site-packages/markdown/extensions/headerid.pyt uniqueb s /
c c@ sY | j r | j Vn x> | D]6 } x t | ƒ D] } | Vq. W| j r | j Vq q Wd S( uˆ Loop through all children and return text only.
Reimplements method of same name added to ElementTree in Python 2.7
N( t textt itertextt tail( t elemt et s( ( s@ /usr/lib/python2.7/site-packages/markdown/extensions/headerid.pyR n s
c @ s ‡ f d † } t j | | ƒ S( uC Extract raw HTML, reduce to plain text and swap with placeholder. c @ st y) ˆ j j t | j d ƒ ƒ \ } } Wn! t t f k
rL | j d ƒ SXˆ j ra | ra d St j d d | ƒ S( u&