Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/mistune-0.8.4.dist-info/METADATA @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 Metadata-Version: 2.0 | |
| 2 Name: mistune | |
| 3 Version: 0.8.4 | |
| 4 Summary: The fastest markdown parser in pure Python | |
| 5 Home-page: https://github.com/lepture/mistune | |
| 6 Author: Hsiaoming Yang | |
| 7 Author-email: me@lepture.com | |
| 8 License: BSD | |
| 9 Platform: any | |
| 10 Classifier: Development Status :: 4 - Beta | |
| 11 Classifier: Environment :: Web Environment | |
| 12 Classifier: Intended Audience :: Developers | |
| 13 Classifier: License :: OSI Approved :: BSD License | |
| 14 Classifier: Operating System :: OS Independent | |
| 15 Classifier: Programming Language :: Python | |
| 16 Classifier: Programming Language :: Python :: 2 | |
| 17 Classifier: Programming Language :: Python :: 2.7 | |
| 18 Classifier: Programming Language :: Python :: 3 | |
| 19 Classifier: Programming Language :: Python :: 3.5 | |
| 20 Classifier: Programming Language :: Python :: 3.6 | |
| 21 Classifier: Programming Language :: Python :: 3.7 | |
| 22 Classifier: Programming Language :: Python :: Implementation :: CPython | |
| 23 Classifier: Programming Language :: Python :: Implementation :: PyPy | |
| 24 Classifier: Topic :: Text Processing :: Markup | |
| 25 Classifier: Topic :: Software Development :: Libraries :: Python Modules | |
| 26 | |
| 27 Mistune | |
| 28 ======= | |
| 29 | |
| 30 The fastest markdown parser in pure Python with renderer features, | |
| 31 inspired by marked_. | |
| 32 | |
| 33 .. image:: https://img.shields.io/badge/donate-lepture-green.svg | |
| 34 :target: https://lepture.com/donate | |
| 35 :alt: Donate lepture | |
| 36 .. image:: https://img.shields.io/pypi/wheel/mistune.svg?style=flat | |
| 37 :target: https://pypi.python.org/pypi/mistune/ | |
| 38 :alt: Wheel Status | |
| 39 .. image:: https://anaconda.org/conda-forge/mistune/badges/version.svg | |
| 40 :target: https://anaconda.org/conda-forge/mistune | |
| 41 :alt: Conda Version | |
| 42 .. image:: https://img.shields.io/pypi/v/mistune.svg | |
| 43 :target: https://pypi.python.org/pypi/mistune/ | |
| 44 :alt: Latest Version | |
| 45 .. image:: https://travis-ci.org/lepture/mistune.svg?branch=master | |
| 46 :target: https://travis-ci.org/lepture/mistune | |
| 47 :alt: Travis CI Status | |
| 48 .. image:: https://coveralls.io/repos/lepture/mistune/badge.svg?branch=master | |
| 49 :target: https://coveralls.io/r/lepture/mistune | |
| 50 :alt: Coverage Status | |
| 51 .. image:: https://ci.appveyor.com/api/projects/status/8ai8tfwp75oela17?svg=true | |
| 52 :target: https://ci.appveyor.com/project/lepture/mistune | |
| 53 :alt: App Veyor CI Status | |
| 54 | |
| 55 .. _marked: https://github.com/chjj/marked | |
| 56 | |
| 57 | |
| 58 Features | |
| 59 -------- | |
| 60 | |
| 61 * **Pure Python**. Tested in Python 2.7, Python 3.5+ and PyPy. | |
| 62 * **Very Fast**. It is the fastest in all **pure Python** markdown parsers. | |
| 63 * **More Features**. Table, footnotes, autolink, fenced code etc. | |
| 64 | |
| 65 View the `benchmark results <https://github.com/lepture/mistune/issues/1>`_. | |
| 66 | |
| 67 Installation | |
| 68 ------------ | |
| 69 | |
| 70 Installing mistune with pip:: | |
| 71 | |
| 72 $ pip install mistune | |
| 73 | |
| 74 | |
| 75 Mistune can be faster, if you compile with cython:: | |
| 76 | |
| 77 $ pip install cython mistune | |
| 78 | |
| 79 | |
| 80 Basic Usage | |
| 81 ----------- | |
| 82 | |
| 83 A simple API that render a markdown formatted text: | |
| 84 | |
| 85 .. code:: python | |
| 86 | |
| 87 import mistune | |
| 88 | |
| 89 mistune.markdown('I am using **mistune markdown parser**') | |
| 90 # output: <p>I am using <strong>mistune markdown parser</strong></p> | |
| 91 | |
| 92 If you care about performance, it is better to re-use the Markdown instance: | |
| 93 | |
| 94 .. code:: python | |
| 95 | |
| 96 import mistune | |
| 97 | |
| 98 markdown = mistune.Markdown() | |
| 99 markdown('I am using **mistune markdown parser**') | |
| 100 | |
| 101 Mistune has enabled all features by default. You don't have to configure | |
| 102 anything. But there are options for you to change the parser behaviors. | |
| 103 | |
| 104 | |
| 105 Options | |
| 106 ------- | |
| 107 | |
| 108 Here is a list of all options that will affect the rendering results, | |
| 109 configure them with ``mistune.Renderer``: | |
| 110 | |
| 111 .. code:: python | |
| 112 | |
| 113 renderer = mistune.Renderer(escape=True, hard_wrap=True) | |
| 114 # use this renderer instance | |
| 115 markdown = mistune.Markdown(renderer=renderer) | |
| 116 markdown(text) | |
| 117 | |
| 118 * **escape**: if set to *False*, all raw html tags will not be escaped. | |
| 119 * **hard_wrap**: if set to *True*, it will has GFM line breaks feature. | |
| 120 All new lines will be replaced with ``<br>`` tag | |
| 121 * **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``<hr />``. | |
| 122 * **parse_block_html**: parse text only in block level html. | |
| 123 * **parse_inline_html**: parse text only in inline level html. | |
| 124 | |
| 125 When using the default renderer, you can use one of the following shortcuts:: | |
| 126 | |
| 127 mistune.markdown(text, escape=True, hard_wrap=True) | |
| 128 | |
| 129 markdown = mistune.Markdown(escape=True, hard_wrap=True) | |
| 130 markdown(text) | |
| 131 | |
| 132 | |
| 133 Renderer | |
| 134 -------- | |
| 135 | |
| 136 Like misaka/sundown, you can influence the rendering by custom renderers. | |
| 137 All you need to do is subclassing a `Renderer` class. | |
| 138 | |
| 139 Here is an example of code highlighting: | |
| 140 | |
| 141 .. code:: python | |
| 142 | |
| 143 import mistune | |
| 144 from pygments import highlight | |
| 145 from pygments.lexers import get_lexer_by_name | |
| 146 from pygments.formatters import html | |
| 147 | |
| 148 class HighlightRenderer(mistune.Renderer): | |
| 149 def block_code(self, code, lang): | |
| 150 if not lang: | |
| 151 return '\n<pre><code>%s</code></pre>\n' % \ | |
| 152 mistune.escape(code) | |
| 153 lexer = get_lexer_by_name(lang, stripall=True) | |
| 154 formatter = html.HtmlFormatter() | |
| 155 return highlight(code, lexer, formatter) | |
| 156 | |
| 157 renderer = HighlightRenderer() | |
| 158 markdown = mistune.Markdown(renderer=renderer) | |
| 159 print(markdown('```python\nassert 1 == 1\n```')) | |
| 160 | |
| 161 Find more renderers in `mistune-contrib`_. | |
| 162 | |
| 163 Block Level | |
| 164 ~~~~~~~~~~~ | |
| 165 | |
| 166 Here is a list of block level renderer API:: | |
| 167 | |
| 168 block_code(code, language=None) | |
| 169 block_quote(text) | |
| 170 block_html(html) | |
| 171 header(text, level, raw=None) | |
| 172 hrule() | |
| 173 list(body, ordered=True) | |
| 174 list_item(text) | |
| 175 paragraph(text) | |
| 176 table(header, body) | |
| 177 table_row(content) | |
| 178 table_cell(content, **flags) | |
| 179 | |
| 180 The *flags* tells you whether it is header with ``flags['header']``. And it | |
| 181 also tells you the align with ``flags['align']``. | |
| 182 | |
| 183 | |
| 184 Span Level | |
| 185 ~~~~~~~~~~ | |
| 186 | |
| 187 Here is a list of span level renderer API:: | |
| 188 | |
| 189 autolink(link, is_email=False) | |
| 190 codespan(text) | |
| 191 double_emphasis(text) | |
| 192 emphasis(text) | |
| 193 image(src, title, alt_text) | |
| 194 linebreak() | |
| 195 newline() | |
| 196 link(link, title, content) | |
| 197 strikethrough(text) | |
| 198 text(text) | |
| 199 inline_html(text) | |
| 200 | |
| 201 Footnotes | |
| 202 ~~~~~~~~~ | |
| 203 | |
| 204 Here is a list of renderers related to footnotes:: | |
| 205 | |
| 206 footnote_ref(key, index) | |
| 207 footnote_item(key, text) | |
| 208 footnotes(text) | |
| 209 | |
| 210 Lexers | |
| 211 ------ | |
| 212 | |
| 213 Sometimes you want to add your own rules to Markdown, such as GitHub Wiki | |
| 214 links. You can't achieve this goal with renderers. You will need to deal | |
| 215 with the lexers, it would be a little difficult for the first time. | |
| 216 | |
| 217 We will take an example for GitHub Wiki links: ``[[Page 2|Page 2]]``. | |
| 218 It is an inline grammar, which requires custom ``InlineGrammar`` and | |
| 219 ``InlineLexer``: | |
| 220 | |
| 221 .. code:: python | |
| 222 | |
| 223 import copy,re | |
| 224 from mistune import Renderer, InlineGrammar, InlineLexer | |
| 225 | |
| 226 class WikiLinkRenderer(Renderer): | |
| 227 def wiki_link(self, alt, link): | |
| 228 return '<a href="%s">%s</a>' % (link, alt) | |
| 229 | |
| 230 class WikiLinkInlineLexer(InlineLexer): | |
| 231 def enable_wiki_link(self): | |
| 232 # add wiki_link rules | |
| 233 self.rules.wiki_link = re.compile( | |
| 234 r'\[\[' # [[ | |
| 235 r'([\s\S]+?\|[\s\S]+?)' # Page 2|Page 2 | |
| 236 r'\]\](?!\])' # ]] | |
| 237 ) | |
| 238 | |
| 239 # Add wiki_link parser to default rules | |
| 240 # you can insert it some place you like | |
| 241 # but place matters, maybe 3 is not good | |
| 242 self.default_rules.insert(3, 'wiki_link') | |
| 243 | |
| 244 def output_wiki_link(self, m): | |
| 245 text = m.group(1) | |
| 246 alt, link = text.split('|') | |
| 247 # you can create an custom render | |
| 248 # you can also return the html if you like | |
| 249 return self.renderer.wiki_link(alt, link) | |
| 250 | |
| 251 You should pass the inline lexer to ``Markdown`` parser: | |
| 252 | |
| 253 .. code:: python | |
| 254 | |
| 255 renderer = WikiLinkRenderer() | |
| 256 inline = WikiLinkInlineLexer(renderer) | |
| 257 # enable the feature | |
| 258 inline.enable_wiki_link() | |
| 259 markdown = Markdown(renderer, inline=inline) | |
| 260 markdown('[[Link Text|Wiki Link]]') | |
| 261 | |
| 262 It is the same with block level lexer. It would take a while to understand | |
| 263 the whole mechanism. But you won't do the trick a lot. | |
| 264 | |
| 265 | |
| 266 Contribution & Extensions | |
| 267 ------------------------- | |
| 268 | |
| 269 Mistune itself doesn't accept any extension. It will always be a simple one | |
| 270 file script. | |
| 271 | |
| 272 If you want to add features, you can head over to `mistune-contrib`_. | |
| 273 | |
| 274 Here are some extensions already in `mistune-contrib`_: | |
| 275 | |
| 276 * Math/MathJax features | |
| 277 * Highlight Code Renderer | |
| 278 * TOC table of content features | |
| 279 * MultiMarkdown Metadata parser | |
| 280 | |
| 281 Get inspired with the contrib repository. | |
| 282 | |
| 283 .. _`mistune-contrib`: https://github.com/lepture/mistune-contrib | |
| 284 | |
| 285 |
