Xc@s=dZdZddddfZddkZddkZddkZddkZddkZddklZl Z l Z l Z l Z e Z d ZeZeZd Zd Zeid Zd ZdZdZedZedeZedeZddfddffZdZdZdefdYZ de!fdYZ"de#fdYZ$ddk%Z%ddk&Z&ddk'Z'ddk(Z(ddk)Z)ddk*Z*ddk+Z+ddk,Z,e+i-Z.ddk/Z/dfd YZ0d!fd"YZ1gd#Z2d$Z3ge4ed%Z5e6e6ge6e4ed&Z7dS('s Python Markdown =============== Python Markdown converts Markdown to HTML and can be used as a library or called from the command line. ## Basic usage as a module: import markdown md = Markdown() html = md.convert(your_text_string) ## Basic use from the command line: markdown source.txt > destination.html Run "markdown --help" to see more options. ## Extensions See for more information and instructions on how to extend the functionality of Python Markdown. Read that before you try modifying this file. ## Authors and License Started by [Manfred Stienstra](http://www.dwerg.net/). Continued and maintained by [Yuri Takhteyev](http://www.freewisdom.org), [Waylan Limberg](http://achinghead.com/) and [Artem Yunusov](http://blog.splyer.com). Contact: markdown@freewisdom.org Copyright 2007, 2008 The Python Markdown Project (v. 1.7 and later) Copyright 200? Django Software Foundation (OrderedDict implementation) Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b) Copyright 2004 Manfred Stienstra (the original version) License: BSD (see docs/LICENSE for details). s2.0.1iiitFinaliN(tDEBUGtINFOtWARNtERRORtCRITICALitxhtml1s[HTML_REMOVED]sp|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|hr|hr/|style|li|dt|dd|thead|tbody|tr|th|tdtdivuusklzzwxh:s%stampu֐u߿uⴰu⵿cCsytid}|io2|i|||tjotidqun+|tjo t|nti |t dS(s. A wrapper method for logging debug messages. tMARKDOWNiN( tloggingt getLoggerthandlerstlogRtsystexittMarkdownExceptiontwarningstwarntMarkdownWarning(tlevelttexttlogger((s5/usr/lib/python2.6/site-packages/markdown/__init__.pytmessagegs    cCs ti|S(s+Check if the tag is a block level HTML tag.(tBLOCK_LEVEL_ELEMENTStmatch(ttag((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyt isBlockLevelust AtomicStringcBseZdZRS(s/A string which should not be further processed.(t__name__t __module__t__doc__(((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyR~sRcBseZdZRS(s A Markdown Exception. (RRR(((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyRsRcBseZdZRS(s A Markdown Warning. (RRR(((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyRstMarkdowncBsbeZdZgheedZdZdZdZdZ dZ ddddZ RS( sConvert Markdown to HTML.cCsU||_g|_d|_t|_ti|_ti||idd6t=i>d%6t?i@d&6t?i@d'6|_Ah|_BtiC|_D|iEd(|d)||iF||iGd*S(+s Creates a new Markdown instance. Keyword arguments: * extensions: A list of extensions. If they are of type string, the module mdx_name.py will be loaded. If they are a subclass of markdown.Extension, they will be used as-is. * extension-configs: Configuration setting for extensions. * safe_mode: Disallow raw html. One of "remove", "replace" or "escape". * output_format: Format of output. Supported formats are: * "xhtml1": Outputs XHTML 1.x. Default. * "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1). * "html4": Outputs HTML 4 * "html": Outputs latest supported version of HTML (currently HTML 4). Note that it is suggested that the more specific formats ("xhtml1" and "html4") be used as "xhtml" or "html" may change in the future if it makes sense at that time. tt html_blockt referencetemptytindenttcodet hashheadert setextheaderthrtolisttulisttquotet paragraphtbackticktescapetlinkt image_linktimage_referencetautolinktautomailtbrt linebreak2t linebreakthtmltentityt not_strongs strong,emt strong_emtstrongtemtemphasist emphasis2tinlinetprettifytraw_htmltamp_substitutethtml4txhtmlRt extensionstconfigsN(HtsafeModetregisteredExtensionstdocTypetTruetstripTopLevelTagstodictt OrderedDictt preprocessorstHtmlBlockPreprocessortReferencePreprocessort blockparsert BlockParsertparsertblockprocessorstEmptyBlockProcessortListIndentProcessortCodeBlockProcessortHashHeaderProcessortSetextHeaderProcessort HRProcessortOListProcessortUListProcessortBlockQuoteProcessortParagraphProcessortinlinePatternstinlinepatternstBacktickPatternt BACKTICK_REtSimpleTextPatternt ESCAPE_REtReferencePatternt REFERENCE_REt LinkPatterntLINK_REt ImagePatternt IMAGE_LINK_REtImageReferencePatterntIMAGE_REFERENCE_REtAutolinkPatternt AUTOLINK_REtAutomailPatternt AUTOMAIL_REtSubstituteTagPatterntLINE_BREAK_2_REt LINE_BREAK_REt HtmlPatterntHTML_REt ENTITY_REt NOT_STRONG_REtDoubleTagPatternt STRONG_EM_REtSimpleTagPatternt STRONG_REt EMPHASIS_REt EMPHASIS_2_REttreeprocessorstInlineProcessortPrettifyTreeprocessortpostprocessorstRawHtmlPostprocessortAndSubstitutePostprocessorRDtto_html_stringtetreettostringtoutput_formatst referencest HtmlStasht htmlStashtregisterExtensionstset_output_formattreset(tselfRFtextension_configst safe_modet output_format((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyt__init__sj         cCsx|D]y}t|tot||i|g}ny|i|tWqtj ottdt |qXqWdS(s+ Register extensions with this instance of Markdown. Keyword aurguments: * extensions: A list of extensions, which can either be strings or objects. See the docstring on Markdown. * configs: A dictionary mapping module names to config options. sCIncorrect type! Extension '%s' is neither a string or an Extension.N( t isinstancet basestringtload_extensiontgettextendMarkdowntglobalstAttributeErrorRRtrepr(RRFRGtext((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyR<s  cCs|ii|dS(s# This gets called by the extension N(RItappend(Rt extension((s5/usr/lib/python2.6/site-packages/markdown/__init__.pytregisterExtensionQscCs<|ii|iix|iD]}|iq$WdS(sR Resets all state variables so that we can start with a new text. N(RRRtclearRI(RR((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyRUs    cCsTy|i|i|_Wn3tj o'ttd||iifnXdS(s/ Set the output format for the class instance. s+Invalid Output Format: "%s". Use one of %s.N(Rtlowert serializertKeyErrorRRtkeys(Rtformat((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyR_s  c Cs|ipdSyt|}Wn!tj ottddSX|itditd}|iddiddd}ti dd|}|i t }|i d|_ x,|iiD]}|i|i |_ qW|ii|i i}x7|iiD]&}|i|}|o |}qqWti|i|d d \}}|ioK|id tttd }|id t} ||| !i}nx&|iiD]} | i|}qW|iS(s Convert markdown to serialized XHTML or HTML. Keyword arguments: * source: Source text as a Unicode string. usAUnicodeDecodeError: Markdown only accepts unicode or ascii input.R!s s s s s\n\s+\ntencodingtutf8s<%s>is(tstriptunicodetUnicodeDecodeErrorRRtreplacetSTXtETXtretsubt expandtabst TAB_LENGTHtsplittlinesROtvaluestrunRTt parseDocumenttgetrootRtcodecst utf_8_decodeRRLtindextDOC_TAGtlentrindexR( Rtsourcetpreptroott treeprocessortnewRoottoutputtlengthtstarttendtpp((s5/usr/lib/python2.6/site-packages/markdown/__init__.pytconvertgs<  "$ !cCs|pd}ti|ddd|}|i}|i|id}|i|}t|ttfo3ti|dd|}|i ||in|i |i |dS(sConverts a markdown file and returns the HTML as a unicode string. Decodes the file using the provided encoding (defaults to utf-8), passes the file content to markdown, and outputs the html to either the provided stream or the file with provided name, using the same encoding as the source file. **Note:** This is the only place that decoding and encoding of unicode takes place in Python-Markdown. (All other code is unicode-in / unicode-out.) Keyword arguments: * input: Name of source text file. * output: Name of output file. Writes to stdout if `None`. * encoding: Encoding of input and output files. Defaults to utf-8. sutf-8tmodetrRutwN( RtopentreadtclosetlstripRRtstrRtwritetencode(RtinputRRt input_fileRR8t output_file((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyt convertFiles    N( RRRtFalsetDEFAULT_OUTPUT_FORMATRRRRRRtNoneR(((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyR s    3t ExtensioncBs>eZdZhdZdZdZdZdZRS(s( Base class for extensions to subclass. cCs ||_dS(sCreate an instance of an Extention. Keyword arguments: * configs: A dict of configuration setting used by an Extension. N(tconfig(RRG((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyRscCs(||ijo|i|dSdSdS(s8 Return a setting for the given key or an empty string. iR!N(R(Rtkey((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyt getConfigscCs9g}|iiD]}|||i|dfq~S(s1 Return all config settings as a list of tuples. i(RR(Rt_[1]R((s5/usr/lib/python2.6/site-packages/markdown/__init__.pyt getConfigInfoscCs||i|d(sh     (              * *