dev-python/mistune: Clean old versions up

This commit is contained in:
Michał Górny
2017-05-02 13:17:27 +02:00
parent 667b0f9ed6
commit 4ddb0a2b15
6 changed files with 0 additions and 654 deletions

View File

@@ -1,5 +1 @@
DIST mistune-0.5.1.tar.gz 183864 SHA256 cc66489a28845c0e1848ae290af5b555074eb76185136ca058e8eed1faa89692 SHA512 56399def88cc1daf5df02a97aba49c3dcc2f860d53222e524bfbd5f48f262f01344582bfd647c363e631b25c300923f690cd0e68ff4e179c4974166f8beca95f WHIRLPOOL 7fbf46712111c0f3087203e50630e200c4df395cd6593001bc23761f5b07c6151c3199dd44b607058bcfbe726eef244797423497d304e87a1f7ceacff2df4261
DIST mistune-0.6.tar.gz 47026 SHA256 d54a69365d01bc97412a39c11674a8aae3f333586e91f38895cc1ad818e13dc5 SHA512 f7f7a7830a733f957c8c541195e061de3ba5843540bc1811639526d7ff0f7b7f549c33af14990bb50e9890eaeb9645cfb9b8cd92e92a4e9a01e388773a33ca16 WHIRLPOOL c52395733faa678655b987a8705f05075ca05922aa5ed5a910d67af35694bdc8a11f7fb8b3fed6398e587dda2208e7e28015756eb5185d372cd3fd3de33610bd
DIST mistune-0.7.1.tar.gz 48371 SHA256 6076dedf768348927d991f4371e5a799c6a0158b16091df08ee85ee231d929a7 SHA512 634eb321026d45ca1f87cd9fecfb7f105ad0ae6a24f881074326d9c9b5dd714047ffba175f5e8ec5e8de6070cf448d03fb13ca0e5a4cc90a01475d389a8777e8 WHIRLPOOL 9e6980b79b94ca2548854333f97cb7f02d1fbe0cd6805750fa81d143349c90b088f7e098d25021df94c0fa1242f95b3764a04315101f4bfef8711f97c9b9266a
DIST mistune-0.7.2.tar.gz 48887 SHA256 626f2516adcde4af608eaf83635ff20ff7e577c1898ad4d0f0fcd8c094399840 SHA512 9002bf83a368671389f05928f4f689064a1e415e54309259b6bbb7781b4bfddbbf834e2c63ed3271e1e6ec7b78c1665c7708177b9723433d1e2ad4b13ad903ca WHIRLPOOL 54d95b82bb061709a48bbd3e87a16e4cc03734f8adfc88e48b44da0070e16ec062ea4c219e258bd4abd2a4e7dd6aa144a4f73257c24ee28622eb36fcba89effe
DIST mistune-0.7.tar.gz 48203 SHA256 1daa2e55f5de63ecde7c446c4677c0447006752f78ad2c9c1c3c3452d395f89f SHA512 0d7450dab279f8dc1a608bccad34ec6a99c54ef26ce2439ffa92e1589b0a505ef11382c5d5db990df0e57ba908e3d4b1198c6416dccaf7f5b798894c898874a3 WHIRLPOOL 51db0cf3ab4990c0ee4b2503e2c1ad2ede225c999d0196a6f24cd4d18a69236d1c9365ffc79f0011b1d2d977aa6a69533a968b2e640bb4c0345234e9e5e5e44c

View File

