Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
proc
/
thread-self
/
root
/
usr
/
lib
/
python2.7
/
site-packages
/
markdown
/
extensions
/
File Content:
headerid.pyo
� �(�Sc @@ 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 <h1 id="some-header">Some Header</h1> All header IDs are unique: >>> text = ''' ... #Header ... #Header ... #Header''' >>> md = markdown.markdown(text, ['headerid']) >>> print md <h1 id="header">Header</h1> <h1 id="header_1">Header</h1> <h1 id="header_2">Header</h1> 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 <h3 id="some-header">Some Header</h3> <h4 id="next-level">Next Level</h4> Works with inline markup. >>> text = '#Some *Header* with [markup](http://example.com).' >>> md = markdown.markdown(text, ['headerid']) >>> print md <h1 id="some-header-with-markup">Some <em>Header</em> with <a href="http://example.com">markup</a>.</h1> Turn off auto generated IDs: >>> text = ''' ... # Some Header ... # Another Header''' >>> md = markdown.markdown(text, ['headerid(forceid=False)']) >>> print md <h1>Some Header</h1> <h1>Another Header</h1> Use with MetaData extension: >>> text = '''header_level: 2 ... header_forceid: Off ... ... # A Header''' >>> md = markdown.markdown(text, ['headerid', 'meta']) >>> print md <h2>A Header</h2> Copyright 2007-2011 [Waylan Limberg](http://achinghead.com/). Project website: <http://packages.python.org/Markdown/extensions/header_id.html> 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>