mistune-0.7.1/0000755000076500000240000000000012566114341014011 5ustar lepturestaff00000000000000mistune-0.7.1/CHANGES.rst0000644000076500000240000000621412566112430015613 0ustar lepturestaff00000000000000Changelog ---------- Here is the full history of mistune. Version 0.7.1 ~~~~~~~~~~~~~ Released on Aug. 22, 2015 * Fix inline html when there is no content per `#71`_. .. _`#71`: https://github.com/lepture/mistune/issues/71 Version 0.7 ~~~~~~~~~~~ Released on Jul. 18, 2015 * Fix the breaking change in version 0.6 with options: **parse_inline_html** and **parse_block_html** * Breaking change: remove **parse_html** option for explicit * Change option **escape** default value to ``True`` for security reason Version 0.6 ~~~~~~~~~~~ Released on Jun. 17, 2015 * Breaking change on inline HTML, text in inline HTML will not be parsed per `#38`_. * Replace **tag** renderer with **inline_html** for breaking change on inline HTML * Double emphasis, emphasis, code, and strikethrough can contain one linebreak per `#48`_. * Match autolinks that do not have / in their URI via `#53`_. * A work around on link that contains ``)`` per `#46`_. * Add ```` tag for inline tags per `#55`_. .. _`#38`: https://github.com/lepture/mistune/issues/38 .. _`#46`: https://github.com/lepture/mistune/issues/46 .. _`#48`: https://github.com/lepture/mistune/issues/48 .. _`#53`: https://github.com/lepture/mistune/pull/53 .. _`#55`: https://github.com/lepture/mistune/issues/55 Version 0.5.1 ~~~~~~~~~~~~~ Released on Mar. 10, 2015 * Fix a bug when list item is blank via `ipython#7929`_. * Use python-wheels to build wheels for Mac. .. _`ipython#7929`: https://github.com/ipython/ipython/issues/7929 Version 0.5 ~~~~~~~~~~~ Released on Dec. 5, 2014. This release will break things. * For custom lexers, **features** is replaced with **rules**. * Refactor on function names and codes. * Add a way to output the render tree via `#20`_. * Fix emphasis and strikethrough regular expressions. .. _`#20`: https://github.com/lepture/mistune/pull/20 Version 0.4.1 ~~~~~~~~~~~~~ Released on Oct. 12, 2014 * Add option for parse markdown in block level html. * Fix on lheading, any number of underline = or - will work. * Patch for setup if Cython is available but no C compiler. Version 0.4 ~~~~~~~~~~~ Released on Aug. 14, 2014 * Bugfix. Use inspect to detect renderer class. * Move all meth:`escape` to renderer. Use renderer to escape everything. * A little changes in code style and parameter naming. * Don't parse text in a block html, behave like sundown. Version 0.3.1 ~~~~~~~~~~~~~ Released on Jul. 31, 2014 * Fix in meth:`Renderer.block_code`, no need to add ``\n`` in ````. * Trim whitespace of code in code span via `#15`_. .. _`#15`: https://github.com/lepture/mistune/issues/15 Version 0.3 ~~~~~~~~~~~ Released on Jun. 27, 2014 * Add ``
`` in footnotes renderer * Add hard_wrap configuration for GFM linebreaks. * Add text renderer, via `#9`_. * Define features for lexers available via `#11`_. .. _`#9`: https://github.com/lepture/mistune/pull/9 .. _`#11`: https://github.com/lepture/mistune/pull/11 Version 0.2 ~~~~~~~~~~~ Released on Mar. 12, 2014 * Use tuple instead of list for efficient * Add ``line_match`` and ``line_started`` property on InlineLexer, via `#4`_ .. _`#4`: https://github.com/lepture/mistune/pull/4 Version 0.1 ~~~~~~~~~~~ First preview release. mistune-0.7.1/LICENSE0000644000076500000240000000271212461416154015021 0ustar lepturestaff00000000000000Copyright (c) 2014 - 2015, Hsiaoming Yang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the creator nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. mistune-0.7.1/Makefile0000644000076500000240000000127712477527455015477 0ustar lepturestaff00000000000000.PHONY: clean-pyc clean-build docs test: @nosetests -s bench: @python tests/bench.py coverage: @rm -f .coverage @nosetests --with-coverage --cover-package=mistune --cover-html clean: clean-build clean-pyc clean-docs clean-build: @rm -fr build/ @rm -fr dist/ @rm -fr *.egg-info @rm -f mistune.c @rm -fr cover/ clean-pyc: @find . -name '*.pyc' -exec rm -f {} + @find . -name '*.pyo' -exec rm -f {} + @find . -name '*~' -exec rm -f {} + @find . -name '__pycache__' -exec rm -fr {} + clean-docs: @rm -fr docs/_build docs: @$(MAKE) -C docs html rtd: curl -X POST http://readthedocs.org/build/mistune publish: @twine upload dist/*.tar.gz @twine upload dist/*.whl .PHONY: build mistune-0.7.1/MANIFEST.in0000644000076500000240000000023012477732622015553 0ustar lepturestaff00000000000000include Makefile LICENSE README.rst CHANGES.rst exclude mistune.c recursive-include tests * recursive-exclude tests *.pyc recursive-exclude tests *.pyo mistune-0.7.1/mistune.egg-info/0000755000076500000240000000000012566114341017167 5ustar lepturestaff00000000000000mistune-0.7.1/mistune.egg-info/dependency_links.txt0000644000076500000240000000000112566114336023241 0ustar lepturestaff00000000000000 mistune-0.7.1/mistune.egg-info/not-zip-safe0000644000076500000240000000000112540211353021406 0ustar lepturestaff00000000000000 mistune-0.7.1/mistune.egg-info/PKG-INFO0000644000076500000240000002356512566114336020303 0ustar lepturestaff00000000000000Metadata-Version: 1.1 Name: mistune Version: 0.7.1 Summary: The fastest markdown parser in pure Python Home-page: https://github.com/lepture/mistune Author: Hsiaoming Yang Author-email: me@lepture.com License: BSD Description: Mistune ======= The fastest markdown parser in pure Python with renderer features, inspired by marked_. .. image:: https://img.shields.io/pypi/wheel/mistune.svg?style=flat :target: https://pypi.python.org/pypi/mistune/ :alt: Wheel Status .. image:: https://img.shields.io/pypi/v/mistune.svg :target: https://pypi.python.org/pypi/mistune/ :alt: Latest Version .. image:: https://travis-ci.org/lepture/mistune.svg?branch=master :target: https://travis-ci.org/lepture/mistune :alt: Travis CI Status .. image:: https://coveralls.io/repos/lepture/mistune/badge.svg?branch=master :target: https://coveralls.io/r/lepture/mistune :alt: Coverage Status .. image:: https://ci.appveyor.com/api/projects/status/8ai8tfwp75oela17?svg=true :target: https://ci.appveyor.com/project/lepture/mistune :alt: App Veyor CI Status .. _marked: https://github.com/chjj/marked Features -------- * **Pure Python**. Tested in Python 2.6+, Python 3.3+ and PyPy. * **Very Fast**. It is the fastest in all **pure Python** markdown parsers. * **More Features**. Table, footnotes, autolink, fenced code etc. View the `benchmark results `_. Installation ------------ Installing mistune with pip:: $ pip install mistune Mistune can be faster, if you compile with cython:: $ pip install cython mistune Basic Usage ----------- A simple API that render a markdown formatted text: .. code:: python import mistune mistune.markdown('I am using **mistune markdown parser**') # output:

I am using mistune markdown parser