@@ -1,536 +0,0 @@
diff --git a/CHANGES.rst b/CHANGES.rst
index eb204dd..3eb99a7 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,14 @@ Changelog
Here is the full history of mistune.
+Version 0.7
+~~~~~~~~~~~
+
+Release date not decided.
+
+* Fix the breaking change in version 0.6 with options: **parse_inline_html** and **parse_block_html**
+
+
Version 0.6
~~~~~~~~~~~
diff --git a/README.rst b/README.rst
index 894833b..f6cb5f9 100644
--- a/README.rst
+++ b/README.rst
@@ -38,12 +38,6 @@ Installing mistune with pip::
$ pip install mistune
-If pip is not available, try easy_install::
-
- $ easy_install mistune
-
-Cython Feature
-~~~~~~~~~~~~~~
Mistune can be faster, if you compile with cython::
@@ -59,10 +53,49 @@ A simple API that render a markdown formatted text:
import mistune
- mistune.markdown('I am using **markdown**')
- # output: <p>I am using <strong>markdown</strong></p>
+ mistune.markdown('I am using **mistune markdown parser**')
+ # output: <p>I am using <strong>mistune markdown parser</strong></p>
+
+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 *True*, all raw html tags will be escaped.
+* **hard_wrap**: if set to *True*, it will has GFM line breaks feature.
+* **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``<hr />``.
+* **parse_html**: parse text in block and inline level html.
+* **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)
-Mistune has all features by default. You don't have to configure anything.
Renderer
--------
@@ -79,7 +112,7 @@ Here is an example of code highlighting:
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
- class MyRenderer(mistune.Renderer):
+ class HighlightRenderer(mistune.Renderer):
def block_code(self, code, lang):
if not lang:
return '\n<pre><code>%s</code></pre>\n' % \
@@ -88,9 +121,9 @@ Here is an example of code highlighting:
formatter = HtmlFormatter()
return highlight(code, lexer, formatter)
- renderer = MyRenderer()
- md = mistune.Markdown(renderer=renderer)
- print(md.render('Some Markdown text.'))
+ renderer = HighlightRenderer()
+ markdown = mistune.Markdown(renderer=renderer)
+ print(markdown('Some code text.'))
Block Level
@@ -127,34 +160,18 @@ Here is a list of span level renderer API::
linebreak()
newline()
link(link, title, content)
- tag(html)
strikethrough(text)
text(text)
+ inline_html(text)
+Footnotes
+~~~~~~~~~
-Options
--------
-
-Here is a list of all options that will affect the rendering results:
-
-.. code:: python
-
- renderer = mistune.Renderer(escape=True)
- md = mistune.Markdown(renderer=renderer)
- md.render(text)
-
-* **escape**: if set to *True*, all raw html tags will be escaped.
-* **hard_wrap**: if set to *True*, it will has GFM line breaks feature.
-* **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``<hr />``.
-* **parse_html**: parse text in block level html.
-
-When using the default renderer, you can use one of the following shorthands::
-
- mistune.markdown(text, escape=True)
-
- md = mistune.Markdown(escape=True)
- md.render(text)
+Here is a list of renderers related to footnotes::
+ footnote_ref(key, index)
+ footnote_item(key, text)
+ footnotes(text)
Lexers
------
@@ -172,33 +189,23 @@ It is an inline grammar, which requires custom ``InlineGrammar`` and
import copy
from mistune import Renderer, InlineGrammar, InlineLexer
- class MyRenderer(Renderer):
+ class WikiLinkRenderer(Renderer):
def wiki_link(self, alt, link):
return '<a href="%s">%s</a>' % (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'\]\](?!\])' # ]]
+ )
- class MyInlineGrammar(InlineGrammar):
- # it would take a while for creating the right regex
- wiki_link = re.compile(
- r'\[\[' # [[
- r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2
- r'\]\](?!\])' # ]]
- )
-
-
- class MyInlineLexer(InlineLexer):
- default_rules = copy.copy(InlineLexer.default_rules)
-
- # Add wiki_link parser to default rules
- # you can insert it any place you like
- default_rules.insert(3, 'wiki_link')
-
- def __init__(self, renderer, rules=None, **kwargs):
- if rules is None:
- # use the inline grammar
- rules = MyInlineGrammar()
-
- super(MyInlineLexer, self).__init__(renderer, rules, **kwargs)
+ # 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)
@@ -211,8 +218,10 @@ You should pass the inline lexer to ``Markdown`` parser:
.. code:: python
- renderer = MyRenderer()
- inline = MyInlineLexer(renderer)
+ renderer = WikiLinkRenderer()
+ inline = WikiLinkInlineLexer(renderer)
+ # enable the feature
+ inline.enable_wiki_link()
markdown = Markdown(renderer, inline=inline)
markdown('[[Link Text|Wiki Link]]')
@@ -220,12 +229,21 @@ 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
-------------
+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
diff --git a/mistune.py b/mistune.py
index 316f86d..86d215e 100644
--- a/mistune.py
+++ b/mistune.py
@@ -476,6 +476,11 @@ class InlineLexer(object):
'double_emphasis', 'emphasis', 'code',
'linebreak', 'strikethrough', 'text',
]
+ inline_html_rules = [
+ 'escape', 'autolink', 'url', 'link', 'reflink',
+ 'nolink', 'double_emphasis', 'emphasis', 'code',
+ 'linebreak', 'strikethrough', 'text',
+ ]
def __init__(self, renderer, rules=None, **kwargs):
self.renderer = renderer
@@ -491,6 +496,10 @@ class InlineLexer(object):
self._in_link = False
self._in_footnote = False
+ kwargs.update(self.renderer.options)
+ _to_parse = kwargs.get('parse_html') or kwargs.get('parse_inline_html')
+ self._parse_inline_html = _to_parse
+
def __call__(self, text):
return self.output(text)
@@ -553,7 +562,15 @@ class InlineLexer(object):
return self.renderer.autolink(link, False)
def output_inline_html(self, m):
- return self.renderer.inline_html(m.group(0))
+ text = m.group(0)
+ if self._parse_inline_html:
+ if m.group(1) == 'a':
+ self._in_link = True
+ text = self.output(text, rules=self.inline_html_rules)
+ self._in_link = False
+ else:
+ text = self.output(text, rules=self.inline_html_rules)
+ return self.renderer.inline_html(text)
def output_footnote(self, m):
key = _keyify(m.group(1))
@@ -909,6 +926,10 @@ class Markdown(object):
self.footnotes = []
self.tokens = []
+ # detect if it should parse text in block html
+ _to_parse = kwargs.get('parse_html') or kwargs.get('parse_block_html')
+ self._parse_block_html = _to_parse
+
def __call__(self, text):
return self.parse(text)
@@ -1072,7 +1093,7 @@ class Markdown(object):
def output_block_html(self):
text = self.token['text']
- if self.options.get('parse_html') and not self.token.get('pre'):
+ if self._parse_block_html and not self.token.get('pre'):
text = self.inline(text)
return self.renderer.block_html(text)
diff --git a/tests/test_cases.py b/tests/test_cases.py
index 933fa4c..3853a67 100644
--- a/tests/test_cases.py
+++ b/tests/test_cases.py
@@ -99,12 +99,36 @@ def test_use_xhtml():
assert '<img src="bar" alt="foo" title="title" />' in ret
-def test_block_html():
+def test_parse_html():
ret = mistune.markdown('<div>**foo**</div>')
assert '<strong>' not in ret
ret = mistune.markdown('<div>**foo**</div>', parse_html=True)
assert '<strong>' in ret
+ ret = mistune.markdown('<span>**foo**</span>')
+ assert '<strong>' not in ret
+ ret = mistune.markdown('<span>**foo**</span>', parse_html=True)
+ assert '<strong>' in ret
+
+ ret = mistune.markdown('<span>http://example.com</span>', parse_html=True)
+ assert 'href' in ret
+ ret = mistune.markdown('<a>http://example.com</a>', parse_html=True)
+ assert 'href' not in ret
+
+
+def test_parse_inline_html():
+ ret = mistune.markdown('<div>**foo**</div>', parse_inline_html=True)
+ assert '<strong>' not in ret
+ ret = mistune.markdown('<span>**foo**</span>', parse_inline_html=True)
+ assert '<strong>' in ret
+
+
+def test_parse_block_html():
+ ret = mistune.markdown('<div>**foo**</div>', parse_block_html=True)
+ assert '<strong>' in ret
+ ret = mistune.markdown('<span>**foo**</span>', parse_block_html=True)
+ assert '<strong>' not in ret
+
def test_trigger_more_cases():
markdown = mistune.Markdown(
@@ -114,79 +138,3 @@ def test_trigger_more_cases():
)
ret = markdown.render('foo[^foo]\n\n[^foo]: foo\n\n[^foo]: bar\n')
assert 'bar' not in ret
-
-
-def test_custom_lexer():
- import copy
-
- class MyInlineGrammar(mistune.InlineGrammar):
- # it would take a while for creating the right regex
- wiki_link = re.compile(
- r'\[\[' # [[
- r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2
- r'\]\](?!\])' # ]]
- )
-
- class MyInlineLexer(mistune.InlineLexer):
- default_rules = copy.copy(mistune.InlineLexer.default_rules)
- default_rules.insert(3, 'wiki_link')
-
- def __init__(self, renderer, rules=None, **kwargs):
- if rules is None:
- rules = MyInlineGrammar()
-
- super(MyInlineLexer, self).__init__(renderer, rules, **kwargs)
-
- def output_wiki_link(self, m):
- text = m.group(1)
- alt, link = text.split('|')
- return '<a href="%s">%s</a>' % (link, alt)
-
- markdown = mistune.Markdown(inline=MyInlineLexer)
- ret = markdown('[[Link Text|Wiki Link]]')
- assert '<a href' in ret
-
-
-def test_token_tree():
- """Tests a Renderer that returns a list from the placeholder method."""
-
- class CustomRenderer(mistune.Renderer):
- def placeholder(self):
- return []
-
- def __getattribute__(self, name):
- """Saves the arguments to each Markdown handling method."""
- found = CustomRenderer.__dict__.get(name)
- if found:
- return object.__getattribute__(self, name)
-
- def fake_method(*args, **kwargs):
- return [(name, args, kwargs)]
- return fake_method
-
- with open(os.path.join(root, 'fixtures', 'data', 'tree.md')) as f:
- content = f.read()
-
- expected = [
- ('header', ([('text', ('Title here',), {})], 2, 'Title here'), {}),
- ('paragraph', ([('text', ('Some text.',), {})],), {}),
- ('paragraph',
- ([('text', ('In two paragraphs. And then a list.',), {})],),
- {}),
- ('list',
- ([('list_item', ([('text', ('foo',), {})],), {}),
- ('list_item',
- ([('text', ('bar',), {}),
- ('list',
- ([('list_item', ([('text', ('meep',), {})],), {}),
- ('list_item', ([('text', ('stuff',), {})],), {})],
- True),
- {})],),
- {})],
- False),
- {})
- ]
-
- processor = mistune.Markdown(renderer=CustomRenderer())
- found = processor.render(content)
- assert expected == found, "Expected:\n%r\n\nFound:\n%r" % (expected, found)
diff --git a/tests/test_subclassing.py b/tests/test_subclassing.py
index 2cebfc0..f0df225 100644
--- a/tests/test_subclassing.py
+++ b/tests/test_subclassing.py
@@ -2,6 +2,7 @@
import os
import re
+import copy
import mistune
root = os.path.dirname(__file__)
@@ -73,7 +74,7 @@ class MarkdownWithMath(mistune.Markdown):
)
-class CustomRenderer(mistune.Renderer):
+class MathRenderer(mistune.Renderer):
def block_math(self, text):
return '$$%s$$' % text
@@ -92,7 +93,7 @@ def assert_data(filename):
else:
text = filename
- rv = MarkdownWithMath(renderer=CustomRenderer()).render(text)
+ rv = MarkdownWithMath(renderer=MathRenderer()).render(text)
assert text in rv
@@ -109,3 +110,82 @@ def test_markdown2html_math():
def test_math_paragraph():
# https://github.com/ipython/ipython/issues/6724
assert_data('math-paragraph.md')
+
+
+class WikiInlineGrammar(mistune.InlineGrammar):
+ # it would take a while for creating the right regex
+ wiki_link = re.compile(
+ r'\[\[' # [[
+ r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2
+ r'\]\](?!\])' # ]]
+ )
+
+
+class WikiInlineLexer(mistune.InlineLexer):
+ default_rules = copy.copy(mistune.InlineLexer.default_rules)
+ default_rules.insert(3, 'wiki_link')
+
+ def __init__(self, renderer, rules=None, **kwargs):
+ if rules is None:
+ rules = WikiInlineGrammar()
+
+ super(WikiInlineLexer, self).__init__(renderer, rules, **kwargs)
+
+ def output_wiki_link(self, m):
+ text = m.group(1)
+ alt, link = text.split('|')
+ return '<a href="%s">%s</a>' % (link, alt)
+
+
+def test_custom_lexer():
+ markdown = mistune.Markdown(inline=WikiInlineLexer)
+ ret = markdown('[[Link Text|Wiki Link]]')
+ assert '<a href' in ret
+
+
+class TokenTreeRenderer(mistune.Renderer):
+ # options is required
+ options = {}
+
+ def placeholder(self):
+ return []
+
+ def __getattribute__(self, name):
+ """Saves the arguments to each Markdown handling method."""
+ found = TokenTreeRenderer.__dict__.get(name)
+ if found is not None:
+ return object.__getattribute__(self, name)
+
+ def fake_method(*args, **kwargs):
+ return [(name, args, kwargs)]
+ return fake_method
+
+
+def test_token_tree():
+ """Tests a Renderer that returns a list from the placeholder method."""
+ with open(os.path.join(root, 'fixtures', 'data', 'tree.md')) as f:
+ content = f.read()
+
+ expected = [
+ ('header', ([('text', ('Title here',), {})], 2, 'Title here'), {}),
+ ('paragraph', ([('text', ('Some text.',), {})],), {}),
+ ('paragraph',
+ ([('text', ('In two paragraphs. And then a list.',), {})],),
+ {}),
+ ('list',
+ ([('list_item', ([('text', ('foo',), {})],), {}),
+ ('list_item',
+ ([('text', ('bar',), {}),
+ ('list',
+ ([('list_item', ([('text', ('meep',), {})],), {}),
+ ('list_item', ([('text', ('stuff',), {})],), {})],
+ True),
+ {})],),
+ {})],
+ False),
+ {})
+ ]
+
+ processor = mistune.Markdown(renderer=TokenTreeRenderer())
+ found = processor.render(content)
+ assert expected == found, "Expected:\n%r\n\nFound:\n%r" % (expected, found)

View File

@@ -1,28 +0,0 @@
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=5
PYTHON_COMPAT=( python2_7 python3_4 pypy pypy3 )
inherit distutils-r1
DESCRIPTION="The fastest markdown parser in pure Python"
HOMEPAGE="https://pypi.python.org/pypi/mistune https://github.com/lepture/mistune"
SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
SLOT="0"
LICENSE="BSD"
KEYWORDS="amd64 arm ~ppc ~ppc64 x86 ~amd64-linux ~x86-linux"
IUSE="test"
RDEPEND=""
DEPEND="${RDEPEND}
dev-python/cython[$(python_gen_usedep 'python*')]
dev-python/setuptools[${PYTHON_USEDEP}]
test? ( dev-python/nose[${PYTHON_USEDEP}] )
"
python_test() {
nosetests || die
}

View File

@@ -1,30 +0,0 @@
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=5
PYTHON_COMPAT=( python2_7 python3_4 pypy pypy3 )
inherit distutils-r1
DESCRIPTION="The fastest markdown parser in pure Python"
HOMEPAGE="https://pypi.python.org/pypi/mistune https://github.com/lepture/mistune"
SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
SLOT="0"
LICENSE="BSD"
KEYWORDS="~amd64 ~ppc ~ppc64 ~x86 ~amd64-linux ~x86-linux"
IUSE="test"
RDEPEND=""
DEPEND="${RDEPEND}
dev-python/cython[$(python_gen_usedep 'python*')]
dev-python/setuptools[${PYTHON_USEDEP}]
test? ( dev-python/nose[${PYTHON_USEDEP}] )
"
PATCHES=( "${FILESDIR}"/${P}-inline-html.patch )
python_test() {
nosetests || die
}