If you care about performance, it is better to re-use the Markdown instance: .. code:: python import mistune markdown = mistune.Markdown() markdown('I am using **mistune markdown parser**') Mistune has enabled all features by default. You don't have to configure anything. But there are options for you to change the parser behaviors. Options ------- Here is a list of all options that will affect the rendering results, configure them with ``mistune.Renderer``: .. code:: python renderer = mistune.Renderer(escape=True, hard_wrap=True) # use this renderer instance markdown = mistune.Markdown(renderer=renderer) markdown(text) * **escape**: if set to *False*, all raw html tags will not be escaped. * **hard_wrap**: if set to *True*, it will has GFM line breaks feature. All new lines will be replaced with ``
`` tag * **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``
``. * **parse_block_html**: parse text only in block level html. * **parse_inline_html**: parse text only in inline level html. When using the default renderer, you can use one of the following shortcuts:: mistune.markdown(text, escape=True, hard_wrap=True) markdown = mistune.Markdown(escape=True, hard_wrap=True) markdown(text) Renderer -------- Like misaka/sundown, you can influence the rendering by custom renderers. All you need to do is subclassing a `Renderer` class. Here is an example of code highlighting: .. code:: python import mistune from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter class HighlightRenderer(mistune.Renderer): def block_code(self, code, lang): if not lang: return '\n
%s
\n' % \ mistune.escape(code) lexer = get_lexer_by_name(lang, stripall=True) formatter = HtmlFormatter() return highlight(code, lexer, formatter) renderer = HighlightRenderer() markdown = mistune.Markdown(renderer=renderer) print(markdown('```python\nassert 1 == 1\n```')) Find more renderers in `mistune-contrib`_. Block Level ~~~~~~~~~~~ Here is a list of block level renderer API:: block_code(code, language=None) block_quote(text) block_html(html) header(text, level, raw=None) hrule() list(body, ordered=True) list_item(text) paragraph(text) table(header, body) table_row(content) table_cell(content, **flags) The *flags* tells you whether it is header with ``flags['header']``. And it also tells you the align with ``flags['align']``. Span Level ~~~~~~~~~~ Here is a list of span level renderer API:: autolink(link, is_email=False) codespan(text) double_emphasis(text) emphasis(text) image(src, title, alt_text) linebreak() newline() link(link, title, content) strikethrough(text) text(text) inline_html(text) Footnotes ~~~~~~~~~ Here is a list of renderers related to footnotes:: footnote_ref(key, index) footnote_item(key, text) footnotes(text) Lexers ------ Sometimes you want to add your own rules to Markdown, such as GitHub Wiki links. You can't achieve this goal with renderers. You will need to deal with the lexers, it would be a little difficult for the first time. We will take an example for GitHub Wiki links: ``[[Page 2|Page 2]]``. It is an inline grammar, which requires custom ``InlineGrammar`` and ``InlineLexer``: .. code:: python import copy from mistune import Renderer, InlineGrammar, InlineLexer class WikiLinkRenderer(Renderer): def wiki_link(self, alt, link): return '%s' % (link, alt) class WikiLinkInlineLexer(InlineLexer): def enable_wiki_link(self): # add wiki_link rules self.rules.wiki_link = re.compile( r'\[\[' # [[ r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2 r'\]\](?!\])' # ]] ) # Add wiki_link parser to default rules # you can insert it some place you like # but place matters, maybe 3 is not good self.default_rules.insert(3, 'wiki_link') def output_wiki_link(self, m): text = m.group(1) alt, link = text.split('|') # you can create an custom render # you can also return the html if you like return self.renderer.wiki_link(alt, link) You should pass the inline lexer to ``Markdown`` parser: .. code:: python renderer = WikiLinkRenderer() inline = WikiLinkInlineLexer(renderer) # enable the feature inline.enable_wiki_link() markdown = Markdown(renderer, inline=inline) markdown('[[Link Text|Wiki Link]]') It is the same with block level lexer. It would take a while to understand the whole mechanism. But you won't do the trick a lot. Contribution & Extensions ------------------------- Mistune itself doesn't accept any extension. It will always be a simple one file script. If you want to add features, you can head over to `mistune-contrib`_. Here are some extensions already in `mistune-contrib`_: * Math/MathJax features * Highlight Code Renderer * TOC table of content features * MultiMarkdown Metadata parser Get inspired with the contrib repository. .. _`mistune-contrib`: https://github.com/lepture/mistune-contrib Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Text Processing :: Markup Classifier: Topic :: Software Development :: Libraries :: Python Modules mistune-0.7.1/mistune.egg-info/SOURCES.txt0000644000076500000240000001074212566114340021056 0ustar lepturestaff00000000000000CHANGES.rst LICENSE MANIFEST.in Makefile README.rst mistune.py setup.cfg setup.py mistune.egg-info/PKG-INFO mistune.egg-info/SOURCES.txt mistune.egg-info/dependency_links.txt mistune.egg-info/not-zip-safe mistune.egg-info/top_level.txt tests/bench.py tests/test_cases.py tests/test_extra.py tests/test_subclassing.py tests/fixtures/data/math-paragraph.md tests/fixtures/data/math.md tests/fixtures/data/tree.md tests/fixtures/extra/autolink_lines.html tests/fixtures/extra/autolink_lines.text tests/fixtures/extra/blockquote_list_item.html tests/fixtures/extra/blockquote_list_item.text tests/fixtures/extra/case_insensitive_refs.html tests/fixtures/extra/case_insensitive_refs.text tests/fixtures/extra/double_link.html tests/fixtures/extra/double_link.text tests/fixtures/extra/escaped_angles.html tests/fixtures/extra/escaped_angles.text tests/fixtures/extra/footnotes.html tests/fixtures/extra/footnotes.text tests/fixtures/extra/gfm_code.html tests/fixtures/extra/gfm_code.text tests/fixtures/extra/gfm_code_hr_list.html tests/fixtures/extra/gfm_code_hr_list.text tests/fixtures/extra/gfm_del.html tests/fixtures/extra/gfm_del.text tests/fixtures/extra/gfm_em.html tests/fixtures/extra/gfm_em.text tests/fixtures/extra/gfm_links.html tests/fixtures/extra/gfm_links.text tests/fixtures/extra/gfm_tables.html tests/fixtures/extra/gfm_tables.text tests/fixtures/extra/gfm_tables_uneven.html tests/fixtures/extra/gfm_tables_uneven.text tests/fixtures/extra/hr_list_break.html tests/fixtures/extra/hr_list_break.text tests/fixtures/extra/lazy_blockquotes.html tests/fixtures/extra/lazy_blockquotes.text tests/fixtures/extra/list_item_text.html tests/fixtures/extra/list_item_text.text tests/fixtures/extra/loose_lists.html tests/fixtures/extra/loose_lists.text tests/fixtures/extra/main.html tests/fixtures/extra/main.text tests/fixtures/extra/nested_code.html tests/fixtures/extra/nested_code.text tests/fixtures/extra/nested_em.html tests/fixtures/extra/nested_em.text tests/fixtures/extra/nested_square_link.html tests/fixtures/extra/nested_square_link.text tests/fixtures/extra/not_a_link.html tests/fixtures/extra/not_a_link.text tests/fixtures/extra/ref_paren.html tests/fixtures/extra/ref_paren.text tests/fixtures/extra/same_bullet.html tests/fixtures/extra/same_bullet.text tests/fixtures/extra/toplevel_paragraphs.gfm.html tests/fixtures/extra/toplevel_paragraphs.gfm.text tests/fixtures/extra/tricky_list.html tests/fixtures/extra/tricky_list.text tests/fixtures/normal/amps_and_angles_encoding.html tests/fixtures/normal/amps_and_angles_encoding.text tests/fixtures/normal/auto_email.html tests/fixtures/normal/auto_email.text tests/fixtures/normal/auto_links.html tests/fixtures/normal/auto_links.text tests/fixtures/normal/backslash_escapes.html tests/fixtures/normal/backslash_escapes.text tests/fixtures/normal/blockquotes_with_code_blocks.html tests/fixtures/normal/blockquotes_with_code_blocks.text tests/fixtures/normal/code_blocks.html tests/fixtures/normal/code_blocks.text tests/fixtures/normal/code_spans.html tests/fixtures/normal/code_spans.text tests/fixtures/normal/headers.html tests/fixtures/normal/headers.text tests/fixtures/normal/horizontal_rules.html tests/fixtures/normal/horizontal_rules.text tests/fixtures/normal/inline_html_advanced.html tests/fixtures/normal/inline_html_advanced.text tests/fixtures/normal/inline_html_comments.html tests/fixtures/normal/inline_html_comments.text tests/fixtures/normal/inline_html_simple.html tests/fixtures/normal/inline_html_simple.text tests/fixtures/normal/links_inline_style.html tests/fixtures/normal/links_inline_style.text tests/fixtures/normal/links_reference_style.html tests/fixtures/normal/links_reference_style.text tests/fixtures/normal/links_shortcut_references.html tests/fixtures/normal/links_shortcut_references.text tests/fixtures/normal/literal_quotes_in_titles.html tests/fixtures/normal/literal_quotes_in_titles.text tests/fixtures/normal/markdown_documentation_basics.html tests/fixtures/normal/markdown_documentation_basics.text tests/fixtures/normal/markdown_documentation_syntax.html tests/fixtures/normal/markdown_documentation_syntax.text tests/fixtures/normal/nested_blockquotes.html tests/fixtures/normal/nested_blockquotes.text tests/fixtures/normal/ordered_and_unordered_lists.html tests/fixtures/normal/ordered_and_unordered_lists.text tests/fixtures/normal/strong_and_em_together.html tests/fixtures/normal/strong_and_em_together.text tests/fixtures/normal/tabs.html tests/fixtures/normal/tabs.text tests/fixtures/normal/tidyness.html tests/fixtures/normal/tidyness.textmistune-0.7.1/mistune.egg-info/top_level.txt0000644000076500000240000000001012566114336021714 0ustar lepturestaff00000000000000mistune mistune-0.7.1/mistune.py0000644000076500000240000010412312566112456016055 0ustar lepturestaff00000000000000# coding: utf-8 """ mistune ~~~~~~~ The fastest markdown parser in pure Python with renderer feature. :copyright: (c) 2014 - 2015 by Hsiaoming Yang. """ import re import inspect __version__ = '0.7.1' __author__ = 'Hsiaoming Yang ' __all__ = [ 'BlockGrammar', 'BlockLexer', 'InlineGrammar', 'InlineLexer', 'Renderer', 'Markdown', 'markdown', 'escape', ] _key_pattern = re.compile(r'\s+') _escape_pattern = re.compile(r'&(?!#?\w+;)') _newline_pattern = re.compile(r'\r\n|\r') _block_quote_leading_pattern = re.compile(r'^ *> ?', flags=re.M) _block_code_leadning_pattern = re.compile(r'^ {4}', re.M) _inline_tags = [ 'a', 'em', 'strong', 'small', 's', 'cite', 'q', 'dfn', 'abbr', 'data', 'time', 'code', 'var', 'samp', 'kbd', 'sub', 'sup', 'i', 'b', 'u', 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'span', 'br', 'wbr', 'ins', 'del', 'img', 'font', ] _pre_tags = ['pre', 'script', 'style'] _valid_end = r'(?!:/|[^\w\s@]*@)\b' _valid_attr = r'''"[^"]*"|'[^']*'|[^'">]''' _block_tag = r'(?!(?:%s)\b)\w+%s' % ('|'.join(_inline_tags), _valid_end) def _pure_pattern(regex): pattern = regex.pattern if pattern.startswith('^'): pattern = pattern[1:] return pattern def _keyify(key): return _key_pattern.sub(' ', key.lower()) def escape(text, quote=False, smart_amp=True): """Replace special characters "&", "<" and ">" to HTML-safe sequences. The original cgi.escape will always escape "&", but you can control this one for a smart escape amp. :param quote: if set to True, " and ' will be escaped. :param smart_amp: if set to False, & will always be escaped. """ if smart_amp: text = _escape_pattern.sub('&', text) else: text = text.replace('&', '&') text = text.replace('<', '<') text = text.replace('>', '>') if quote: text = text.replace('"', '"') text = text.replace("'", ''') return text def preprocessing(text, tab=4): text = _newline_pattern.sub('\n', text) text = text.replace('\t', ' ' * tab) text = text.replace('\u00a0', ' ') text = text.replace('\u2424', '\n') pattern = re.compile(r'^ +$', re.M) return pattern.sub('', text) class BlockGrammar(object): """Grammars for block level tokens.""" def_links = re.compile( r'^ *\[([^^\]]+)\]: *' # [key]: r']+)>?' # or link r'(?: +["(]([^\n]+)[")])? *(?:\n+|$)' ) def_footnotes = re.compile( r'^\[\^([^\]]+)\]: *(' r'[^\n]*(?:\n+|$)' # [^key]: r'(?: {1,}[^\n]*(?:\n+|$))*' r')' ) newline = re.compile(r'^\n+') block_code = re.compile(r'^( {4}[^\n]+\n*)+') fences = re.compile( r'^ *(`{3,}|~{3,}) *(\S+)? *\n' # ```lang r'([\s\S]+?)\s*' r'\1 *(?:\n+|$)' # ``` ) hrule = re.compile(r'^ {0,3}[-*_](?: *[-*_]){2,} *(?:\n+|$)') heading = re.compile(r'^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)') lheading = re.compile(r'^([^\n]+)\n *(=|-)+ *(?:\n+|$)') block_quote = re.compile(r'^( *>[^\n]+(\n[^\n]+)*\n*)+') list_block = re.compile( r'^( *)([*+-]|\d+\.) [\s\S]+?' r'(?:' r'\n+(?=\1?(?:[-*_] *){3,}(?:\n+|$))' # hrule r'|\n+(?=%s)' # def links r'|\n+(?=%s)' # def footnotes r'|\n{2,}' r'(?! )' r'(?!\1(?:[*+-]|\d+\.) )\n*' r'|' r'\s*$)' % ( _pure_pattern(def_links), _pure_pattern(def_footnotes), ) ) list_item = re.compile( r'^(( *)(?:[*+-]|\d+\.) [^\n]*' r'(?:\n(?!\2(?:[*+-]|\d+\.) )[^\n]*)*)', flags=re.M ) list_bullet = re.compile(r'^ *(?:[*+-]|\d+\.) +') paragraph = re.compile( r'^((?:[^\n]+\n?(?!' r'%s|%s|%s|%s|%s|%s|%s|%s|%s' r'))+)\n*' % ( _pure_pattern(fences).replace(r'\1', r'\2'), _pure_pattern(list_block).replace(r'\1', r'\3'), _pure_pattern(hrule), _pure_pattern(heading), _pure_pattern(lheading), _pure_pattern(block_quote), _pure_pattern(def_links), _pure_pattern(def_footnotes), '<' + _block_tag, ) ) block_html = re.compile( r'^ *(?:%s|%s|%s) *(?:\n{2,}|\s*$)' % ( r'', r'<(%s)((?:%s)*?)>([\s\S]+?)<\/\1>' % (_block_tag, _valid_attr), r'<%s(?:%s)*?>' % (_block_tag, _valid_attr), ) ) table = re.compile( r'^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*' ) nptable = re.compile( r'^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*' ) text = re.compile(r'^[^\n]+') class BlockLexer(object): """Block level lexer for block grammars.""" grammar_class = BlockGrammar default_rules = [ 'newline', 'hrule', 'block_code', 'fences', 'heading', 'nptable', 'lheading', 'block_quote', 'list_block', 'block_html', 'def_links', 'def_footnotes', 'table', 'paragraph', 'text' ] list_rules = ( 'newline', 'block_code', 'fences', 'lheading', 'hrule', 'block_quote', 'list_block', 'block_html', 'text', ) footnote_rules = ( 'newline', 'block_code', 'fences', 'heading', 'nptable', 'lheading', 'hrule', 'block_quote', 'list_block', 'block_html', 'table', 'paragraph', 'text' ) def __init__(self, rules=None, **kwargs): self.tokens = [] self.def_links = {} self.def_footnotes = {} if not rules: rules = self.grammar_class() self.rules = rules def __call__(self, text, rules=None): return self.parse(text, rules) def parse(self, text, rules=None): text = text.rstrip('\n') if not rules: rules = self.default_rules def manipulate(text): for key in rules: rule = getattr(self.rules, key) m = rule.match(text) if not m: continue getattr(self, 'parse_%s' % key)(m) return m return False # pragma: no cover while text: m = manipulate(text) if m is not False: text = text[len(m.group(0)):] continue if text: # pragma: no cover raise RuntimeError('Infinite loop at: %s' % text) return self.tokens def parse_newline(self, m): length = len(m.group(0)) if length > 1: self.tokens.append({'type': 'newline'}) def parse_block_code(self, m): # clean leading whitespace code = _block_code_leadning_pattern.sub('', m.group(0)) self.tokens.append({ 'type': 'code', 'lang': None, 'text': code, }) def parse_fences(self, m): self.tokens.append({ 'type': 'code', 'lang': m.group(2), 'text': m.group(3), }) def parse_heading(self, m): self.tokens.append({ 'type': 'heading', 'level': len(m.group(1)), 'text': m.group(2), }) def parse_lheading(self, m): """Parse setext heading.""" self.tokens.append({ 'type': 'heading', 'level': 1 if m.group(2) == '=' else 2, 'text': m.group(1), }) def parse_hrule(self, m): self.tokens.append({'type': 'hrule'}) def parse_list_block(self, m): bull = m.group(2) self.tokens.append({ 'type': 'list_start', 'ordered': '.' in bull, }) cap = m.group(0) self._process_list_item(cap, bull) self.tokens.append({'type': 'list_end'}) def _process_list_item(self, cap, bull): cap = self.rules.list_item.findall(cap) _next = False length = len(cap) for i in range(length): item = cap[i][0] # remove the bullet space = len(item) item = self.rules.list_bullet.sub('', item) # outdent if '\n ' in item: space = space - len(item) pattern = re.compile(r'^ {1,%d}' % space, flags=re.M) item = pattern.sub('', item) # determin whether item is loose or not loose = _next if not loose and re.search(r'\n\n(?!\s*$)', item): loose = True rest = len(item) if i != length - 1 and rest: _next = item[rest-1] == '\n' if not loose: loose = _next if loose: t = 'loose_item_start' else: t = 'list_item_start' self.tokens.append({'type': t}) # recurse self.parse(item, self.list_rules) self.tokens.append({'type': 'list_item_end'}) def parse_block_quote(self, m): self.tokens.append({'type': 'block_quote_start'}) # clean leading > cap = _block_quote_leading_pattern.sub('', m.group(0)) self.parse(cap) self.tokens.append({'type': 'block_quote_end'}) def parse_def_links(self, m): key = _keyify(m.group(1)) self.def_links[key] = { 'link': m.group(2), 'title': m.group(3), } def parse_def_footnotes(self, m): key = _keyify(m.group(1)) if key in self.def_footnotes: # footnote is already defined return self.def_footnotes[key] = 0 self.tokens.append({ 'type': 'footnote_start', 'key': key, }) text = m.group(2) if '\n' in text: lines = text.split('\n') whitespace = None for line in lines[1:]: space = len(line) - len(line.lstrip()) if space and (not whitespace or space < whitespace): whitespace = space newlines = [lines[0]] for line in lines[1:]: newlines.append(line[whitespace:]) text = '\n'.join(newlines) self.parse(text, self.footnote_rules) self.tokens.append({ 'type': 'footnote_end', 'key': key, }) def parse_table(self, m): item = self._process_table(m) cells = re.sub(r'(?: *\| *)?\n$', '', m.group(3)) cells = cells.split('\n') for i, v in enumerate(cells): v = re.sub(r'^ *\| *| *\| *$', '', v) cells[i] = re.split(r' *\| *', v) item['cells'] = cells self.tokens.append(item) def parse_nptable(self, m): item = self._process_table(m) cells = re.sub(r'\n$', '', m.group(3)) cells = cells.split('\n') for i, v in enumerate(cells): cells[i] = re.split(r' *\| *', v) item['cells'] = cells self.tokens.append(item) def _process_table(self, m): header = re.sub(r'^ *| *\| *$', '', m.group(1)) header = re.split(r' *\| *', header) align = re.sub(r' *|\| *$', '', m.group(2)) align = re.split(r' *\| *', align) for i, v in enumerate(align): if re.search(r'^ *-+: *$', v): align[i] = 'right' elif re.search(r'^ *:-+: *$', v): align[i] = 'center' elif re.search(r'^ *:-+ *$', v): align[i] = 'left' else: align[i] = None item = { 'type': 'table', 'header': header, 'align': align, } return item def parse_block_html(self, m): tag = m.group(1) if not tag: text = m.group(0) self.tokens.append({ 'type': 'close_html', 'text': text }) else: attr = m.group(2) text = m.group(3) self.tokens.append({ 'type': 'open_html', 'tag': tag, 'extra': attr, 'text': text }) def parse_paragraph(self, m): text = m.group(1).rstrip('\n') self.tokens.append({'type': 'paragraph', 'text': text}) def parse_text(self, m): text = m.group(0) self.tokens.append({'type': 'text', 'text': text}) class InlineGrammar(object): """Grammars for inline level tokens.""" escape = re.compile(r'^\\([\\`*{}\[\]()#+\-.!_>~|])') # \* \+ \! .... inline_html = re.compile( r'^(?:%s|%s|%s)' % ( r'', r'<(\w+%s)((?:%s)*?)>([\s\S]*?)<\/\1>' % (_valid_end, _valid_attr), r'<\w+%s(?:%s)*?>' % (_valid_end, _valid_attr), ) ) autolink = re.compile(r'^<([^ >]+(@|:)[^ >]+)>') link = re.compile( r'^!?\[(' r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*' r')\]\(' r'''\s*(<)?([\s\S]*?)(?(2)>)(?:\s+['"]([\s\S]*?)['"])?\s*''' r'\)' ) reflink = re.compile( r'^!?\[(' r'(?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*' r')\]\s*\[([^^\]]*)\]' ) nolink = re.compile(r'^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]') url = re.compile(r'''^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])''') double_emphasis = re.compile( r'^_{2}([\s\S]+?)_{2}(?!_)' # __word__ r'|' r'^\*{2}([\s\S]+?)\*{2}(?!\*)' # **word** ) emphasis = re.compile( r'^\b_((?:__|[\s\S])+?)_\b' # _word_ r'|' r'^\*((?:\*\*|[\s\S])+?)\*(?!\*)' # *word* ) code = re.compile(r'^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)') # `code` linebreak = re.compile(r'^ {2,}\n(?!\s*$)') strikethrough = re.compile(r'^~~(?=\S)([\s\S]+?\S)~~') # ~~word~~ footnote = re.compile(r'^\[\^([^\]]+)\]') text = re.compile(r'^[\s\S]+?(?=[\\%s' % (tag, extra, text, tag) else: html = m.group(0) return self.renderer.inline_html(html) def output_footnote(self, m): key = _keyify(m.group(1)) if key not in self.footnotes: return None if self.footnotes[key]: return None self.footnote_index += 1 self.footnotes[key] = self.footnote_index return self.renderer.footnote_ref(key, self.footnote_index) def output_link(self, m): return self._process_link(m, m.group(3), m.group(4)) def output_reflink(self, m): key = _keyify(m.group(2) or m.group(1)) if key not in self.links: return None ret = self.links[key] return self._process_link(m, ret['link'], ret['title']) def output_nolink(self, m): key = _keyify(m.group(1)) if key not in self.links: return None ret = self.links[key] return self._process_link(m, ret['link'], ret['title']) def _process_link(self, m, link, title=None): line = m.group(0) text = m.group(1) if line[0] == '!': return self.renderer.image(link, title, text) self._in_link = True text = self.output(text) self._in_link = False return self.renderer.link(link, title, text) def output_double_emphasis(self, m): text = m.group(2) or m.group(1) text = self.output(text) return self.renderer.double_emphasis(text) def output_emphasis(self, m): text = m.group(2) or m.group(1) text = self.output(text) return self.renderer.emphasis(text) def output_code(self, m): text = m.group(2) return self.renderer.codespan(text) def output_linebreak(self, m): return self.renderer.linebreak() def output_strikethrough(self, m): text = self.output(m.group(1)) return self.renderer.strikethrough(text) def output_text(self, m): text = m.group(0) return self.renderer.text(text) class Renderer(object): """The default HTML renderer for rendering Markdown. """ def __init__(self, **kwargs): self.options = kwargs def placeholder(self): """Returns the default, empty output value for the renderer. All renderer methods use the '+=' operator to append to this value. Default is a string so rendering HTML can build up a result string with the rendered Markdown. Can be overridden by Renderer subclasses to be types like an empty list, allowing the renderer to create a tree-like structure to represent the document (which can then be reprocessed later into a separate format like docx or pdf). """ return '' def block_code(self, code, lang=None): """Rendering block level code. ``pre > code``. :param code: text content of the code block. :param lang: language of the given code. """ code = code.rstrip('\n') if not lang: code = escape(code, smart_amp=False) return '
%s\n
\n' % code code = escape(code, quote=True, smart_amp=False) return '
%s\n
\n' % (lang, code) def block_quote(self, text): """Rendering
with the given text. :param text: text content of the blockquote. """ return '
%s\n
\n' % text.rstrip('\n') def block_html(self, html): """Rendering block level pure html content. :param html: text content of the html snippet. """ if self.options.get('skip_style') and \ html.lower().startswith('`` ``

``. :param text: rendered text content for the header. :param level: a number for the header level, for example: 1. :param raw: raw text content of the header. """ return '%s\n' % (level, text, level) def hrule(self): """Rendering method for ``
`` tag.""" if self.options.get('use_xhtml'): return '
\n' return '
\n' def list(self, body, ordered=True): """Rendering list tags like ``
    `` and ``
      ``. :param body: body contents of the list. :param ordered: whether this list is ordered or not. """ tag = 'ul' if ordered: tag = 'ol' return '<%s>\n%s\n' % (tag, body, tag) def list_item(self, text): """Rendering list item snippet. Like ``
    1. ``.""" return '
    2. %s
    3. \n' % text def paragraph(self, text): """Rendering paragraph tags. Like ``

      ``.""" return '

      %s

      \n' % text.strip(' ') def table(self, header, body): """Rendering table element. Wrap header and body in it. :param header: header part of the table. :param body: body part of the table. """ return ( '\n%s\n' '\n%s\n
      \n' ) % (header, body) def table_row(self, content): """Rendering a table row. Like ````. :param content: content of current table row. """ return '\n%s\n' % content def table_cell(self, content, **flags): """Rendering a table cell. Like ```` ````. :param content: content of current table cell. :param header: whether this is header or not. :param align: align of current table cell. """ if flags['header']: tag = 'th' else: tag = 'td' align = flags['align'] if not align: return '<%s>%s\n' % (tag, content, tag) return '<%s style="text-align:%s">%s\n' % ( tag, align, content, tag ) def double_emphasis(self, text): """Rendering **strong** text. :param text: text content for emphasis. """ return '%s' % text def emphasis(self, text): """Rendering *emphasis* text. :param text: text content for emphasis. """ return '%s' % text def codespan(self, text): """Rendering inline `code` text. :param text: text content for inline code. """ text = escape(text.rstrip(), smart_amp=False) return '%s' % text def linebreak(self): """Rendering line break like ``
      ``.""" if self.options.get('use_xhtml'): return '
      \n' return '
      \n' def strikethrough(self, text): """Rendering ~~strikethrough~~ text. :param text: text content for strikethrough. """ return '%s' % text def text(self, text): """Rendering unformatted text. :param text: text content. """ return escape(text) def autolink(self, link, is_email=False): """Rendering a given link or email address. :param link: link content or email address. :param is_email: whether this is an email or not. """ text = link = escape(link) if is_email: link = 'mailto:%s' % link return '%s' % (link, text) def link(self, link, title, text): """Rendering a given link with content and title. :param link: href link for ```` tag. :param title: title content for `title` attribute. :param text: text content for description. """ if link.startswith('javascript:'): link = '' if not title: return '%s' % (link, text) title = escape(title, quote=True) return '%s' % (link, title, text) def image(self, src, title, text): """Rendering a image with title and text. :param src: source link of the image. :param title: title text of the image. :param text: alt text of the image. """ if src.startswith('javascript:'): src = '' text = escape(text, quote=True) if title: title = escape(title, quote=True) html = '%s' % html return '%s>' % html def inline_html(self, html): """Rendering span level pure html content. :param html: text content of the html snippet. """ if self.options.get('escape'): return escape(html) return html def newline(self): """Rendering newline element.""" return '' def footnote_ref(self, key, index): """Rendering the ref anchor of a footnote. :param key: identity key for the footnote. :param index: the index count of current footnote. """ html = ( '' '%d' ) % (escape(key), escape(key), index) return html def footnote_item(self, key, text): """Rendering a footnote item. :param key: identity key for the footnote. :param text: text content of the footnote. """ back = ( '' ) % escape(key) text = text.rstrip() if text.endswith('

      '): text = re.sub(r'<\/p>$', r'%s

      ' % back, text) else: text = '%s

      %s

      ' % (text, back) html = '
    4. %s
    5. \n' % (escape(key), text) return html def footnotes(self, text): """Wrapper for all footnotes. :param text: contents of all footnotes. """ html = '
      \n%s
        %s
      \n
      \n' return html % (self.hrule(), text) class Markdown(object): """The Markdown parser. :param renderer: An instance of ``Renderer``. :param inline: An inline lexer class or instance. :param block: A block lexer class or instance. """ def __init__(self, renderer=None, inline=None, block=None, **kwargs): if not renderer: renderer = Renderer(**kwargs) self.renderer = renderer if inline and inspect.isclass(inline): inline = inline(renderer, **kwargs) if block and inspect.isclass(block): block = block(**kwargs) if inline: self.inline = inline else: rules = InlineGrammar() if kwargs.get('hard_wrap'): rules.hard_wrap() self.inline = InlineLexer(renderer, rules=rules) self.block = block or BlockLexer(BlockGrammar()) self.options = kwargs self.footnotes = [] self.tokens = [] # detect if it should parse text in block html self._parse_block_html = kwargs.get('parse_block_html') def __call__(self, text): return self.parse(text) def render(self, text): """Render the Markdown text. :param text: markdown formatted text content. """ return self.parse(text) def parse(self, text): out = self.output(preprocessing(text)) keys = self.block.def_footnotes # reset block self.block.def_links = {} self.block.def_footnotes = {} # reset inline self.inline.links = {} self.inline.footnotes = {} if not self.footnotes: return out footnotes = filter(lambda o: keys.get(o['key']), self.footnotes) self.footnotes = sorted( footnotes, key=lambda o: keys.get(o['key']), reverse=True ) body = self.renderer.placeholder() while self.footnotes: note = self.footnotes.pop() body += self.renderer.footnote_item( note['key'], note['text'] ) out += self.renderer.footnotes(body) return out def pop(self): if not self.tokens: return None self.token = self.tokens.pop() return self.token def peek(self): if self.tokens: return self.tokens[-1] return None # pragma: no cover def output(self, text, rules=None): self.tokens = self.block(text, rules) self.tokens.reverse() self.inline.setup(self.block.def_links, self.block.def_footnotes) out = self.renderer.placeholder() while self.pop(): out += self.tok() return out def tok(self): t = self.token['type'] # sepcial cases if t.endswith('_start'): t = t[:-6] return getattr(self, 'output_%s' % t)() def tok_text(self): text = self.token['text'] while self.peek()['type'] == 'text': text += '\n' + self.pop()['text'] return self.inline(text) def output_newline(self): return self.renderer.newline() def output_hrule(self): return self.renderer.hrule() def output_heading(self): return self.renderer.header( self.inline(self.token['text']), self.token['level'], self.token['text'], ) def output_code(self): return self.renderer.block_code( self.token['text'], self.token['lang'] ) def output_table(self): aligns = self.token['align'] aligns_length = len(aligns) cell = self.renderer.placeholder() # header part header = self.renderer.placeholder() for i, value in enumerate(self.token['header']): align = aligns[i] if i < aligns_length else None flags = {'header': True, 'align': align} cell += self.renderer.table_cell(self.inline(value), **flags) header += self.renderer.table_row(cell) # body part body = self.renderer.placeholder() for i, row in enumerate(self.token['cells']): cell = self.renderer.placeholder() for j, value in enumerate(row): align = aligns[j] if j < aligns_length else None flags = {'header': False, 'align': align} cell += self.renderer.table_cell(self.inline(value), **flags) body += self.renderer.table_row(cell) return self.renderer.table(header, body) def output_block_quote(self): body = self.renderer.placeholder() while self.pop()['type'] != 'block_quote_end': body += self.tok() return self.renderer.block_quote(body) def output_list(self): ordered = self.token['ordered'] body = self.renderer.placeholder() while self.pop()['type'] != 'list_end': body += self.tok() return self.renderer.list(body, ordered) def output_list_item(self): body = self.renderer.placeholder() while self.pop()['type'] != 'list_item_end': if self.token['type'] == 'text': body += self.tok_text() else: body += self.tok() return self.renderer.list_item(body) def output_loose_item(self): body = self.renderer.placeholder() while self.pop()['type'] != 'list_item_end': body += self.tok() return self.renderer.list_item(body) def output_footnote(self): self.inline._in_footnote = True body = self.renderer.placeholder() key = self.token['key'] while self.pop()['type'] != 'footnote_end': body += self.tok() self.footnotes.append({'key': key, 'text': body}) self.inline._in_footnote = False return self.renderer.placeholder() def output_close_html(self): text = self.token['text'] return self.renderer.block_html(text) def output_open_html(self): text = self.token['text'] tag = self.token['tag'] if self._parse_block_html and tag not in _pre_tags: text = self.inline(text, rules=self.inline.inline_html_rules) extra = self.token.get('extra') or '' html = '<%s%s>%s' % (tag, extra, text, tag) return self.renderer.block_html(html) def output_paragraph(self): return self.renderer.paragraph(self.inline(self.token['text'])) def output_text(self): return self.renderer.paragraph(self.tok_text()) def markdown(text, escape=True, **kwargs): """Render markdown formatted text to html. :param text: markdown formatted text content. :param escape: if set to False, all html tags will not be escaped. :param use_xhtml: output with xhtml tags. :param hard_wrap: if set to True, it will has GFM line breaks feature. :param parse_block_html: parse text only in block level html. :param parse_inline_html: parse text only in inline level html. """ return Markdown(escape=escape, **kwargs)(text) mistune-0.7.1/PKG-INFO0000644000076500000240000002356512566114341015121 0ustar lepturestaff00000000000000Metadata-Version: 1.1 Name: mistune Version: 0.7.1 Summary: The fastest markdown parser in pure Python Home-page: https://github.com/lepture/mistune Author: Hsiaoming Yang Author-email: me@lepture.com License: BSD Description: Mistune ======= The fastest markdown parser in pure Python with renderer features, inspired by marked_. .. image:: https://img.shields.io/pypi/wheel/mistune.svg?style=flat :target: https://pypi.python.org/pypi/mistune/ :alt: Wheel Status .. image:: https://img.shields.io/pypi/v/mistune.svg :target: https://pypi.python.org/pypi/mistune/ :alt: Latest Version .. image:: https://travis-ci.org/lepture/mistune.svg?branch=master :target: https://travis-ci.org/lepture/mistune :alt: Travis CI Status .. image:: https://coveralls.io/repos/lepture/mistune/badge.svg?branch=master :target: https://coveralls.io/r/lepture/mistune :alt: Coverage Status .. image:: https://ci.appveyor.com/api/projects/status/8ai8tfwp75oela17?svg=true :target: https://ci.appveyor.com/project/lepture/mistune :alt: App Veyor CI Status .. _marked: https://github.com/chjj/marked Features -------- * **Pure Python**. Tested in Python 2.6+, Python 3.3+ and PyPy. * **Very Fast**. It is the fastest in all **pure Python** markdown parsers. * **More Features**. Table, footnotes, autolink, fenced code etc. View the `benchmark results `_. Installation ------------ Installing mistune with pip:: $ pip install mistune Mistune can be faster, if you compile with cython:: $ pip install cython mistune Basic Usage ----------- A simple API that render a markdown formatted text: .. code:: python import mistune mistune.markdown('I am using **mistune markdown parser**') # output:

      I am using mistune markdown parser

      If you care about performance, it is better to re-use the Markdown instance: .. code:: python import mistune markdown = mistune.Markdown() markdown('I am using **mistune markdown parser**') Mistune has enabled all features by default. You don't have to configure anything. But there are options for you to change the parser behaviors. Options ------- Here is a list of all options that will affect the rendering results, configure them with ``mistune.Renderer``: .. code:: python renderer = mistune.Renderer(escape=True, hard_wrap=True) # use this renderer instance markdown = mistune.Markdown(renderer=renderer) markdown(text) * **escape**: if set to *False*, all raw html tags will not be escaped. * **hard_wrap**: if set to *True*, it will has GFM line breaks feature. All new lines will be replaced with ``
      `` tag * **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``
      ``. * **parse_block_html**: parse text only in block level html. * **parse_inline_html**: parse text only in inline level html. When using the default renderer, you can use one of the following shortcuts:: mistune.markdown(text, escape=True, hard_wrap=True) markdown = mistune.Markdown(escape=True, hard_wrap=True) markdown(text) Renderer -------- Like misaka/sundown, you can influence the rendering by custom renderers. All you need to do is subclassing a `Renderer` class. Here is an example of code highlighting: .. code:: python import mistune from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter class HighlightRenderer(mistune.Renderer): def block_code(self, code, lang): if not lang: return '\n
      %s
      \n' % \ mistune.escape(code) lexer = get_lexer_by_name(lang, stripall=True) formatter = HtmlFormatter() return highlight(code, lexer, formatter) renderer = HighlightRenderer() markdown = mistune.Markdown(renderer=renderer) print(markdown('```python\nassert 1 == 1\n```')) Find more renderers in `mistune-contrib`_. Block Level ~~~~~~~~~~~ Here is a list of block level renderer API:: block_code(code, language=None) block_quote(text) block_html(html) header(text, level, raw=None) hrule() list(body, ordered=True) list_item(text) paragraph(text) table(header, body) table_row(content) table_cell(content, **flags) The *flags* tells you whether it is header with ``flags['header']``. And it also tells you the align with ``flags['align']``. Span Level ~~~~~~~~~~ Here is a list of span level renderer API:: autolink(link, is_email=False) codespan(text) double_emphasis(text) emphasis(text) image(src, title, alt_text) linebreak() newline() link(link, title, content) strikethrough(text) text(text) inline_html(text) Footnotes ~~~~~~~~~ Here is a list of renderers related to footnotes:: footnote_ref(key, index) footnote_item(key, text) footnotes(text) Lexers ------ Sometimes you want to add your own rules to Markdown, such as GitHub Wiki links. You can't achieve this goal with renderers. You will need to deal with the lexers, it would be a little difficult for the first time. We will take an example for GitHub Wiki links: ``[[Page 2|Page 2]]``. It is an inline grammar, which requires custom ``InlineGrammar`` and ``InlineLexer``: .. code:: python import copy from mistune import Renderer, InlineGrammar, InlineLexer class WikiLinkRenderer(Renderer): def wiki_link(self, alt, link): return '%s' % (link, alt) class WikiLinkInlineLexer(InlineLexer): def enable_wiki_link(self): # add wiki_link rules self.rules.wiki_link = re.compile( r'\[\[' # [[ r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2 r'\]\](?!\])' # ]] ) # Add wiki_link parser to default rules # you can insert it some place you like # but place matters, maybe 3 is not good self.default_rules.insert(3, 'wiki_link') def output_wiki_link(self, m): text = m.group(1) alt, link = text.split('|') # you can create an custom render # you can also return the html if you like return self.renderer.wiki_link(alt, link) You should pass the inline lexer to ``Markdown`` parser: .. code:: python renderer = WikiLinkRenderer() inline = WikiLinkInlineLexer(renderer) # enable the feature inline.enable_wiki_link() markdown = Markdown(renderer, inline=inline) markdown('[[Link Text|Wiki Link]]') It is the same with block level lexer. It would take a while to understand the whole mechanism. But you won't do the trick a lot. Contribution & Extensions ------------------------- Mistune itself doesn't accept any extension. It will always be a simple one file script. If you want to add features, you can head over to `mistune-contrib`_. Here are some extensions already in `mistune-contrib`_: * Math/MathJax features * Highlight Code Renderer * TOC table of content features * MultiMarkdown Metadata parser Get inspired with the contrib repository. .. _`mistune-contrib`: https://github.com/lepture/mistune-contrib Platform: any Classifier: Development Status :: 4 - Beta Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Text Processing :: Markup Classifier: Topic :: Software Development :: Libraries :: Python Modules mistune-0.7.1/README.rst0000644000076500000240000001571712562325210015506 0ustar lepturestaff00000000000000Mistune ======= The fastest markdown parser in pure Python with renderer features, inspired by marked_. .. image:: https://img.shields.io/pypi/wheel/mistune.svg?style=flat :target: https://pypi.python.org/pypi/mistune/ :alt: Wheel Status .. image:: https://img.shields.io/pypi/v/mistune.svg :target: https://pypi.python.org/pypi/mistune/ :alt: Latest Version .. image:: https://travis-ci.org/lepture/mistune.svg?branch=master :target: https://travis-ci.org/lepture/mistune :alt: Travis CI Status .. image:: https://coveralls.io/repos/lepture/mistune/badge.svg?branch=master :target: https://coveralls.io/r/lepture/mistune :alt: Coverage Status .. image:: https://ci.appveyor.com/api/projects/status/8ai8tfwp75oela17?svg=true :target: https://ci.appveyor.com/project/lepture/mistune :alt: App Veyor CI Status .. _marked: https://github.com/chjj/marked Features -------- * **Pure Python**. Tested in Python 2.6+, Python 3.3+ and PyPy. * **Very Fast**. It is the fastest in all **pure Python** markdown parsers. * **More Features**. Table, footnotes, autolink, fenced code etc. View the `benchmark results `_. Installation ------------ Installing mistune with pip:: $ pip install mistune Mistune can be faster, if you compile with cython:: $ pip install cython mistune Basic Usage ----------- A simple API that render a markdown formatted text: .. code:: python import mistune mistune.markdown('I am using **mistune markdown parser**') # output:

      I am using mistune markdown parser

      If you care about performance, it is better to re-use the Markdown instance: .. code:: python import mistune markdown = mistune.Markdown() markdown('I am using **mistune markdown parser**') Mistune has enabled all features by default. You don't have to configure anything. But there are options for you to change the parser behaviors. Options ------- Here is a list of all options that will affect the rendering results, configure them with ``mistune.Renderer``: .. code:: python renderer = mistune.Renderer(escape=True, hard_wrap=True) # use this renderer instance markdown = mistune.Markdown(renderer=renderer) markdown(text) * **escape**: if set to *False*, all raw html tags will not be escaped. * **hard_wrap**: if set to *True*, it will has GFM line breaks feature. All new lines will be replaced with ``
      `` tag * **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``
      ``. * **parse_block_html**: parse text only in block level html. * **parse_inline_html**: parse text only in inline level html. When using the default renderer, you can use one of the following shortcuts:: mistune.markdown(text, escape=True, hard_wrap=True) markdown = mistune.Markdown(escape=True, hard_wrap=True) markdown(text) Renderer -------- Like misaka/sundown, you can influence the rendering by custom renderers. All you need to do is subclassing a `Renderer` class. Here is an example of code highlighting: .. code:: python import mistune from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import HtmlFormatter class HighlightRenderer(mistune.Renderer): def block_code(self, code, lang): if not lang: return '\n
      %s
      \n' % \ mistune.escape(code) lexer = get_lexer_by_name(lang, stripall=True) formatter = HtmlFormatter() return highlight(code, lexer, formatter) renderer = HighlightRenderer() markdown = mistune.Markdown(renderer=renderer) print(markdown('```python\nassert 1 == 1\n```')) Find more renderers in `mistune-contrib`_. Block Level ~~~~~~~~~~~ Here is a list of block level renderer API:: block_code(code, language=None) block_quote(text) block_html(html) header(text, level, raw=None) hrule() list(body, ordered=True) list_item(text) paragraph(text) table(header, body) table_row(content) table_cell(content, **flags) The *flags* tells you whether it is header with ``flags['header']``. And it also tells you the align with ``flags['align']``. Span Level ~~~~~~~~~~ Here is a list of span level renderer API:: autolink(link, is_email=False) codespan(text) double_emphasis(text) emphasis(text) image(src, title, alt_text) linebreak() newline() link(link, title, content) strikethrough(text) text(text) inline_html(text) Footnotes ~~~~~~~~~ Here is a list of renderers related to footnotes:: footnote_ref(key, index) footnote_item(key, text) footnotes(text) Lexers ------ Sometimes you want to add your own rules to Markdown, such as GitHub Wiki links. You can't achieve this goal with renderers. You will need to deal with the lexers, it would be a little difficult for the first time. We will take an example for GitHub Wiki links: ``[[Page 2|Page 2]]``. It is an inline grammar, which requires custom ``InlineGrammar`` and ``InlineLexer``: .. code:: python import copy from mistune import Renderer, InlineGrammar, InlineLexer class WikiLinkRenderer(Renderer): def wiki_link(self, alt, link): return '%s' % (link, alt) class WikiLinkInlineLexer(InlineLexer): def enable_wiki_link(self): # add wiki_link rules self.rules.wiki_link = re.compile( r'\[\[' # [[ r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2 r'\]\](?!\])' # ]] ) # Add wiki_link parser to default rules # you can insert it some place you like # but place matters, maybe 3 is not good self.default_rules.insert(3, 'wiki_link') def output_wiki_link(self, m): text = m.group(1) alt, link = text.split('|') # you can create an custom render # you can also return the html if you like return self.renderer.wiki_link(alt, link) You should pass the inline lexer to ``Markdown`` parser: .. code:: python renderer = WikiLinkRenderer() inline = WikiLinkInlineLexer(renderer) # enable the feature inline.enable_wiki_link() markdown = Markdown(renderer, inline=inline) markdown('[[Link Text|Wiki Link]]') It is the same with block level lexer. It would take a while to understand the whole mechanism. But you won't do the trick a lot. Contribution & Extensions ------------------------- Mistune itself doesn't accept any extension. It will always be a simple one file script. If you want to add features, you can head over to `mistune-contrib`_. Here are some extensions already in `mistune-contrib`_: * Math/MathJax features * Highlight Code Renderer * TOC table of content features * MultiMarkdown Metadata parser Get inspired with the contrib repository. .. _`mistune-contrib`: https://github.com/lepture/mistune-contrib mistune-0.7.1/setup.cfg0000644000076500000240000000020412566114341015626 0ustar lepturestaff00000000000000[wheel] universal = 1 [check-manifest] ignore = .travis.yml tox.ini [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 mistune-0.7.1/setup.py0000644000076500000240000001061012546702256015527 0ustar lepturestaff00000000000000#!/usr/bin/env python # coding: utf-8 from __future__ import print_function try: # python setup.py test import multiprocessing except ImportError: pass import mistune from setuptools import setup, Extension cmdclass = {} try: from Cython.Distutils import build_ext except ImportError: have_cython = False else: have_cython = True import sys # Failsafe compilation originally from simplejson. Author: Bob Ippolito # Copied here from markupsafe from distutils.errors import CCompilerError, DistutilsExecError from distutils.errors import DistutilsPlatformError is_jython = 'java' in sys.platform is_pypy = hasattr(sys, 'pypy_version_info') ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) if sys.platform == 'win32' and sys.version_info > (2, 6): # 2.6's distutils.msvc9compiler can raise an IOError when failing to # find the compiler ext_errors += (IOError,) class BuildFailed(Exception): pass class ve_build_ext(build_ext): """This class allows C extension building to fail.""" def run(self): try: build_ext.run(self) except DistutilsPlatformError: raise BuildFailed() def build_extension(self, ext): try: build_ext.build_extension(self, ext) except ext_errors: raise BuildFailed() except ValueError as e: # this can happen on Windows 64 bit, see Python issue 7511 if "'path'" in str(e): raise BuildFailed() raise cmdclass['build_ext'] = ve_build_ext # patch bdist_wheel try: from wheel.bdist_wheel import bdist_wheel REPLACE = ( 'macosx_10_6_intel.' 'macosx_10_9_intel.' 'macosx_10_9_x86_64.' 'macosx_10_10_intel.' 'macosx_10_10_x86_64' ) class _bdist_wheel(bdist_wheel): def get_tag(self): tag = bdist_wheel.get_tag(self) if tag[2] == 'macosx_10_6_intel': tag = (tag[0], tag[1], REPLACE) return tag cmdclass['bdist_wheel'] = _bdist_wheel except ImportError: pass def fread(filepath): with open(filepath, 'r') as f: return f.read() def run_setup(with_binary): ext_modules = [Extension('mistune', ['mistune.py'])] if with_binary else [] setup( name='mistune', version=mistune.__version__, url='https://github.com/lepture/mistune', author='Hsiaoming Yang', author_email='me@lepture.com', description='The fastest markdown parser in pure Python', long_description=fread('README.rst'), license='BSD', py_modules=['mistune'], cmdclass=cmdclass, ext_modules=ext_modules, zip_safe=False, platforms='any', tests_require=['nose'], test_suite='nose.collector', classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Text Processing :: Markup', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) def try_building_extension(): try: run_setup(True) except BuildFailed: LINE = '=' * 74 BUILD_EXT_WARNING = 'WARNING: The C extension could not be ' \ 'compiled, speedups are not enabled.' print(LINE) print(BUILD_EXT_WARNING) print('Failure information, if any, is above.') print('Retrying the build without the C extension now.') print() run_setup(False) print(LINE) print(BUILD_EXT_WARNING) print('Plain-Python installation succeeded.') print(LINE) if have_cython and not(is_jython or is_pypy): try_building_extension() else: run_setup(False) mistune-0.7.1/tests/0000755000076500000240000000000012566114341015153 5ustar lepturestaff00000000000000mistune-0.7.1/tests/bench.py0000644000076500000240000000463512531763272016621 0ustar lepturestaff00000000000000# coding: utf-8 import os import time import functools class benchmark(object): suites = [] def __init__(self, name): self._name = name def __call__(self, func): @functools.wraps(func) def wrapper(text, loops=1000): start = time.clock() while loops: func(text) loops -= 1 end = time.clock() return end - start # register benchmark.suites.append((self._name, wrapper)) return wrapper @classmethod def bench(cls, text, loops=1000): print('Parsing the Markdown Syntax document %d times...' % loops) for name, func in cls.suites: try: total = func(text, loops=loops) print('{0}: {1}'.format(name, total)) except ImportError: print('{0} is not available'.format(name)) @benchmark('mistune') def benchmark_mistune(text): import mistune mistune.markdown(text) @benchmark('misaka') def benchmark_misaka(text): import misaka as m # mistune has all these features extensions = ( m.EXT_NO_INTRA_EMPHASIS | m.EXT_FENCED_CODE | m.EXT_AUTOLINK | m.EXT_TABLES | m.EXT_STRIKETHROUGH ) md = m.Markdown(m.HtmlRenderer(), extensions=extensions) md.render(text) @benchmark('markdown2') def benchmark_markdown2(text): import markdown2 extras = ['code-friendly', 'fenced-code-blocks', 'footnotes'] markdown2.markdown(text, extras=extras) @benchmark('markdown') def benchmark_markdown(text): import markdown markdown.markdown(text, ['extra']) @benchmark('cMarkdown') def benchmark_cMarkdown(text): import cMarkdown cMarkdown.markdown(text) @benchmark('discount') def benchmark_discount(text): import discount discount.Markdown(text).get_html_content() @benchmark('hoep') def benchmark_hoep(text): import hoep as m # mistune has all these features extensions = ( m.EXT_NO_INTRA_EMPHASIS | m.EXT_FENCED_CODE | m.EXT_AUTOLINK | m.EXT_TABLES | m.EXT_STRIKETHROUGH | m.EXT_FOOTNOTES ) md = m.Hoep(extensions=extensions) md.render(text.decode('utf-8')) if __name__ == '__main__': root = os.path.dirname(__file__) filepath = os.path.join( root, 'fixtures/normal', 'markdown_documentation_syntax.text' ) with open(filepath, 'r') as f: text = f.read() benchmark.bench(text) mistune-0.7.1/tests/fixtures/0000755000076500000240000000000012566114341017024 5ustar lepturestaff00000000000000mistune-0.7.1/tests/fixtures/data/0000755000076500000240000000000012566114341017735 5ustar lepturestaff00000000000000mistune-0.7.1/tests/fixtures/data/math-paragraph.md0000644000076500000240000000036612442503207023154 0ustar lepturestaff00000000000000Water that is stored in $t$, $s_t$, must equal the storage content of the previous stage, $s_{t-1}$, plus a stochastic inflow, $I_t$, minus what is being released in $t$, $r_t$. With $s_0$ defined as the initial storage content in $t=1$, we have mistune-0.7.1/tests/fixtures/data/math.md0000644000076500000240000000022112442503207021177 0ustar lepturestaff00000000000000\begin{equation*} \left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right) \end{equation*} mistune-0.7.1/tests/fixtures/data/tree.md0000644000076500000240000000014512442500732021212 0ustar lepturestaff00000000000000## Title here Some text. In two paragraphs. And then a list. - foo - bar 1. meep 1. stuff mistune-0.7.1/tests/fixtures/extra/0000755000076500000240000000000012566114341020147 5ustar lepturestaff00000000000000mistune-0.7.1/tests/fixtures/extra/autolink_lines.html0000644000076500000240000000011012416110764024044 0ustar lepturestaff00000000000000

      hello world http://example.com

      mistune-0.7.1/tests/fixtures/extra/autolink_lines.text0000644000076500000240000000004112416110764024067 0ustar lepturestaff00000000000000hello world mistune-0.7.1/tests/fixtures/extra/blockquote_list_item.html0000644000076500000240000000015412416110764025255 0ustar lepturestaff00000000000000

      This fails in markdown.pl and upskirt:

      • hello

        world

      mistune-0.7.1/tests/fixtures/extra/blockquote_list_item.text0000644000076500000240000000007212416110764025274 0ustar lepturestaff00000000000000This fails in markdown.pl and upskirt: * hello > world mistune-0.7.1/tests/fixtures/extra/case_insensitive_refs.html0000644000076500000240000000003512416110764025404 0ustar lepturestaff00000000000000

      hi

      mistune-0.7.1/tests/fixtures/extra/case_insensitive_refs.text0000644000076500000240000000002112416110764025417 0ustar lepturestaff00000000000000[hi] [HI]: /url mistune-0.7.1/tests/fixtures/extra/double_link.html0000644000076500000240000000036012531506273023324 0ustar lepturestaff00000000000000

      Already linked: http://example.com/.

      Already linked: http://example.com/.

      Already linked: **http://example.com/**.

      mistune-0.7.1/tests/fixtures/extra/double_link.text0000644000076500000240000000032712416110764023345 0ustar lepturestaff00000000000000

      Already linked: http://example.com/.

      Already linked: [http://example.com/](http://example.com/). Already linked: **http://example.com/**. mistune-0.7.1/tests/fixtures/extra/escaped_angles.html0000644000076500000240000000001112416110764023761 0ustar lepturestaff00000000000000

      >

      mistune-0.7.1/tests/fixtures/extra/escaped_angles.text0000644000076500000240000000000312416110764024002 0ustar lepturestaff00000000000000\> mistune-0.7.1/tests/fixtures/extra/footnotes.html0000644000076500000240000000526712416110764023066 0ustar lepturestaff00000000000000

      This is the first paragraph.1

      • List item one.2
      • List item two.3

      Header4

      Some paragraph with a footnote5, and another6.

      Another paragraph with a named footnote7.

      This paragraph should not have a footnote marker since the footnote is undefined.[^3]

      This paragraph should not have a footnote marker since the footnote has already been used before.[^1]

      This paragraph links to a footnote with plenty of block-level content.8

      This paragraph host the footnote reference within a footnote test9.


      1. This is the first note.

      2. This is the second note.

      3. This is the third note, defined out of order.

      4. This is the fourth note.

      5. Content for fifth footnote.

      6. Content for sixth footnote spaning on three lines, with some span-level markup like emphasis, a link.

      7. Footnote beginning on the line next to the marker.

      8. Paragraph.

        • List item

        Blockquote

        Code block
        

      9. This footnote attemps to refer to another footnote. This should be impossible.[^impossible]

      mistune-0.7.1/tests/fixtures/extra/footnotes.text0000644000076500000240000000241212416110764023073 0ustar lepturestaff00000000000000This is the first paragraph.[^first] [^first]: This is the first note. * List item one.[^second] * List item two.[^third] [^third]: This is the third note, defined out of order. [^second]: This is the second note. [^fourth]: This is the fourth note. # Header[^fourth] Some paragraph with a footnote[^1], and another[^2]. [^1]: Content for fifth footnote. [^2]: Content for sixth footnote spaning on three lines, with some span-level markup like _emphasis_, a [link][]. [link]: http://www.michelf.com/ Another paragraph with a named footnote[^fn-name]. [^fn-name]: Footnote beginning on the line next to the marker. This paragraph should not have a footnote marker since the footnote is undefined.[^3] This paragraph should not have a footnote marker since the footnote has already been used before.[^1] This paragraph links to a footnote with plenty of block-level content.[^block] [^block]: Paragraph. * List item > Blockquote Code block This paragraph host the footnote reference within a footnote test[^reference]. [^reference]: This footnote attemps to refer to another footnote. This should be impossible.[^impossible] [^impossible]: This footnote should not appear, as it is refered from another footnote, which is not allowed. mistune-0.7.1/tests/fixtures/extra/gfm_code.html0000644000076500000240000000052512416110764022601 0ustar lepturestaff00000000000000
      var a = 'hello';
      console.log(a + ' world');
      echo "hello, ${WORLD}"
      Q: What do you call a tall person who sells stolen goods?
      A longfence!
      mistune-0.7.1/tests/fixtures/extra/gfm_code.text0000644000076500000240000000033712416110764022622 0ustar lepturestaff00000000000000``` js var a = 'hello'; console.log(a + ' world'); ``` ~~~bash echo "hello, ${WORLD}" ~~~ ```````longfence Q: What do you call a tall person who sells stolen goods? ``````` ~~~~~~~~~~ ManyTildes A longfence! ~~~~~~~~~~ mistune-0.7.1/tests/fixtures/extra/gfm_code_hr_list.html0000644000076500000240000000127212416110764024325 0ustar lepturestaff00000000000000

      foo

      1. bar:

        • one
          • two
            • three
            • four
            • five
      2. foo:

         line 1
         line 2
      3. foo:

        1. foo bar bar:

           some code here
          
        2. foo bar bar:

           foo
           ---
           bar
           ---
           foo
           bar
        3. foo bar bar:

           ---
           foo
           foo
           ---
           bar
        4. foo bar bar:

           foo
           ---
           bar
        5. foo

      mistune-0.7.1/tests/fixtures/extra/gfm_code_hr_list.text0000644000076500000240000000105212416110764024341 0ustar lepturestaff00000000000000## foo 1. bar: > - one - two - three - four - five 1. foo: ``` line 1 line 2 ``` 1. foo: 1. foo `bar` bar: ``` erb some code here ``` 2. foo `bar` bar: ``` erb foo --- bar --- foo bar ``` 3. foo `bar` bar: ``` html --- foo foo --- bar ``` 4. foo `bar` bar: foo --- bar 5. foo mistune-0.7.1/tests/fixtures/extra/gfm_del.html0000644000076500000240000000004112416110764022424 0ustar lepturestaff00000000000000

      hello hi world

      mistune-0.7.1/tests/fixtures/extra/gfm_del.text0000644000076500000240000000002312416110764022444 0ustar lepturestaff00000000000000hello ~~hi~~ world mistune-0.7.1/tests/fixtures/extra/gfm_em.html0000644000076500000240000000005512416110764022266 0ustar lepturestaff00000000000000

      These words should_not_be_emphasized.

      mistune-0.7.1/tests/fixtures/extra/gfm_em.text0000644000076500000240000000004612416110764022306 0ustar lepturestaff00000000000000These words should_not_be_emphasized. mistune-0.7.1/tests/fixtures/extra/gfm_links.html0000644000076500000240000000015312416110764023004 0ustar lepturestaff00000000000000

      This should be a link: http://example.com/hello-world.

      mistune-0.7.1/tests/fixtures/extra/gfm_links.text0000644000076500000240000000006712416110764023030 0ustar lepturestaff00000000000000This should be a link: http://example.com/hello-world. mistune-0.7.1/tests/fixtures/extra/gfm_tables.html0000644000076500000240000000261712416110764023145 0ustar lepturestaff00000000000000
      Heading 1Heading 2
      Cell 1Cell 2
      Cell 3Cell 4
      Header 1Header 2Header 3Header 4
      Cell 1Cell 2Cell 3Cell 4
      Cell 5Cell 6Cell 7Cell 8
      Test code
      Header 1Header 2
      Cell 1Cell 2
      Cell 3Cell 4
      Header 1Header 2Header 3Header 4
      Cell 1Cell 2Cell 3Cell 4
      Cell 5Cell 6Cell 7Cell 8
      mistune-0.7.1/tests/fixtures/extra/gfm_tables.text0000644000076500000240000000077412416110764023167 0ustar lepturestaff00000000000000| Heading 1 | Heading 2 | --------- | --------- | Cell 1 | Cell 2 | Cell 3 | Cell 4 | Header 1 | Header 2 | Header 3 | Header 4 | | :------: | -------: | :------- | -------- | | Cell 1 | Cell 2 | Cell 3 | Cell 4 | | Cell 5 | Cell 6 | Cell 7 | Cell 8 | Test code Header 1 | Header 2 -------- | -------- Cell 1 | Cell 2 Cell 3 | Cell 4 Header 1|Header 2|Header 3|Header 4 :-------|:------:|-------:|-------- Cell 1 |Cell 2 |Cell 3 |Cell 4 *Cell 5*|Cell 6 |Cell 7 |Cell 8 mistune-0.7.1/tests/fixtures/extra/gfm_tables_uneven.html0000644000076500000240000000022512461415673024525 0ustar lepturestaff00000000000000
      x y z
      1 2 3 4
      mistune-0.7.1/tests/fixtures/extra/gfm_tables_uneven.text0000644000076500000240000000004212461415673024542 0ustar lepturestaff00000000000000x | y | z --- | --- 1 | 2 | 3 | 4 mistune-0.7.1/tests/fixtures/extra/hr_list_break.html0000644000076500000240000000011212416110764023636 0ustar lepturestaff00000000000000
      • hello world
      • how are

      you today?

      mistune-0.7.1/tests/fixtures/extra/hr_list_break.text0000644000076500000240000000005112416110764023660 0ustar lepturestaff00000000000000* hello world * how are * * * you today? mistune-0.7.1/tests/fixtures/extra/lazy_blockquotes.html0000644000076500000240000000006112416110764024423 0ustar lepturestaff00000000000000

      hi there bud

      mistune-0.7.1/tests/fixtures/extra/lazy_blockquotes.text0000644000076500000240000000001712416110764024444 0ustar lepturestaff00000000000000> hi there bud mistune-0.7.1/tests/fixtures/extra/list_item_text.html0000644000076500000240000000010612416110764024066 0ustar lepturestaff00000000000000
      • item1

        • item2

        text

      mistune-0.7.1/tests/fixtures/extra/list_item_text.text0000644000076500000240000000003712416110764024111 0ustar lepturestaff00000000000000 * item1 * item2 text mistune-0.7.1/tests/fixtures/extra/loose_lists.html0000644000076500000240000000111212416110764023366 0ustar lepturestaff00000000000000
      • hello world

        how are

      • you

      better behavior:

      • hello

        • world how

          are you

        • today

      • hi
      • hello

      • world

      • hi
      • hello
      • world

      • hi

      • hello
      • world

        how

      • hi
      • hello
      • world
      • how

        are

      • hello
      • world

      • how

        are

      mistune-0.7.1/tests/fixtures/extra/loose_lists.text0000644000076500000240000000040512416110764023412 0ustar lepturestaff00000000000000* hello world how are * you better behavior: * hello * world how are you * today * hi * hello * world * hi * hello * world * hi * hello * world how * hi * hello * world * how are * hello * world * how are mistune-0.7.1/tests/fixtures/extra/main.html0000644000076500000240000000236012416110764021761 0ustar lepturestaff00000000000000

      A heading

      Just a note, I've found that I can't test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They're also completely inconsistent with regards to paragraphs in list items.

      A link. Not anymore.

      • List Item 1

      • List Item 2

        • New List Item 1 Hi, this is a list item.
        • New List Item 2 Another item
          Code goes here.
          Lots of it...
        • New List Item 3 The last item
      • List Item 3 The final item.

      • List Item 4 The real final item.

      Paragraph.

      • bq Item 1
      • bq Item 2
        • New bq Item 1
        • New bq Item 2 Text here

      Another blockquote! I really need to get more creative with mockup text.. markdown.js breaks here again

      Another Heading

      Hello world. Here is a link. And an image alt.

      Code goes here.
      Lots of it...
      mistune-0.7.1/tests/fixtures/extra/main.text0000644000076500000240000000201512416110764021776 0ustar lepturestaff00000000000000[test]: http://google.com/ "Google" # A heading Just a note, I've found that I can't test my markdown parser vs others. For example, both markdown.js and showdown code blocks in lists wrong. They're also completely [inconsistent][test] with regards to paragraphs in list items. A link. Not anymore. * List Item 1 * List Item 2 * New List Item 1 Hi, this is a list item. * New List Item 2 Another item Code goes here. Lots of it... * New List Item 3 The last item * List Item 3 The final item. * List Item 4 The real final item. Paragraph. > * bq Item 1 > * bq Item 2 > * New bq Item 1 > * New bq Item 2 > Text here * * * > Another blockquote! > I really need to get > more creative with > mockup text.. > markdown.js breaks here again Another Heading ------------- Hello *world*. Here is a [link](//hello). And an image ![alt](src). Code goes here. Lots of it... mistune-0.7.1/tests/fixtures/extra/nested_code.html0000644000076500000240000000004612416110764023310 0ustar lepturestaff00000000000000

      hi ther `` ok ```

      mistune-0.7.1/tests/fixtures/extra/nested_code.text0000644000076500000240000000003612416110764023327 0ustar lepturestaff00000000000000````` hi ther `` ok ``` ````` mistune-0.7.1/tests/fixtures/extra/nested_em.html0000644000076500000240000000014112416110764022773 0ustar lepturestaff00000000000000

      test test test

      test test test

      mistune-0.7.1/tests/fixtures/extra/nested_em.text0000644000076500000240000000005312416110764023015 0ustar lepturestaff00000000000000*test **test** test* _test __test__ test_ mistune-0.7.1/tests/fixtures/extra/nested_square_link.html0000644000076500000240000000006712416110764024716 0ustar lepturestaff00000000000000

      the ] character

      mistune-0.7.1/tests/fixtures/extra/nested_square_link.text0000644000076500000240000000003212416110764024726 0ustar lepturestaff00000000000000[the `]` character](/url) mistune-0.7.1/tests/fixtures/extra/not_a_link.html0000644000076500000240000000003212416110764023144 0ustar lepturestaff00000000000000

      [test](not a link)

      mistune-0.7.1/tests/fixtures/extra/not_a_link.text0000644000076500000240000000002412416110764023165 0ustar lepturestaff00000000000000\[test](not a link) mistune-0.7.1/tests/fixtures/extra/ref_paren.html0000644000076500000240000000005312416110764022773 0ustar lepturestaff00000000000000

      hi

      mistune-0.7.1/tests/fixtures/extra/ref_paren.text0000644000076500000240000000003112416110764023007 0ustar lepturestaff00000000000000[hi] [hi]: /url (there) mistune-0.7.1/tests/fixtures/extra/same_bullet.html0000644000076500000240000000006512416110764023331 0ustar lepturestaff00000000000000
      • test
      • test
      • test
      mistune-0.7.1/tests/fixtures/extra/same_bullet.text0000644000076500000240000000002512416110764023345 0ustar lepturestaff00000000000000* test + test - test mistune-0.7.1/tests/fixtures/extra/toplevel_paragraphs.gfm.html0000644000076500000240000000077112416110764025653 0ustar lepturestaff00000000000000

      hello world how are you how are you

      hello world

      how are you

      hello world


      hello world

      how are you

      hello world

      how are you

      hello world

      how are you

      hello world

      • how are you

      hello world

      how are you

      hello world how are you

      hello world

      hello

      hello

      mistune-0.7.1/tests/fixtures/extra/toplevel_paragraphs.gfm.text0000644000076500000240000000055212416110764025670 0ustar lepturestaff00000000000000hello world how are you how are you hello world ``` how are you ``` hello world * * * hello world # how are you hello world how are you =========== hello world > how are you hello world * how are you hello world
      how are you
      hello world how are you hello [world][how] [how]: /are/you
      hello
      hello mistune-0.7.1/tests/fixtures/extra/tricky_list.html0000644000076500000240000000047312416110764023400 0ustar lepturestaff00000000000000

      hello world

      • hello world

      hello world

      • hello world

      hello world

      • Hello world

      hello world

      • hello world
      mistune-0.7.1/tests/fixtures/extra/tricky_list.text0000644000076500000240000000020712416110764023413 0ustar lepturestaff00000000000000**hello** _world_ * hello world **hello** _world_ * hello world **hello** _world_ * Hello world **hello** _world_ * hello world mistune-0.7.1/tests/fixtures/normal/0000755000076500000240000000000012566114341020314 5ustar lepturestaff00000000000000mistune-0.7.1/tests/fixtures/normal/amps_and_angles_encoding.html0000644000076500000240000000076012416110764026165 0ustar lepturestaff00000000000000

      AT&T has an ampersand in their name.

      AT&T is another way to write it.

      This & that.

      4 < 5.

      6 > 5.

      Here's a link with an ampersand in the URL.

      Here's a link with an amersand in the link text: AT&T.

      Here's an inline link.

      Here's an inline link.

      mistune-0.7.1/tests/fixtures/normal/amps_and_angles_encoding.text0000644000076500000240000000057612416110764026212 0ustar lepturestaff00000000000000AT&T has an ampersand in their name. AT&T is another way to write it. This & that. 4 < 5. 6 > 5. Here's a [link] [1] with an ampersand in the URL. Here's a link with an amersand in the link text: [AT&T] [2]. Here's an inline [link](/script?foo=1&bar=2). Here's an inline [link](). [1]: http://example.com/?foo=1&bar=2 [2]: http://att.com/ "AT&T" mistune-0.7.1/tests/fixtures/normal/auto_email.html0000644000076500000240000000012212416110764023313 0ustar lepturestaff00000000000000

      This should be a link: me@example.com.

      mistune-0.7.1/tests/fixtures/normal/auto_email.text0000644000076500000240000000005112416110764023334 0ustar lepturestaff00000000000000This should be a link: . mistune-0.7.1/tests/fixtures/normal/auto_links.html0000644000076500000240000000104212416110764023346 0ustar lepturestaff00000000000000

      Link: http://example.com/.

      With an ampersand: http://example.com/?foo=1&bar=2

      Blockquoted: http://example.com/

      Auto-links should not occur here: <http://example.com/>

      or here: <http://example.com/>
      
      mistune-0.7.1/tests/fixtures/normal/auto_links.text0000644000076500000240000000041012416110764023364 0ustar lepturestaff00000000000000Link: . With an ampersand: * In a list? * * It should. > Blockquoted: Auto-links should not occur here: `` or here: mistune-0.7.1/tests/fixtures/normal/backslash_escapes.html0000644000076500000240000000326112416110764024641 0ustar lepturestaff00000000000000

      These should all get escaped:

      Backslash: \

      Backtick: `

      Asterisk: *

      Underscore: _

      Left brace: {

      Right brace: }

      Left bracket: [

      Right bracket: ]

      Left paren: (

      Right paren: )

      Greater-than: >

      Hash: #

      Period: .

      Bang: !

      Plus: +

      Minus: -

      These should not, because they occur within a code block:

      Backslash: \\
      
      Backtick: \`
      
      Asterisk: \*
      
      Underscore: \_
      
      Left brace: \{
      
      Right brace: \}
      
      Left bracket: \[
      
      Right bracket: \]
      
      Left paren: \(
      
      Right paren: \)
      
      Greater-than: \>
      
      Hash: \#
      
      Period: \.
      
      Bang: \!
      
      Plus: \+
      
      Minus: \-
      

      Nor should these, which occur in code spans:

      Backslash: \\

      Backtick: \`

      Asterisk: \*

      Underscore: \_

      Left brace: \{

      Right brace: \}

      Left bracket: \[

      Right bracket: \]

      Left paren: \(

      Right paren: \)

      Greater-than: \>

      Hash: \#

      Period: \.

      Bang: \!

      Plus: \+

      Minus: \-

      These should get escaped, even though they're matching pairs for other Markdown constructs:

      *asterisks*

      _underscores_

      `backticks`

      This is a code span with a literal backslash-backtick sequence: \`

      This is a tag with unescaped backticks bar.

      This is a tag with backslashes bar.

      mistune-0.7.1/tests/fixtures/normal/backslash_escapes.text0000644000076500000240000000234212416110764024660 0ustar lepturestaff00000000000000These should all get escaped: Backslash: \\ Backtick: \` Asterisk: \* Underscore: \_ Left brace: \{ Right brace: \} Left bracket: \[ Right bracket: \] Left paren: \( Right paren: \) Greater-than: \> Hash: \# Period: \. Bang: \! Plus: \+ Minus: \- These should not, because they occur within a code block: Backslash: \\ Backtick: \` Asterisk: \* Underscore: \_ Left brace: \{ Right brace: \} Left bracket: \[ Right bracket: \] Left paren: \( Right paren: \) Greater-than: \> Hash: \# Period: \. Bang: \! Plus: \+ Minus: \- Nor should these, which occur in code spans: Backslash: `\\` Backtick: `` \` `` Asterisk: `\*` Underscore: `\_` Left brace: `\{` Right brace: `\}` Left bracket: `\[` Right bracket: `\]` Left paren: `\(` Right paren: `\)` Greater-than: `\>` Hash: `\#` Period: `\.` Bang: `\!` Plus: `\+` Minus: `\-` These should get escaped, even though they're matching pairs for other Markdown constructs: \*asterisks\* \_underscores\_ \`backticks\` This is a code span with a literal backslash-backtick sequence: `` \` `` This is a tag with unescaped backticks bar. This is a tag with backslashes bar. mistune-0.7.1/tests/fixtures/normal/blockquotes_with_code_blocks.html0000644000076500000240000000027212416110764027117 0ustar lepturestaff00000000000000

      Example:

      sub status {
          print "working";
      }
      

      Or:

      sub status {
          return "working";
      }
      
      mistune-0.7.1/tests/fixtures/normal/blockquotes_with_code_blocks.text0000644000076500000240000000020712416110764027135 0ustar lepturestaff00000000000000> Example: > > sub status { > print "working"; > } > > Or: > > sub status { > return "working"; > } mistune-0.7.1/tests/fixtures/normal/code_blocks.html0000644000076500000240000000047012416110764023451 0ustar lepturestaff00000000000000
      code block on the first line
      

      Regular text.

      code block indented by spaces
      

      Regular text.

      the lines in this block  
      all contain trailing spaces  
      

      Regular Text.

      code block on the last line
      
      mistune-0.7.1/tests/fixtures/normal/code_blocks.text0000644000076500000240000000031012416110764023462 0ustar lepturestaff00000000000000 code block on the first line Regular text. code block indented by spaces Regular text. the lines in this block all contain trailing spaces Regular Text. code block on the last line mistune-0.7.1/tests/fixtures/normal/code_spans.html0000644000076500000240000000055612416110764023325 0ustar lepturestaff00000000000000

      <test a=" content of attribute ">

      Fix for backticks within HTML tag: like this

      Here's how you put `backticks` in a code span.

      From <!-- to --> on two lines.

      From <!-- to --> on three lines.

      mistune-0.7.1/tests/fixtures/normal/code_spans.text0000644000076500000240000000036012416110764023336 0ustar lepturestaff00000000000000`` Fix for backticks within HTML tag: like this Here's how you put `` `backticks` `` in a code span. From `` on two lines. From `` on three lines. mistune-0.7.1/tests/fixtures/normal/headers.html0000644000076500000240000000050612416110764022615 0ustar lepturestaff00000000000000

      Header

      Header

      Header


      Header

      Paragraph

      Header

      Paragraph

      Header

      Paragraph


      Paragraph

      Header

      Paragraph

      Paragraph

      Header

      Paragraph

      Paragraph

      Header

      Paragraph

      mistune-0.7.1/tests/fixtures/normal/headers.text0000644000076500000240000000034712416110764022640 0ustar lepturestaff00000000000000Header ====== Header ------ ### Header - - - Header ====== Paragraph Header ------ Paragraph ### Header Paragraph - - - Paragraph Header ====== Paragraph Paragraph Header ------ Paragraph Paragraph ### Header Paragraph mistune-0.7.1/tests/fixtures/normal/horizontal_rules.html0000644000076500000240000000060112416110764024601 0ustar lepturestaff00000000000000

      Dashes:





      ---
      




      - - -
      

      Asterisks:





      ***
      




      * * *
      

      Underscores:





      ___
      




      _ _ _
      
      mistune-0.7.1/tests/fixtures/normal/horizontal_rules.text0000644000076500000240000000041612416110764024625 0ustar lepturestaff00000000000000Dashes: --- --- --- --- --- - - - - - - - - - - - - - - - Asterisks: *** *** *** *** *** * * * * * * * * * * * * * * * Underscores: ___ ___ ___ ___ ___ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ mistune-0.7.1/tests/fixtures/normal/inline_html_advanced.html0000644000076500000240000000024512416110764025331 0ustar lepturestaff00000000000000

      Simple block on one line:

      foo

      And nested without indentation:

      foo
      bar
      mistune-0.7.1/tests/fixtures/normal/inline_html_advanced.text0000644000076500000240000000022712416110764025351 0ustar lepturestaff00000000000000Simple block on one line:
      foo
      And nested without indentation:
      foo
      bar
      mistune-0.7.1/tests/fixtures/normal/inline_html_comments.html0000644000076500000240000000027412416110764025413 0ustar lepturestaff00000000000000

      Paragraph one.

      Paragraph two.

      The end.

      mistune-0.7.1/tests/fixtures/normal/inline_html_comments.text0000644000076500000240000000024412416110764025430 0ustar lepturestaff00000000000000Paragraph one. Paragraph two. The end. mistune-0.7.1/tests/fixtures/normal/inline_html_simple.html0000644000076500000240000000142012416110764025051 0ustar lepturestaff00000000000000

      Here's a simple block:

      foo

      This should be a code block, though:

      <div>
          foo
      </div>
      

      As should this:

      <div>foo</div>
      

      Now, nested:

      foo

      This should just be an HTML comment:

      Multiline:

      Code block:

      <!-- Comment -->
      

      Just plain comment, with trailing spaces on the line:

      Code:

      <hr />
      

      Hr's:










      mistune-0.7.1/tests/fixtures/normal/inline_html_simple.text0000644000076500000240000000105112416110764025071 0ustar lepturestaff00000000000000Here's a simple block:
      foo
      This should be a code block, though:
      foo
      As should this:
      foo
      Now, nested:
      foo
      This should just be an HTML comment: Multiline: Code block: Just plain comment, with trailing spaces on the line: Code:
      Hr's:








      mistune-0.7.1/tests/fixtures/normal/links_inline_style.html0000644000076500000240000000076012416110764025102 0ustar lepturestaff00000000000000

      Just a URL.

      URL and title.

      URL and title.

      URL and title.

      URL and title.

      URL and title.

      URL and title.

      Empty.

      mistune-0.7.1/tests/fixtures/normal/links_inline_style.text0000644000076500000240000000051012416110764025113 0ustar lepturestaff00000000000000Just a [URL](/url/). [URL and title](/url/ "title"). [URL and title](/url/ "title preceded by two spaces"). [URL and title](/url/ "title preceded by a tab"). [URL and title](/url/ "title has spaces afterward" ). [URL and title]( /url/has space ). [URL and title]( /url/has space/ "url has space and title"). [Empty](). mistune-0.7.1/tests/fixtures/normal/links_reference_style.html0000644000076500000240000000214112416110764025555 0ustar lepturestaff00000000000000

      Foo bar.

      Foo bar.

      Foo bar.

      With embedded [brackets].

      Indented once.

      Indented twice.

      Indented thrice.

      Indented [four][] times.

      [four]: /url
      

      this should work

      So should this.

      And this.

      And this.

      And this.

      But not [that] [].

      Nor [that][].

      Nor [that].

      [Something in brackets like this should work]

      [Same with this.]

      In this case, this points to something else.

      Backslashing should suppress [this] and [this].


      Here's one where the link breaks across lines.

      Here's another where the link breaks across lines, but with a line-ending space.

      mistune-0.7.1/tests/fixtures/normal/links_reference_style.text0000644000076500000240000000142712416110764025603 0ustar lepturestaff00000000000000Foo [bar] [1]. Foo [bar][1]. Foo [bar] [1]. [1]: /url/ "Title" With [embedded [brackets]] [b]. Indented [once][]. Indented [twice][]. Indented [thrice][]. Indented [four][] times. [once]: /url [twice]: /url [thrice]: /url [four]: /url [b]: /url/ * * * [this] [this] should work So should [this][this]. And [this] []. And [this][]. And [this]. But not [that] []. Nor [that][]. Nor [that]. [Something in brackets like [this][] should work] [Same with [this].] In this case, [this](/somethingelse/) points to something else. Backslashing should suppress \[this] and [this\]. [this]: foo * * * Here's one where the [link breaks] across lines. Here's another where the [link breaks] across lines, but with a line-ending space. [link breaks]: /url/ mistune-0.7.1/tests/fixtures/normal/links_shortcut_references.html0000644000076500000240000000040012416110764026447 0ustar lepturestaff00000000000000

      This is the simple case.

      This one has a line break.

      This one has a line break with a line-ending space.

      this and the other

      mistune-0.7.1/tests/fixtures/normal/links_shortcut_references.text0000644000076500000240000000035412416110764026477 0ustar lepturestaff00000000000000This is the [simple case]. [simple case]: /simple This one has a [line break]. This one has a [line break] with a line-ending space. [line break]: /foo [this] [that] and the [other] [this]: /this [that]: /that [other]: /other mistune-0.7.1/tests/fixtures/normal/literal_quotes_in_titles.html0000644000076500000240000000024312416110764026306 0ustar lepturestaff00000000000000

      Foo bar.

      Foo bar.

      mistune-0.7.1/tests/fixtures/normal/literal_quotes_in_titles.text0000644000076500000240000000015412416110764026327 0ustar lepturestaff00000000000000Foo [bar][]. Foo [bar](/url/ "Title with "quotes" inside"). [bar]: /url/ "Title with "quotes" inside" mistune-0.7.1/tests/fixtures/normal/markdown_documentation_basics.html0000644000076500000240000002225012416110764027301 0ustar lepturestaff00000000000000

      Markdown: Basics

      Getting the Gist of Markdown's Formatting Syntax

      This page offers a brief overview of what it's like to use Markdown. The syntax page provides complete, detailed documentation for every feature, but Markdown should be very easy to pick up simply by looking at a few examples of it in action. The examples on this page are written in a before/after style, showing example syntax and the HTML output produced by Markdown.

      It's also helpful to simply try Markdown out; the Dingus is a web application that allows you type your own Markdown-formatted text and translate it to XHTML.

      Note: This document is itself written using Markdown; you can see the source for it by adding '.text' to the URL.

      Paragraphs, Headers, Blockquotes

      A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing spaces or tabs is considered blank.) Normal paragraphs should not be intended with spaces or tabs.

      Markdown offers two styles of headers: Setext and atx. Setext-style headers for <h1> and <h2> are created by "underlining" with equal signs (=) and hyphens (-), respectively. To create an atx-style header, you put 1-6 hash marks (#) at the beginning of the line -- the number of hashes equals the resulting HTML header level.

      Blockquotes are indicated using email-style '>' angle brackets.

      Markdown:

      A First Level Header
      ====================
      
      A Second Level Header
      ---------------------
      
      Now is the time for all good men to come to
      the aid of their country. This is just a
      regular paragraph.
      
      The quick brown fox jumped over the lazy
      dog's back.
      
      ### Header 3
      
      > This is a blockquote.
      > 
      > This is the second paragraph in the blockquote.
      >
      > ## This is an H2 in a blockquote
      

      Output:

      <h1>A First Level Header</h1>
      
      <h2>A Second Level Header</h2>
      
      <p>Now is the time for all good men to come to
      the aid of their country. This is just a
      regular paragraph.</p>
      
      <p>The quick brown fox jumped over the lazy
      dog's back.</p>
      
      <h3>Header 3</h3>
      
      <blockquote>
          <p>This is a blockquote.</p>
      
          <p>This is the second paragraph in the blockquote.</p>
      
          <h2>This is an H2 in a blockquote</h2>
      </blockquote>
      

      Phrase Emphasis

      Markdown uses asterisks and underscores to indicate spans of emphasis.

      Markdown:

      Some of these words *are emphasized*.
      Some of these words _are emphasized also_.
      
      Use two asterisks for **strong emphasis**.
      Or, if you prefer, __use two underscores instead__.
      

      Output:

      <p>Some of these words <em>are emphasized</em>.
      Some of these words <em>are emphasized also</em>.</p>
      
      <p>Use two asterisks for <strong>strong emphasis</strong>.
      Or, if you prefer, <strong>use two underscores instead</strong>.</p>
      

      Lists

      Unordered (bulleted) lists use asterisks, pluses, and hyphens (*, +, and -) as list markers. These three markers are interchangable; this:

      *   Candy.
      *   Gum.
      *   Booze.
      

      this:

      +   Candy.
      +   Gum.
      +   Booze.
      

      and this:

      -   Candy.
      -   Gum.
      -   Booze.
      

      all produce the same output:

      <ul>
      <li>Candy.</li>
      <li>Gum.</li>
      <li>Booze.</li>
      </ul>
      

      Ordered (numbered) lists use regular numbers, followed by periods, as list markers:

      1.  Red
      2.  Green
      3.  Blue
      

      Output:

      <ol>
      <li>Red</li>
      <li>Green</li>
      <li>Blue</li>
      </ol>
      

      If you put blank lines between items, you'll get <p> tags for the list item text. You can create multi-paragraph list items by indenting the paragraphs by 4 spaces or 1 tab:

      *   A list item.
      
          With multiple paragraphs.
      
      *   Another item in the list.
      

      Output:

      <ul>
      <li><p>A list item.</p>
      <p>With multiple paragraphs.</p></li>
      <li><p>Another item in the list.</p></li>
      </ul>
      

      Links

      Markdown supports two styles for creating links: inline and reference. With both styles, you use square brackets to delimit the text you want to turn into a link.

      Inline-style links use parentheses immediately after the link text. For example:

      This is an [example link](http://example.com/).
      

      Output:

      <p>This is an <a href="http://example.com/">
      example link</a>.</p>
      

      Optionally, you may include a title attribute in the parentheses:

      This is an [example link](http://example.com/ "With a Title").
      

      Output:

      <p>This is an <a href="http://example.com/" title="With a Title">
      example link</a>.</p>
      

      Reference-style links allow you to refer to your links by names, which you define elsewhere in your document:

      I get 10 times more traffic from [Google][1] than from
      [Yahoo][2] or [MSN][3].
      
      [1]: http://google.com/        "Google"
      [2]: http://search.yahoo.com/  "Yahoo Search"
      [3]: http://search.msn.com/    "MSN Search"
      

      Output:

      <p>I get 10 times more traffic from <a href="http://google.com/"
      title="Google">Google</a> than from <a href="http://search.yahoo.com/"
      title="Yahoo Search">Yahoo</a> or <a href="http://search.msn.com/"
      title="MSN Search">MSN</a>.</p>
      

      The title attribute is optional. Link names may contain letters, numbers and spaces, but are not case sensitive:

      I start my morning with a cup of coffee and
      [The New York Times][NY Times].
      
      [ny times]: http://www.nytimes.com/
      

      Output:

      <p>I start my morning with a cup of coffee and
      <a href="http://www.nytimes.com/">The New York Times</a>.</p>
      

      Images

      Image syntax is very much like link syntax.

      Inline (titles are optional):

      ![alt text](/path/to/img.jpg "Title")
      

      Reference-style:

      ![alt text][id]
      
      [id]: /path/to/img.jpg "Title"
      

      Both of the above examples produce the same output:

      <img src="/path/to/img.jpg" alt="alt text" title="Title" />
      

      Code

      In a regular paragraph, you can create code span by wrapping text in backtick quotes. Any ampersands (&) and angle brackets (< or >) will automatically be translated into HTML entities. This makes it easy to use Markdown to write about HTML example code:

      I strongly recommend against using any `<blink>` tags.
      
      I wish SmartyPants used named entities like `&mdash;`
      instead of decimal-encoded entites like `&#8212;`.
      

      Output:

      <p>I strongly recommend against using any
      <code>&lt;blink&gt;</code> tags.</p>
      
      <p>I wish SmartyPants used named entities like
      <code>&amp;mdash;</code> instead of decimal-encoded
      entites like <code>&amp;#8212;</code>.</p>
      

      To specify an entire block of pre-formatted code, indent every line of the block by 4 spaces or 1 tab. Just like with code spans, &, <, and > characters will be escaped automatically.

      Markdown:

      If you want your page to validate under XHTML 1.0 Strict,
      you've got to put paragraph tags in your blockquotes:
      
          <blockquote>
              <p>For example.</p>
          </blockquote>
      

      Output:

      <p>If you want your page to validate under XHTML 1.0 Strict,
      you've got to put paragraph tags in your blockquotes:</p>
      
      <pre><code>&lt;blockquote&gt;
          &lt;p&gt;For example.&lt;/p&gt;
      &lt;/blockquote&gt;
      </code></pre>
      
      mistune-0.7.1/tests/fixtures/normal/markdown_documentation_basics.text0000644000076500000240000001760012416110764027324 0ustar lepturestaff00000000000000Markdown: Basics ================ Getting the Gist of Markdown's Formatting Syntax ------------------------------------------------ This page offers a brief overview of what it's like to use Markdown. The [syntax page] [s] provides complete, detailed documentation for every feature, but Markdown should be very easy to pick up simply by looking at a few examples of it in action. The examples on this page are written in a before/after style, showing example syntax and the HTML output produced by Markdown. It's also helpful to simply try Markdown out; the [Dingus] [d] is a web application that allows you type your own Markdown-formatted text and translate it to XHTML. **Note:** This document is itself written using Markdown; you can [see the source for it by adding '.text' to the URL] [src]. [s]: /projects/markdown/syntax "Markdown Syntax" [d]: /projects/markdown/dingus "Markdown Dingus" [src]: /projects/markdown/basics.text ## Paragraphs, Headers, Blockquotes ## A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing spaces or tabs is considered blank.) Normal paragraphs should not be intended with spaces or tabs. Markdown offers two styles of headers: *Setext* and *atx*. Setext-style headers for `

      ` and `

      ` are created by "underlining" with equal signs (`=`) and hyphens (`-`), respectively. To create an atx-style header, you put 1-6 hash marks (`#`) at the beginning of the line -- the number of hashes equals the resulting HTML header level. Blockquotes are indicated using email-style '`>`' angle brackets. Markdown: A First Level Header ==================== A Second Level Header --------------------- Now is the time for all good men to come to the aid of their country. This is just a regular paragraph. The quick brown fox jumped over the lazy dog's back. ### Header 3 > This is a blockquote. > > This is the second paragraph in the blockquote. > > ## This is an H2 in a blockquote Output:

      A First Level Header

      A Second Level Header

      Now is the time for all good men to come to the aid of their country. This is just a regular paragraph.

      The quick brown fox jumped over the lazy dog's back.

      Header 3

      This is a blockquote.

      This is the second paragraph in the blockquote.

      This is an H2 in a blockquote

      ### Phrase Emphasis ### Markdown uses asterisks and underscores to indicate spans of emphasis. Markdown: Some of these words *are emphasized*. Some of these words _are emphasized also_. Use two asterisks for **strong emphasis**. Or, if you prefer, __use two underscores instead__. Output:

      Some of these words are emphasized. Some of these words are emphasized also.

      Use two asterisks for strong emphasis. Or, if you prefer, use two underscores instead.

      ## Lists ## Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`, `+`, and `-`) as list markers. These three markers are interchangable; this: * Candy. * Gum. * Booze. this: + Candy. + Gum. + Booze. and this: - Candy. - Gum. - Booze. all produce the same output:
      • Candy.
      • Gum.
      • Booze.
      Ordered (numbered) lists use regular numbers, followed by periods, as list markers: 1. Red 2. Green 3. Blue Output:
      1. Red
      2. Green
      3. Blue
      If you put blank lines between items, you'll get `

      ` tags for the list item text. You can create multi-paragraph list items by indenting the paragraphs by 4 spaces or 1 tab: * A list item. With multiple paragraphs. * Another item in the list. Output:

      • A list item.

        With multiple paragraphs.

      • Another item in the list.

      ### Links ### Markdown supports two styles for creating links: *inline* and *reference*. With both styles, you use square brackets to delimit the text you want to turn into a link. Inline-style links use parentheses immediately after the link text. For example: This is an [example link](http://example.com/). Output:

      This is an example link.

      Optionally, you may include a title attribute in the parentheses: This is an [example link](http://example.com/ "With a Title"). Output:

      This is an example link.

      Reference-style links allow you to refer to your links by names, which you define elsewhere in your document: I get 10 times more traffic from [Google][1] than from [Yahoo][2] or [MSN][3]. [1]: http://google.com/ "Google" [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search" Output:

      I get 10 times more traffic from Google than from Yahoo or MSN.

      The title attribute is optional. Link names may contain letters, numbers and spaces, but are *not* case sensitive: I start my morning with a cup of coffee and [The New York Times][NY Times]. [ny times]: http://www.nytimes.com/ Output:

      I start my morning with a cup of coffee and The New York Times.

      ### Images ### Image syntax is very much like link syntax. Inline (titles are optional): ![alt text](/path/to/img.jpg "Title") Reference-style: ![alt text][id] [id]: /path/to/img.jpg "Title" Both of the above examples produce the same output: alt text ### Code ### In a regular paragraph, you can create code span by wrapping text in backtick quotes. Any ampersands (`&`) and angle brackets (`<` or `>`) will automatically be translated into HTML entities. This makes it easy to use Markdown to write about HTML example code: I strongly recommend against using any `` tags. I wish SmartyPants used named entities like `—` instead of decimal-encoded entites like `—`. Output:

      I strongly recommend against using any <blink> tags.

      I wish SmartyPants used named entities like &mdash; instead of decimal-encoded entites like &#8212;.

      To specify an entire block of pre-formatted code, indent every line of the block by 4 spaces or 1 tab. Just like with code spans, `&`, `<`, and `>` characters will be escaped automatically. Markdown: If you want your page to validate under XHTML 1.0 Strict, you've got to put paragraph tags in your blockquotes:

      For example.

      Output:

      If you want your page to validate under XHTML 1.0 Strict, you've got to put paragraph tags in your blockquotes:

      <blockquote>
              <p>For example.</p>
          </blockquote>
          
      mistune-0.7.1/tests/fixtures/normal/markdown_documentation_syntax.html0000644000076500000240000007604112416110764027372 0ustar lepturestaff00000000000000

      Markdown: Syntax

      Note: This document is itself written using Markdown; you can see the source for it by adding '.text' to the URL.


      Overview

      Philosophy

      Markdown is intended to be as easy-to-read and easy-to-write as is feasible.

      Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it's been marked up with tags or formatting instructions. While Markdown's syntax has been influenced by several existing text-to-HTML filters -- including Setext, atx, Textile, reStructuredText, Grutatext, and EtText -- the single biggest source of inspiration for Markdown's syntax is the format of plain text email.

      To this end, Markdown's syntax is comprised entirely of punctuation characters, which punctuation characters have been carefully chosen so as to look like what they mean. E.g., asterisks around a word actually look like *emphasis*. Markdown lists look like, well, lists. Even blockquotes look like quoted passages of text, assuming you've ever used email.

      Inline HTML

      Markdown's syntax is intended for one purpose: to be used as a format for writing for the web.

      Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown's formatting syntax only addresses issues that can be conveyed in plain text.

      For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags.

      The only restrictions are that block-level HTML elements -- e.g. <div>, <table>, <pre>, <p>, etc. -- must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) <p> tags around HTML block-level tags.

      For example, to add an HTML table to a Markdown article:

      This is a regular paragraph.
      
      <table>
          <tr>
              <td>Foo</td>
          </tr>
      </table>
      
      This is another regular paragraph.
      

      Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can't use Markdown-style *emphasis* inside an HTML block.

      Span-level HTML tags -- e.g. <span>, <cite>, or <del> -- can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you'd prefer to use HTML <a> or <img> tags instead of Markdown's link or image syntax, go right ahead.

      Unlike block-level HTML tags, Markdown syntax is processed within span-level tags.

      Automatic Escaping for Special Characters

      In HTML, there are two characters that demand special treatment: < and &. Left angle brackets are used to start tags; ampersands are used to denote HTML entities. If you want to use them as literal characters, you must escape them as entities, e.g. &lt;, and &amp;.

      Ampersands in particular are bedeviling for web writers. If you want to write about 'AT&T', you need to write 'AT&amp;T'. You even need to escape ampersands within URLs. Thus, if you want to link to:

      http://images.google.com/images?num=30&q=larry+bird
      

      you need to encode the URL as:

      http://images.google.com/images?num=30&amp;q=larry+bird
      

      in your anchor tag href attribute. Needless to say, this is easy to forget, and is probably the single most common source of HTML validation errors in otherwise well-marked-up web sites.

      Markdown allows you to use these characters naturally, taking care of all the necessary escaping for you. If you use an ampersand as part of an HTML entity, it remains unchanged; otherwise it will be translated into &amp;.

      So, if you want to include a copyright symbol in your article, you can write:

      &copy;
      

      and Markdown will leave it alone. But if you write:

      AT&T
      

      Markdown will translate it to:

      AT&amp;T
      

      Similarly, because Markdown supports inline HTML, if you use angle brackets as delimiters for HTML tags, Markdown will treat them as such. But if you write:

      4 < 5
      

      Markdown will translate it to:

      4 &lt; 5
      

      However, inside Markdown code spans and blocks, angle brackets and ampersands are always encoded automatically. This makes it easy to use Markdown to write about HTML code. (As opposed to raw HTML, which is a terrible format for writing about HTML syntax, because every single < and & in your example code needs to be escaped.)


      Block Elements

      Paragraphs and Line Breaks

      A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be intended with spaces or tabs.

      The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type's "Convert Line Breaks" option) which translate every line break character in a paragraph into a <br /> tag.

      When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

      Yes, this takes a tad more effort to create a <br />, but a simplistic "every line break is a <br />" rule wouldn't work for Markdown. Markdown's email-style blockquoting and multi-paragraph list items work best -- and look better -- when you format them with hard breaks.

      Markdown supports two styles of headers, Setext and atx.

      Setext-style headers are "underlined" using equal signs (for first-level headers) and dashes (for second-level headers). For example:

      This is an H1
      =============
      
      This is an H2
      -------------
      

      Any number of underlining ='s or -'s will work.

      Atx-style headers use 1-6 hash characters at the start of the line, corresponding to header levels 1-6. For example:

      # This is an H1
      
      ## This is an H2
      
      ###### This is an H6
      

      Optionally, you may "close" atx-style headers. This is purely cosmetic -- you can use this if you think it looks better. The closing hashes don't even need to match the number of hashes used to open the header. (The number of opening hashes determines the header level.) :

      # This is an H1 #
      
      ## This is an H2 ##
      
      ### This is an H3 ######
      

      Blockquotes

      Markdown uses email-style > characters for blockquoting. If you're familiar with quoting passages of text in an email message, then you know how to create a blockquote in Markdown. It looks best if you hard wrap the text and put a > before every line:

      > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
      > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
      > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
      > 
      > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
      > id sem consectetuer libero luctus adipiscing.
      

      Markdown allows you to be lazy and only put the > before the first line of a hard-wrapped paragraph:

      > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
      consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
      Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
      
      > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
      id sem consectetuer libero luctus adipiscing.
      

      Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by adding additional levels of >:

      > This is the first level of quoting.
      >
      > > This is nested blockquote.
      >
      > Back to the first level.
      

      Blockquotes can contain other Markdown elements, including headers, lists, and code blocks:

      > ## This is a header.
      > 
      > 1.   This is the first list item.
      > 2.   This is the second list item.
      > 
      > Here's some example code:
      > 
      >     return shell_exec("echo $input | $markdown_script");
      

      Any decent text editor should make email-style quoting easy. For example, with BBEdit, you can make a selection and choose Increase Quote Level from the Text menu.

      Lists

      Markdown supports ordered (numbered) and unordered (bulleted) lists.

      Unordered lists use asterisks, pluses, and hyphens -- interchangably -- as list markers:

      *   Red
      *   Green
      *   Blue
      

      is equivalent to:

      +   Red
      +   Green
      +   Blue
      

      and:

      -   Red
      -   Green
      -   Blue
      

      Ordered lists use numbers followed by periods:

      1.  Bird
      2.  McHale
      3.  Parish
      

      It's important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. The HTML Markdown produces from the above list is:

      <ol>
      <li>Bird</li>
      <li>McHale</li>
      <li>Parish</li>
      </ol>
      

      If you instead wrote the list in Markdown like this:

      1.  Bird
      1.  McHale
      1.  Parish
      

      or even:

      3. Bird
      1. McHale
      8. Parish
      

      you'd get the exact same HTML output. The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don't have to.

      If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

      List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab.

      To make lists look nice, you can wrap items with hanging indents:

      *   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
          Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
          viverra nec, fringilla in, laoreet vitae, risus.
      *   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
          Suspendisse id sem consectetuer libero luctus adipiscing.
      

      But if you want to be lazy, you don't have to:

      *   Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
      Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
      viverra nec, fringilla in, laoreet vitae, risus.
      *   Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
      Suspendisse id sem consectetuer libero luctus adipiscing.
      

      If list items are separated by blank lines, Markdown will wrap the items in <p> tags in the HTML output. For example, this input:

      *   Bird
      *   Magic
      

      will turn into:

      <ul>
      <li>Bird</li>
      <li>Magic</li>
      </ul>
      

      But this:

      *   Bird
      
      *   Magic
      

      will turn into:

      <ul>
      <li><p>Bird</p></li>
      <li><p>Magic</p></li>
      </ul>
      

      List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be intended by either 4 spaces or one tab:

      1.  This is a list item with two paragraphs. Lorem ipsum dolor
          sit amet, consectetuer adipiscing elit. Aliquam hendrerit
          mi posuere lectus.
      
          Vestibulum enim wisi, viverra nec, fringilla in, laoreet
          vitae, risus. Donec sit amet nisl. Aliquam semper ipsum
          sit amet velit.
      
      2.  Suspendisse id sem consectetuer libero luctus adipiscing.
      

      It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy:

      *   This is a list item with two paragraphs.
      
          This is the second paragraph in the list item. You're
      only required to indent the first line. Lorem ipsum dolor
      sit amet, consectetuer adipiscing elit.
      
      *   Another item in the same list.
      

      To put a blockquote within a list item, the blockquote's > delimiters need to be indented:

      *   A list item with a blockquote:
      
          > This is a blockquote
          > inside a list item.
      

      To put a code block within a list item, the code block needs to be indented twice -- 8 spaces or two tabs:

      *   A list item with a code block:
      
              <code goes here>
      

      It's worth noting that it's possible to trigger an ordered list by accident, by writing something like this:

      1986. What a great season.
      

      In other words, a number-period-space sequence at the beginning of a line. To avoid this, you can backslash-escape the period:

      1986\. What a great season.
      

      Code Blocks

      Pre-formatted code blocks are used for writing about programming or markup source code. Rather than forming normal paragraphs, the lines of a code block are interpreted literally. Markdown wraps a code block in both <pre> and <code> tags.

      To produce a code block in Markdown, simply indent every line of the block by at least 4 spaces or 1 tab. For example, given this input:

      This is a normal paragraph:
      
          This is a code block.
      

      Markdown will generate:

      <p>This is a normal paragraph:</p>
      
      <pre><code>This is a code block.
      </code></pre>
      

      One level of indentation -- 4 spaces or 1 tab -- is removed from each line of the code block. For example, this:

      Here is an example of AppleScript:
      
          tell application "Foo"
              beep
          end tell
      

      will turn into:

      <p>Here is an example of AppleScript:</p>
      
      <pre><code>tell application "Foo"
          beep
      end tell
      </code></pre>
      

      A code block continues until it reaches a line that is not indented (or the end of the article).

      Within a code block, ampersands (&) and angle brackets (< and >) are automatically converted into HTML entities. This makes it very easy to include example HTML source code using Markdown -- just paste it and indent it, and Markdown will handle the hassle of encoding the ampersands and angle brackets. For example, this:

          <div class="footer">
              &copy; 2004 Foo Corporation
          </div>
      

      will turn into:

      <pre><code>&lt;div class="footer"&gt;
          &amp;copy; 2004 Foo Corporation
      &lt;/div&gt;
      </code></pre>
      

      Regular Markdown syntax is not processed within code blocks. E.g., asterisks are just literal asterisks within a code block. This means it's also easy to use Markdown to write about Markdown's own syntax.

      Horizontal Rules

      You can produce a horizontal rule tag (<hr />) by placing three or more hyphens, asterisks, or underscores on a line by themselves. If you wish, you may use spaces between the hyphens or asterisks. Each of the following lines will produce a horizontal rule:

      * * *
      
      ***
      
      *****
      
      - - -
      
      ---------------------------------------
      
      _ _ _
      

      Span Elements

      Markdown supports two style of links: inline and reference.

      In both styles, the link text is delimited by [square brackets].

      To create an inline link, use a set of regular parentheses immediately after the link text's closing square bracket. Inside the parentheses, put the URL where you want the link to point, along with an optional title for the link, surrounded in quotes. For example:

      This is [an example](http://example.com/ "Title") inline link.
      
      [This link](http://example.net/) has no title attribute.
      

      Will produce:

      <p>This is <a href="http://example.com/" title="Title">
      an example</a> inline link.</p>
      
      <p><a href="http://example.net/">This link</a> has no
      title attribute.</p>
      

      If you're referring to a local resource on the same server, you can use relative paths:

      See my [About](/about/) page for details.
      

      Reference-style links use a second set of square brackets, inside which you place a label of your choosing to identify the link:

      This is [an example][id] reference-style link.
      

      You can optionally use a space to separate the sets of brackets:

      This is [an example] [id] reference-style link.
      

      Then, anywhere in the document, you define your link label like this, on a line by itself:

      [id]: http://example.com/  "Optional Title Here"
      

      That is:

      • Square brackets containing the link identifier (optionally indented from the left margin using up to three spaces);
      • followed by a colon;
      • followed by one or more spaces (or tabs);
      • followed by the URL for the link;
      • optionally followed by a title attribute for the link, enclosed in double or single quotes.

      The link URL may, optionally, be surrounded by angle brackets:

      [id]: <http://example.com/>  "Optional Title Here"
      

      You can put the title attribute on the next line and use extra spaces or tabs for padding, which tends to look better with longer URLs:

      [id]: http://example.com/longish/path/to/resource/here
          "Optional Title Here"
      

      Link definitions are only used for creating links during Markdown processing, and are stripped from your document in the HTML output.

      Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are not case sensitive. E.g. these two links:

      [link text][a]
      [link text][A]
      

      are equivalent.

      The implicit link name shortcut allows you to omit the name of the link, in which case the link text itself is used as the name. Just use an empty set of square brackets -- e.g., to link the word "Google" to the google.com web site, you could simply write:

      [Google][]
      

      And then define the link:

      [Google]: http://google.com/
      

      Because link names may contain spaces, this shortcut even works for multiple words in the link text:

      Visit [Daring Fireball][] for more information.
      

      And then define the link:

      [Daring Fireball]: http://daringfireball.net/
      

      Link definitions can be placed anywhere in your Markdown document. I tend to put them immediately after each paragraph in which they're used, but if you want, you can put them all at the end of your document, sort of like footnotes.

      Here's an example of reference links in action:

      I get 10 times more traffic from [Google] [1] than from
      [Yahoo] [2] or [MSN] [3].
      
        [1]: http://google.com/        "Google"
        [2]: http://search.yahoo.com/  "Yahoo Search"
        [3]: http://search.msn.com/    "MSN Search"
      

      Using the implicit link name shortcut, you could instead write:

      I get 10 times more traffic from [Google][] than from
      [Yahoo][] or [MSN][].
      
        [google]: http://google.com/        "Google"
        [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
        [msn]:    http://search.msn.com/    "MSN Search"
      

      Both of the above examples will produce the following HTML output:

      <p>I get 10 times more traffic from <a href="http://google.com/"
      title="Google">Google</a> than from
      <a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>
      or <a href="http://search.msn.com/" title="MSN Search">MSN</a>.</p>
      

      For comparison, here is the same paragraph written using Markdown's inline link style:

      I get 10 times more traffic from [Google](http://google.com/ "Google")
      than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or
      [MSN](http://search.msn.com/ "MSN Search").
      

      The point of reference-style links is not that they're easier to write. The point is that with reference-style links, your document source is vastly more readable. Compare the above examples: using reference-style links, the paragraph itself is only 81 characters long; with inline-style links, it's 176 characters; and as raw HTML, it's 234 characters. In the raw HTML, there's more markup than there is text.

      With Markdown's reference-style links, a source document much more closely resembles the final output, as rendered in a browser. By allowing you to move the markup-related metadata out of the paragraph, you can add links without interrupting the narrative flow of your prose.

      Emphasis

      Markdown treats asterisks (*) and underscores (_) as indicators of emphasis. Text wrapped with one * or _ will be wrapped with an HTML <em> tag; double *'s or _'s will be wrapped with an HTML <strong> tag. E.g., this input:

      *single asterisks*
      
      _single underscores_
      
      **double asterisks**
      
      __double underscores__
      

      will produce:

      <em>single asterisks</em>
      
      <em>single underscores</em>
      
      <strong>double asterisks</strong>
      
      <strong>double underscores</strong>
      

      You can use whichever style you prefer; the lone restriction is that the same character must be used to open and close an emphasis span.

      Emphasis can be used in the middle of a word:

      un*fucking*believable
      

      But if you surround an * or _ with spaces, it'll be treated as a literal asterisk or underscore.

      To produce a literal asterisk or underscore at a position where it would otherwise be used as an emphasis delimiter, you can backslash escape it:

      \*this text is surrounded by literal asterisks\*
      

      Code

      To indicate a span of code, wrap it with backtick quotes (`). Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example:

      Use the `printf()` function.
      

      will produce:

      <p>Use the <code>printf()</code> function.</p>
      

      To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters:

      ``There is a literal backtick (`) here.``
      

      which will produce this:

      <p><code>There is a literal backtick (`) here.</code></p>
      

      The backtick delimiters surrounding a code span may include spaces -- one after the opening, one before the closing. This allows you to place literal backtick characters at the beginning or end of a code span:

      A single backtick in a code span: `` ` ``
      
      A backtick-delimited string in a code span: `` `foo` ``
      

      will produce:

      <p>A single backtick in a code span: <code>`</code></p>
      
      <p>A backtick-delimited string in a code span: <code>`foo`</code></p>
      

      With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags. Markdown will turn this:

      Please don't use any `<blink>` tags.
      

      into:

      <p>Please don't use any <code>&lt;blink&gt;</code> tags.</p>
      

      You can write this:

      `&#8212;` is the decimal-encoded equivalent of `&mdash;`.
      

      to produce:

      <p><code>&amp;#8212;</code> is the decimal-encoded
      equivalent of <code>&amp;mdash;</code>.</p>
      

      Images

      Admittedly, it's fairly difficult to devise a "natural" syntax for placing images into a plain text document format.

      Markdown uses an image syntax that is intended to resemble the syntax for links, allowing for two styles: inline and reference.

      Inline image syntax looks like this:

      ![Alt text](/path/to/img.jpg)
      
      ![Alt text](/path/to/img.jpg "Optional title")
      

      That is:

      • An exclamation mark: !;
      • followed by a set of square brackets, containing the alt attribute text for the image;
      • followed by a set of parentheses, containing the URL or path to the image, and an optional title attribute enclosed in double or single quotes.

      Reference-style image syntax looks like this:

      ![Alt text][id]
      

      Where "id" is the name of a defined image reference. Image references are defined using syntax identical to link references:

      [id]: url/to/image  "Optional title attribute"
      

      As of this writing, Markdown has no syntax for specifying the dimensions of an image; if this is important to you, you can simply use regular HTML <img> tags.


      Miscellaneous

      Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:

      <http://example.com/>
      

      Markdown will turn this into:

      <a href="http://example.com/">http://example.com/</a>
      

      Automatic links for email addresses work similarly, except that Markdown will also perform a bit of randomized decimal and hex entity-encoding to help obscure your address from address-harvesting spambots. For example, Markdown will turn this:

      <address@example.com>
      

      into something like this:

      <a href="&#x6D;&#x61;i&#x6C;&#x74;&#x6F;:&#x61;&#x64;&#x64;&#x72;&#x65;
      &#115;&#115;&#64;&#101;&#120;&#x61;&#109;&#x70;&#x6C;e&#x2E;&#99;&#111;
      &#109;">&#x61;&#x64;&#x64;&#x72;&#x65;&#115;&#115;&#64;&#101;&#120;&#x61;
      &#109;&#x70;&#x6C;e&#x2E;&#99;&#111;&#109;</a>
      

      which will render in a browser as a clickable link to "address@example.com".

      (This sort of entity-encoding trick will indeed fool many, if not most, address-harvesting bots, but it definitely won't fool all of them. It's better than nothing, but an address published in this way will probably eventually start receiving spam.)

      Backslash Escapes

      Markdown allows you to use backslash escapes to generate literal characters which would otherwise have special meaning in Markdown's formatting syntax. For example, if you wanted to surround a word with literal asterisks (instead of an HTML <em> tag), you can backslashes before the asterisks, like this:

      \*literal asterisks\*
      

      Markdown provides backslash escapes for the following characters:

      \   backslash
      `   backtick
      *   asterisk
      _   underscore
      {}  curly braces
      []  square brackets
      ()  parentheses
      #   hash mark
      +   plus sign
      -   minus sign (hyphen)
      .   dot
      !   exclamation mark
      
      mistune-0.7.1/tests/fixtures/normal/markdown_documentation_syntax.text0000644000076500000240000006544412416110764027417 0ustar lepturestaff00000000000000Markdown: Syntax ================ * [Overview](#overview) * [Philosophy](#philosophy) * [Inline HTML](#html) * [Automatic Escaping for Special Characters](#autoescape) * [Block Elements](#block) * [Paragraphs and Line Breaks](#p) * [Headers](#header) * [Blockquotes](#blockquote) * [Lists](#list) * [Code Blocks](#precode) * [Horizontal Rules](#hr) * [Span Elements](#span) * [Links](#link) * [Emphasis](#em) * [Code](#code) * [Images](#img) * [Miscellaneous](#misc) * [Backslash Escapes](#backslash) * [Automatic Links](#autolink) **Note:** This document is itself written using Markdown; you can [see the source for it by adding '.text' to the URL][src]. [src]: /projects/markdown/syntax.text * * *

      Overview

      Philosophy

      Markdown is intended to be as easy-to-read and easy-to-write as is feasible. Readability, however, is emphasized above all else. A Markdown-formatted document should be publishable as-is, as plain text, without looking like it's been marked up with tags or formatting instructions. While Markdown's syntax has been influenced by several existing text-to-HTML filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4], [Grutatext] [5], and [EtText] [6] -- the single biggest source of inspiration for Markdown's syntax is the format of plain text email. [1]: http://docutils.sourceforge.net/mirror/setext.html [2]: http://www.aaronsw.com/2002/atx/ [3]: http://textism.com/tools/textile/ [4]: http://docutils.sourceforge.net/rst.html [5]: http://www.triptico.com/software/grutatxt.html [6]: http://ettext.taint.org/doc/ To this end, Markdown's syntax is comprised entirely of punctuation characters, which punctuation characters have been carefully chosen so as to look like what they mean. E.g., asterisks around a word actually look like \*emphasis\*. Markdown lists look like, well, lists. Even blockquotes look like quoted passages of text, assuming you've ever used email.

      Inline HTML

      Markdown's syntax is intended for one purpose: to be used as a format for *writing* for the web. Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is *not* to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a *publishing* format; Markdown is a *writing* format. Thus, Markdown's formatting syntax only addresses issues that can be conveyed in plain text. For any markup that is not covered by Markdown's syntax, you simply use HTML itself. There's no need to preface it or delimit it to indicate that you're switching from Markdown to HTML; you just use the tags. The only restrictions are that block-level HTML elements -- e.g. `
      `, ``, `
      `, `

      `, etc. -- must be separated from surrounding content by blank lines, and the start and end tags of the block should not be indented with tabs or spaces. Markdown is smart enough not to add extra (unwanted) `

      ` tags around HTML block-level tags. For example, to add an HTML table to a Markdown article: This is a regular paragraph.

      Foo
      This is another regular paragraph. Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can't use Markdown-style `*emphasis*` inside an HTML block. Span-level HTML tags -- e.g. ``, ``, or `` -- can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you'd prefer to use HTML `` or `` tags instead of Markdown's link or image syntax, go right ahead. Unlike block-level HTML tags, Markdown syntax *is* processed within span-level tags.

      Automatic Escaping for Special Characters

      In HTML, there are two characters that demand special treatment: `<` and `&`. Left angle brackets are used to start tags; ampersands are used to denote HTML entities. If you want to use them as literal characters, you must escape them as entities, e.g. `<`, and `&`. Ampersands in particular are bedeviling for web writers. If you want to write about 'AT&T', you need to write '`AT&T`'. You even need to escape ampersands within URLs. Thus, if you want to link to: http://images.google.com/images?num=30&q=larry+bird you need to encode the URL as: http://images.google.com/images?num=30&q=larry+bird in your anchor tag `href` attribute. Needless to say, this is easy to forget, and is probably the single most common source of HTML validation errors in otherwise well-marked-up web sites. Markdown allows you to use these characters naturally, taking care of all the necessary escaping for you. If you use an ampersand as part of an HTML entity, it remains unchanged; otherwise it will be translated into `&`. So, if you want to include a copyright symbol in your article, you can write: © and Markdown will leave it alone. But if you write: AT&T Markdown will translate it to: AT&T Similarly, because Markdown supports [inline HTML](#html), if you use angle brackets as delimiters for HTML tags, Markdown will treat them as such. But if you write: 4 < 5 Markdown will translate it to: 4 < 5 However, inside Markdown code spans and blocks, angle brackets and ampersands are *always* encoded automatically. This makes it easy to use Markdown to write about HTML code. (As opposed to raw HTML, which is a terrible format for writing about HTML syntax, because every single `<` and `&` in your example code needs to be escaped.) * * *

      Block Elements

      Paragraphs and Line Breaks

      A paragraph is simply one or more consecutive lines of text, separated by one or more blank lines. (A blank line is any line that looks like a blank line -- a line containing nothing but spaces or tabs is considered blank.) Normal paragraphs should not be intended with spaces or tabs. The implication of the "one or more consecutive lines of text" rule is that Markdown supports "hard-wrapped" text paragraphs. This differs significantly from most other text-to-HTML formatters (including Movable Type's "Convert Line Breaks" option) which translate every line break character in a paragraph into a `
      ` tag. When you *do* want to insert a `
      ` break tag using Markdown, you end a line with two or more spaces, then type return. Yes, this takes a tad more effort to create a `
      `, but a simplistic "every line break is a `
      `" rule wouldn't work for Markdown. Markdown's email-style [blockquoting][bq] and multi-paragraph [list items][l] work best -- and look better -- when you format them with hard breaks. [bq]: #blockquote [l]: #list Markdown supports two styles of headers, [Setext] [1] and [atx] [2]. Setext-style headers are "underlined" using equal signs (for first-level headers) and dashes (for second-level headers). For example: This is an H1 ============= This is an H2 ------------- Any number of underlining `=`'s or `-`'s will work. Atx-style headers use 1-6 hash characters at the start of the line, corresponding to header levels 1-6. For example: # This is an H1 ## This is an H2 ###### This is an H6 Optionally, you may "close" atx-style headers. This is purely cosmetic -- you can use this if you think it looks better. The closing hashes don't even need to match the number of hashes used to open the header. (The number of opening hashes determines the header level.) : # This is an H1 # ## This is an H2 ## ### This is an H3 ######

      Blockquotes

      Markdown uses email-style `>` characters for blockquoting. If you're familiar with quoting passages of text in an email message, then you know how to create a blockquote in Markdown. It looks best if you hard wrap the text and put a `>` before every line: > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, > consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. > Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse > id sem consectetuer libero luctus adipiscing. Markdown allows you to be lazy and only put the `>` before the first line of a hard-wrapped paragraph: > This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. > Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. Blockquotes can be nested (i.e. a blockquote-in-a-blockquote) by adding additional levels of `>`: > This is the first level of quoting. > > > This is nested blockquote. > > Back to the first level. Blockquotes can contain other Markdown elements, including headers, lists, and code blocks: > ## This is a header. > > 1. This is the first list item. > 2. This is the second list item. > > Here's some example code: > > return shell_exec("echo $input | $markdown_script"); Any decent text editor should make email-style quoting easy. For example, with BBEdit, you can make a selection and choose Increase Quote Level from the Text menu.

      Lists

      Markdown supports ordered (numbered) and unordered (bulleted) lists. Unordered lists use asterisks, pluses, and hyphens -- interchangably -- as list markers: * Red * Green * Blue is equivalent to: + Red + Green + Blue and: - Red - Green - Blue Ordered lists use numbers followed by periods: 1. Bird 2. McHale 3. Parish It's important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. The HTML Markdown produces from the above list is:
      1. Bird
      2. McHale
      3. Parish
      If you instead wrote the list in Markdown like this: 1. Bird 1. McHale 1. Parish or even: 3. Bird 1. McHale 8. Parish you'd get the exact same HTML output. The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don't have to. If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number. List markers typically start at the left margin, but may be indented by up to three spaces. List markers must be followed by one or more spaces or a tab. To make lists look nice, you can wrap items with hanging indents: * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. But if you want to be lazy, you don't have to: * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. If list items are separated by blank lines, Markdown will wrap the items in `

      ` tags in the HTML output. For example, this input: * Bird * Magic will turn into:

      • Bird
      • Magic
      But this: * Bird * Magic will turn into:
      • Bird

      • Magic

      List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be intended by either 4 spaces or one tab: 1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 2. Suspendisse id sem consectetuer libero luctus adipiscing. It looks nice if you indent every line of the subsequent paragraphs, but here again, Markdown will allow you to be lazy: * This is a list item with two paragraphs. This is the second paragraph in the list item. You're only required to indent the first line. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. * Another item in the same list. To put a blockquote within a list item, the blockquote's `>` delimiters need to be indented: * A list item with a blockquote: > This is a blockquote > inside a list item. To put a code block within a list item, the code block needs to be indented *twice* -- 8 spaces or two tabs: * A list item with a code block: It's worth noting that it's possible to trigger an ordered list by accident, by writing something like this: 1986. What a great season. In other words, a *number-period-space* sequence at the beginning of a line. To avoid this, you can backslash-escape the period: 1986\. What a great season.

      Code Blocks

      Pre-formatted code blocks are used for writing about programming or markup source code. Rather than forming normal paragraphs, the lines of a code block are interpreted literally. Markdown wraps a code block in both `
      ` and `` tags.
      
      To produce a code block in Markdown, simply indent every line of the
      block by at least 4 spaces or 1 tab. For example, given this input:
      
          This is a normal paragraph:
      
              This is a code block.
      
      Markdown will generate:
      
          

      This is a normal paragraph:

      This is a code block.
          
      One level of indentation -- 4 spaces or 1 tab -- is removed from each line of the code block. For example, this: Here is an example of AppleScript: tell application "Foo" beep end tell will turn into:

      Here is an example of AppleScript:

      tell application "Foo"
              beep
          end tell
          
      A code block continues until it reaches a line that is not indented (or the end of the article). Within a code block, ampersands (`&`) and angle brackets (`<` and `>`) are automatically converted into HTML entities. This makes it very easy to include example HTML source code using Markdown -- just paste it and indent it, and Markdown will handle the hassle of encoding the ampersands and angle brackets. For example, this: will turn into:
      <div class="footer">
              &copy; 2004 Foo Corporation
          </div>
          
      Regular Markdown syntax is not processed within code blocks. E.g., asterisks are just literal asterisks within a code block. This means it's also easy to use Markdown to write about Markdown's own syntax.

      Horizontal Rules

      You can produce a horizontal rule tag (`
      `) by placing three or more hyphens, asterisks, or underscores on a line by themselves. If you wish, you may use spaces between the hyphens or asterisks. Each of the following lines will produce a horizontal rule: * * * *** ***** - - - --------------------------------------- _ _ _ * * *

      Span Elements

      Markdown supports two style of links: *inline* and *reference*. In both styles, the link text is delimited by [square brackets]. To create an inline link, use a set of regular parentheses immediately after the link text's closing square bracket. Inside the parentheses, put the URL where you want the link to point, along with an *optional* title for the link, surrounded in quotes. For example: This is [an example](http://example.com/ "Title") inline link. [This link](http://example.net/) has no title attribute. Will produce:

      This is an example inline link.

      This link has no title attribute.

      If you're referring to a local resource on the same server, you can use relative paths: See my [About](/about/) page for details. Reference-style links use a second set of square brackets, inside which you place a label of your choosing to identify the link: This is [an example][id] reference-style link. You can optionally use a space to separate the sets of brackets: This is [an example] [id] reference-style link. Then, anywhere in the document, you define your link label like this, on a line by itself: [id]: http://example.com/ "Optional Title Here" That is: * Square brackets containing the link identifier (optionally indented from the left margin using up to three spaces); * followed by a colon; * followed by one or more spaces (or tabs); * followed by the URL for the link; * optionally followed by a title attribute for the link, enclosed in double or single quotes. The link URL may, optionally, be surrounded by angle brackets: [id]: "Optional Title Here" You can put the title attribute on the next line and use extra spaces or tabs for padding, which tends to look better with longer URLs: [id]: http://example.com/longish/path/to/resource/here "Optional Title Here" Link definitions are only used for creating links during Markdown processing, and are stripped from your document in the HTML output. Link definition names may constist of letters, numbers, spaces, and punctuation -- but they are *not* case sensitive. E.g. these two links: [link text][a] [link text][A] are equivalent. The *implicit link name* shortcut allows you to omit the name of the link, in which case the link text itself is used as the name. Just use an empty set of square brackets -- e.g., to link the word "Google" to the google.com web site, you could simply write: [Google][] And then define the link: [Google]: http://google.com/ Because link names may contain spaces, this shortcut even works for multiple words in the link text: Visit [Daring Fireball][] for more information. And then define the link: [Daring Fireball]: http://daringfireball.net/ Link definitions can be placed anywhere in your Markdown document. I tend to put them immediately after each paragraph in which they're used, but if you want, you can put them all at the end of your document, sort of like footnotes. Here's an example of reference links in action: I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3]. [1]: http://google.com/ "Google" [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search" Using the implicit link name shortcut, you could instead write: I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][]. [google]: http://google.com/ "Google" [yahoo]: http://search.yahoo.com/ "Yahoo Search" [msn]: http://search.msn.com/ "MSN Search" Both of the above examples will produce the following HTML output:

      I get 10 times more traffic from Google than from Yahoo or MSN.

      For comparison, here is the same paragraph written using Markdown's inline link style: I get 10 times more traffic from [Google](http://google.com/ "Google") than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or [MSN](http://search.msn.com/ "MSN Search"). The point of reference-style links is not that they're easier to write. The point is that with reference-style links, your document source is vastly more readable. Compare the above examples: using reference-style links, the paragraph itself is only 81 characters long; with inline-style links, it's 176 characters; and as raw HTML, it's 234 characters. In the raw HTML, there's more markup than there is text. With Markdown's reference-style links, a source document much more closely resembles the final output, as rendered in a browser. By allowing you to move the markup-related metadata out of the paragraph, you can add links without interrupting the narrative flow of your prose.

      Emphasis

      Markdown treats asterisks (`*`) and underscores (`_`) as indicators of emphasis. Text wrapped with one `*` or `_` will be wrapped with an HTML `` tag; double `*`'s or `_`'s will be wrapped with an HTML `` tag. E.g., this input: *single asterisks* _single underscores_ **double asterisks** __double underscores__ will produce: single asterisks single underscores double asterisks double underscores You can use whichever style you prefer; the lone restriction is that the same character must be used to open and close an emphasis span. Emphasis can be used in the middle of a word: un*fucking*believable But if you surround an `*` or `_` with spaces, it'll be treated as a literal asterisk or underscore. To produce a literal asterisk or underscore at a position where it would otherwise be used as an emphasis delimiter, you can backslash escape it: \*this text is surrounded by literal asterisks\*

      Code

      To indicate a span of code, wrap it with backtick quotes (`` ` ``). Unlike a pre-formatted code block, a code span indicates code within a normal paragraph. For example: Use the `printf()` function. will produce:

      Use the printf() function.

      To include a literal backtick character within a code span, you can use multiple backticks as the opening and closing delimiters: ``There is a literal backtick (`) here.`` which will produce this:

      There is a literal backtick (`) here.

      The backtick delimiters surrounding a code span may include spaces -- one after the opening, one before the closing. This allows you to place literal backtick characters at the beginning or end of a code span: A single backtick in a code span: `` ` `` A backtick-delimited string in a code span: `` `foo` `` will produce:

      A single backtick in a code span: `

      A backtick-delimited string in a code span: `foo`

      With a code span, ampersands and angle brackets are encoded as HTML entities automatically, which makes it easy to include example HTML tags. Markdown will turn this: Please don't use any `` tags. into:

      Please don't use any <blink> tags.

      You can write this: `—` is the decimal-encoded equivalent of `—`. to produce:

      &#8212; is the decimal-encoded equivalent of &mdash;.

      Images

      Admittedly, it's fairly difficult to devise a "natural" syntax for placing images into a plain text document format. Markdown uses an image syntax that is intended to resemble the syntax for links, allowing for two styles: *inline* and *reference*. Inline image syntax looks like this: ![Alt text](/path/to/img.jpg) ![Alt text](/path/to/img.jpg "Optional title") That is: * An exclamation mark: `!`; * followed by a set of square brackets, containing the `alt` attribute text for the image; * followed by a set of parentheses, containing the URL or path to the image, and an optional `title` attribute enclosed in double or single quotes. Reference-style image syntax looks like this: ![Alt text][id] Where "id" is the name of a defined image reference. Image references are defined using syntax identical to link references: [id]: url/to/image "Optional title attribute" As of this writing, Markdown has no syntax for specifying the dimensions of an image; if this is important to you, you can simply use regular HTML `` tags. * * *

      Miscellaneous

      Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this: Markdown will turn this into: http://example.com/ Automatic links for email addresses work similarly, except that Markdown will also perform a bit of randomized decimal and hex entity-encoding to help obscure your address from address-harvesting spambots. For example, Markdown will turn this: into something like this: address@exa mple.com which will render in a browser as a clickable link to "address@example.com". (This sort of entity-encoding trick will indeed fool many, if not most, address-harvesting bots, but it definitely won't fool all of them. It's better than nothing, but an address published in this way will probably eventually start receiving spam.)

      Backslash Escapes

      Markdown allows you to use backslash escapes to generate literal characters which would otherwise have special meaning in Markdown's formatting syntax. For example, if you wanted to surround a word with literal asterisks (instead of an HTML `` tag), you can backslashes before the asterisks, like this: \*literal asterisks\* Markdown provides backslash escapes for the following characters: \ backslash ` backtick * asterisk _ underscore {} curly braces [] square brackets () parentheses # hash mark + plus sign - minus sign (hyphen) . dot ! exclamation mark mistune-0.7.1/tests/fixtures/normal/nested_blockquotes.html0000644000076500000240000000015112416110764025073 0ustar lepturestaff00000000000000

      foo

      bar

      foo

      mistune-0.7.1/tests/fixtures/normal/nested_blockquotes.text0000644000076500000240000000003012416110764025107 0ustar lepturestaff00000000000000> foo > > > bar > > foo mistune-0.7.1/tests/fixtures/normal/ordered_and_unordered_lists.html0000644000076500000240000000324112416110764026734 0ustar lepturestaff00000000000000

      Unordered

      Asterisks tight:

      • asterisk 1
      • asterisk 2
      • asterisk 3

      Asterisks loose:

      • asterisk 1

      • asterisk 2

      • asterisk 3


      Pluses tight:

      • Plus 1
      • Plus 2
      • Plus 3

      Pluses loose:

      • Plus 1

      • Plus 2

      • Plus 3


      Minuses tight:

      • Minus 1
      • Minus 2
      • Minus 3

      Minuses loose:

      • Minus 1

      • Minus 2

      • Minus 3

      Ordered

      Tight:

      1. First
      2. Second
      3. Third

      and:

      1. One
      2. Two
      3. Three

      Loose using tabs:

      1. First

      2. Second

      3. Third

      and using spaces:

      1. One

      2. Two

      3. Three

      Multiple paragraphs:

      1. Item 1, graf one.

        Item 2. graf two. The quick brown fox jumped over the lazy dog's back.

      2. Item 2.

      3. Item 3.

      Nested

      • Tab
        • Tab
          • Tab

      Here's another:

      1. First
      2. Second:
        • Fee
        • Fie
        • Foe
      3. Third

      Same thing but with paragraphs:

      1. First

      2. Second:

        • Fee
        • Fie
        • Foe
      3. Third

      This was an error in Markdown 1.0.1:

      • this

        • sub

        that

      mistune-0.7.1/tests/fixtures/normal/ordered_and_unordered_lists.text0000644000076500000240000000160712416110764026760 0ustar lepturestaff00000000000000## Unordered Asterisks tight: * asterisk 1 * asterisk 2 * asterisk 3 Asterisks loose: * asterisk 1 * asterisk 2 * asterisk 3 * * * Pluses tight: + Plus 1 + Plus 2 + Plus 3 Pluses loose: + Plus 1 + Plus 2 + Plus 3 * * * Minuses tight: - Minus 1 - Minus 2 - Minus 3 Minuses loose: - Minus 1 - Minus 2 - Minus 3 ## Ordered Tight: 1. First 2. Second 3. Third and: 1. One 2. Two 3. Three Loose using tabs: 1. First 2. Second 3. Third and using spaces: 1. One 2. Two 3. Three Multiple paragraphs: 1. Item 1, graf one. Item 2. graf two. The quick brown fox jumped over the lazy dog's back. 2. Item 2. 3. Item 3. ## Nested * Tab * Tab * Tab Here's another: 1. First 2. Second: * Fee * Fie * Foe 3. Third Same thing but with paragraphs: 1. First 2. Second: * Fee * Fie * Foe 3. Third This was an error in Markdown 1.0.1: * this * sub that mistune-0.7.1/tests/fixtures/normal/strong_and_em_together.html0000644000076500000240000000032712416110764025723 0ustar lepturestaff00000000000000

      This is strong and em.

      So is this word.

      This is strong and em.

      So is this word.

      mistune-0.7.1/tests/fixtures/normal/strong_and_em_together.text0000644000076500000240000000015312416110764025740 0ustar lepturestaff00000000000000***This is strong and em.*** So is ***this*** word. ___This is strong and em.___ So is ___this___ word. mistune-0.7.1/tests/fixtures/normal/tabs.html0000644000076500000240000000066712416110764022143 0ustar lepturestaff00000000000000
      • this is a list item indented with tabs

      • this is a list item indented with spaces

      Code:

      this code block is indented by one tab
      

      And:

          this code block is indented by two tabs
      

      And:

      +   this is an example list item
          indented with tabs
      
      +   this is an example list item
          indented with spaces
      
      mistune-0.7.1/tests/fixtures/normal/tabs.text0000644000076500000240000000046712416110764022161 0ustar lepturestaff00000000000000+ this is a list item indented with tabs + this is a list item indented with spaces Code: this code block is indented by one tab And: this code block is indented by two tabs And: + this is an example list item indented with tabs + this is an example list item indented with spaces mistune-0.7.1/tests/fixtures/normal/tidyness.html0000644000076500000240000000020512416110764023040 0ustar lepturestaff00000000000000

      A list within a blockquote:

      • asterisk 1
      • asterisk 2
      • asterisk 3
      mistune-0.7.1/tests/fixtures/normal/tidyness.text0000644000076500000240000000011612416110764023061 0ustar lepturestaff00000000000000> A list within a blockquote: > > * asterisk 1 > * asterisk 2 > * asterisk 3 mistune-0.7.1/tests/test_cases.py0000644000076500000240000000242012550361560017660 0ustar lepturestaff00000000000000 import os import re import mistune root = os.path.dirname(__file__) known = [] rules = [ 'table', 'fenced_code', 'footnotes', 'autolink', 'strikethrough', ] m = mistune.Markdown(rules=rules) def render(folder, name): filepath = os.path.join(folder, name + '.text') with open(filepath) as f: content = f.read() html = m.parse(content) filepath = os.path.join(folder, name + '.html') with open(filepath) as f: result = f.read() html = re.sub(r'\s', '', html) result = re.sub(r'\s', '', result) for i, s in enumerate(html): if s != result[i]: begin = max(i - 30, 0) msg = '\n\n%s\n------Not Equal(%d)------\n%s' % ( html[begin:i+30], i, result[begin:i+30] ) raise ValueError(msg) assert html == result def listdir(folder): folder = os.path.join(root, 'fixtures', folder) files = os.listdir(folder) files = filter(lambda o: o.endswith('.text'), files) names = map(lambda o: o[:-5], files) return folder, names def test_extra(): folder, names = listdir('extra') for key in names: yield render, folder, key def test_normal(): folder, names = listdir('normal') for key in names: yield render, folder, key mistune-0.7.1/tests/test_extra.py0000644000076500000240000000463512562655061017724 0ustar lepturestaff00000000000000import mistune def test_escape(): ret = mistune.markdown('
      **foo**
      ', escape=True) assert '>' in ret ret = mistune.markdown('this **foo** is bold', escape=True) assert '>' in ret def test_linebreak(): ret = mistune.markdown('this **foo** \nis me') assert '
      ' not in ret ret = mistune.markdown('this **foo** \nis me', hard_wrap=True) assert '
      ' in ret def test_safe_links(): ret = mistune.markdown('javascript ![foo]() alert') assert 'src=""' in ret ret = mistune.markdown('javascript [foo]() alert') assert 'href=""' in ret def test_skip_style(): ret = mistune.markdown( 'foo\n', skip_style=True ) assert ret == '

      foo

      \n' def test_use_xhtml(): ret = mistune.markdown('foo\n\n----\n\nbar') assert '
      ' in ret ret = mistune.markdown('foo\n\n----\n\nbar', use_xhtml=True) assert '
      ' in ret ret = mistune.markdown('foo \nbar', use_xhtml=True) assert '
      ' in ret ret = mistune.markdown('![foo](bar "title")', use_xhtml=True) assert 'foo' in ret def test_parse_inline_html(): ret = mistune.markdown( '
      **foo**
      ', parse_inline_html=True, escape=False ) assert '' not in ret ret = mistune.markdown( '**foo**', parse_inline_html=True, escape=False ) assert '' in ret ret = mistune.markdown( 'http://lepture.com', parse_inline_html=True, escape=False ) assert 'href' not in ret def test_parse_block_html(): ret = mistune.markdown( '
      **foo**
      ', parse_block_html=True, escape=False ) assert '
      ' in ret ret = mistune.markdown( '**foo**', parse_block_html=True, escape=False ) assert '' not in ret def test_trigger_more_cases(): markdown = mistune.Markdown( inline=mistune.InlineLexer, block=mistune.BlockLexer, skip_html=True ) ret = markdown.render('foo[^foo]\n\n[^foo]: foo\n\n[^foo]: bar\n') assert 'bar' not in ret def test_not_escape_block_tags(): text = '

      heading

      text' assert text in mistune.markdown(text, escape=False) def test_not_escape_inline_tags(): text = '' assert text in mistune.markdown(text, escape=False) mistune-0.7.1/tests/test_subclassing.py0000644000076500000240000001263312541031325021077 0ustar lepturestaff00000000000000# coding: utf-8 import os import re import copy import mistune root = os.path.dirname(__file__) class MathBlockGrammar(mistune.BlockGrammar): block_math = re.compile("^\$\$(.*?)\$\$", re.DOTALL) latex_environment = re.compile( r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}", re.DOTALL ) class MathBlockLexer(mistune.BlockLexer): default_rules = ['block_math', 'latex_environment'] + \ mistune.BlockLexer.default_rules def __init__(self, rules=None, **kwargs): if rules is None: rules = MathBlockGrammar() super(MathBlockLexer, self).__init__(rules, **kwargs) def parse_block_math(self, m): """Parse a $$math$$ block""" self.tokens.append({ 'type': 'block_math', 'text': m.group(1) }) def parse_latex_environment(self, m): self.tokens.append({ 'type': 'latex_environment', 'name': m.group(1), 'text': m.group(2) }) class MathInlineGrammar(mistune.InlineGrammar): math = re.compile("^\$(.+?)\$") text = re.compile(r'^[\s\S]+?(?=[\\%s' % (link, alt) def test_custom_lexer(): markdown = mistune.Markdown(inline=WikiInlineLexer) ret = markdown('[[Link Text|Wiki Link]]') assert '