View File

@@ -1,28 +0,0 @@
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=5
PYTHON_COMPAT=( python2_7 python3_{4,5} pypy pypy3 )
inherit distutils-r1
DESCRIPTION="The fastest markdown parser in pure Python"
HOMEPAGE="https://pypi.python.org/pypi/mistune https://github.com/lepture/mistune"
SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
SLOT="0"
LICENSE="BSD"
KEYWORDS="~amd64 ~arm ~ppc ~ppc64 ~x86 ~amd64-linux ~x86-linux"
IUSE="test"
RDEPEND=""
DEPEND="${RDEPEND}
dev-python/cython[$(python_gen_usedep 'python*')]
dev-python/setuptools[${PYTHON_USEDEP}]
test? ( dev-python/nose[${PYTHON_USEDEP}] )
"
python_test() {
nosetests || die
}

View File

@@ -1,28 +0,0 @@
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=5
PYTHON_COMPAT=( python2_7 python3_4 pypy pypy3 )
inherit distutils-r1
DESCRIPTION="The fastest markdown parser in pure Python"
HOMEPAGE="https://pypi.python.org/pypi/mistune https://github.com/lepture/mistune"
SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
SLOT="0"
LICENSE="BSD"
KEYWORDS="~amd64 ~ppc ~ppc64 ~x86 ~amd64-linux ~x86-linux"
IUSE="test"
RDEPEND=""
DEPEND="${RDEPEND}
dev-python/cython[$(python_gen_usedep 'python*')]
dev-python/setuptools[${PYTHON_USEDEP}]
test? ( dev-python/nose[${PYTHON_USEDEP}] )
"
python_test() {
nosetests || die
}