python-markdown-math-0.6/0000755000175000017500000000000013310733217016311 5ustar dmitrydmitry00000000000000python-markdown-math-0.6/setup.py0000644000175000017500000000122013310733160020013 0ustar dmitrydmitry00000000000000#!/usr/bin/env python3 from setuptools import setup with open('README.md') as readme_file: long_description = readme_file.read() setup(name='python-markdown-math', description='Math extension for Python-Markdown', long_description=long_description, long_description_content_type='text/markdown', author='Dmitry Shachnev', author_email='mitya57@gmail.com', version='0.6', url='https://github.com/mitya57/python-markdown-math', py_modules=['mdx_math'], entry_points={ 'markdown.extensions': [ 'mdx_math = mdx_math:MathExtension', ], }, license='BSD') python-markdown-math-0.6/changelog0000644000175000017500000000220613310732740020163 0ustar dmitrydmitry00000000000000Version 0.6, 2018-06-13 ======================= * Include LICENSE and tests in the tarball. Version 0.5, 2018-05-03 ======================= * Re-upload with fixed metadata and description. Version 0.4, 2018-05-03 ======================= * Added AsciiMath support. To switch from LaTeX syntax to AsciiMath, set the “use_asciimath” configuration option to true. * The dollar sign can now be escaped when the “enable_dollar_delimiter” option is enabled (\$ produces $). * Inline math can now be used inside standalone math. Version 0.3, 2017-03-24 ======================= * Added “add_preview” configuration option, which adds preview nodes as recognized by MathJax before every script node. - Thanks to Antoine Amarilli and Danni Randeris for their initial work. * Added a test suite. * Documentation improvements. Version 0.2, 2015-12-05 ======================= * Fix compatibility with earlier Python-Markdown versions. - Thanks to Bryan A. Jones for the contribution. * Add installation instructions from PyPI. - Thanks to Drew Hubl for the contribution. Version 0.1, 2015-08-12 ======================= * Initial release. python-markdown-math-0.6/test.py0000755000175000017500000000356513272376735017675 0ustar dmitrydmitry00000000000000#!/usr/bin/env python3 from markdown import Markdown import unittest class MathTestCase(unittest.TestCase): def verify(self, mkd_name, html_name, config=None): config = config or dict() md = Markdown(extensions=['mdx_math'], extension_configs={'mdx_math': config}) with open('test_data/%s.mkd' % mkd_name) as mkd_file: mkd = mkd_file.read() with open('test_data/%s.html' % html_name) as html_file: html = html_file.read() self.assertEqual(html, md.convert(mkd) + '\n') def r(mkd_name, html_name, **config): return lambda self: self.verify(mkd_name, html_name, config=config) test_inline_latex = r('inline_latex', 'inline') test_inline_latex_escaped = r('inline_latex_escaped', 'inline_latex_escaped') test_inline_latex_preview = r('inline_latex', 'inline_preview', add_preview=True) test_inline_tex = r('inline_tex', 'inline', enable_dollar_delimiter=True) test_inline_tex_disabled = r('inline_tex', 'inline_tex_disabled') test_inline_tex_escaped = r('inline_tex_escaped', 'inline_tex_escaped', enable_dollar_delimiter=True) test_inline_inside_code = r('inline_latex_inside_code', 'inline_latex_inside_code') test_inline_inside_standalone = r('inline_inside_standalone', 'inline_inside_standalone') test_standalone_latex = r('standalone_latex', 'standalone') test_standalone_latex_escaped = r('standalone_latex_escaped', 'standalone_latex_escaped') test_standalone_latex_preview = r('standalone_latex', 'standalone_preview', add_preview=True) test_standalone_tex = r('standalone_tex', 'standalone') test_begin_end = r('beginend', 'beginend') test_begin_end_preview = r('beginend', 'beginend_preview', add_preview=True) test_inline_asciimath = r('inline_asciimath', 'inline_asciimath', use_asciimath=True) if __name__ == '__main__': unittest.main(verbosity=2) python-markdown-math-0.6/MANIFEST.in0000644000175000017500000000015513310200540020034 0ustar dmitrydmitry00000000000000include README.md include changelog include LICENSE include test.py recursive-include test_data *.mkd *.html python-markdown-math-0.6/README.md0000644000175000017500000000506413272610642017600 0ustar dmitrydmitry00000000000000[![Travis CI status](https://api.travis-ci.org/mitya57/python-markdown-math.svg)][Travis] [Travis]: https://travis-ci.org/mitya57/python-markdown-math Math extension for Python-Markdown ================================== This extension adds math formulas support to [Python-Markdown]. [Python-Markdown]: https://github.com/Python-Markdown/markdown Installation ------------ ### Install from PyPI ``` $ pip install python-markdown-math ``` ### Install locally Use `setup.py build` and `setup.py install` to build and install this extension, respectively. The extension name is `mdx_math`, so you need to add that name to your list of Python-Markdown extensions. Check [Python-Markdown documentation] for details on how to load extensions. [Python-Markdown documentation]: https://python-markdown.github.io/reference/#extensions Usage ----- To use this extension, you need to include [MathJax] library in HTML files, like: ```html ``` (replace `2.7.4` with the latest version if it is available). [MathJax]: https://www.mathjax.org/ Also, you need to specify a configuration for MathJax. Please note that most of standard configuratons include `tex2jax` extension, which is not needed with this code. Example of MathJax configuration: ```html ``` To pass the extension to Python-Markdown, use `mdx_math` as extension name. For example: ```python >>> md = markdown.Markdown(extensions=['mdx_math']) >>> md.convert('$$e^x$$') '

\n\n

' ``` Usage from the command line: ``` $ echo "\(e^x\)" | python3 -m markdown -x mdx_math

``` Math Delimiters --------------- For inline math, use `\(...\)`. For standalone math, use `$$...$$`, `\[...\]` or `\begin...\end`. The single-dollar delimiter (`$...$`) for inline math is disabled by default, but can be enabled by passing `enable_dollar_delimiter=True` in the extension configuration. If you want to this extension to generate a preview node (which will be shown when MathJax has not yet processed the node, or when JavaScript is unavailable), use `add_preview=True` configuration option. Notes ----- If you use [ReText](https://github.com/retext-project/retext), this extension is not needed as it is included by default. python-markdown-math-0.6/python_markdown_math.egg-info/0000755000175000017500000000000013310733217024237 5ustar dmitrydmitry00000000000000python-markdown-math-0.6/python_markdown_math.egg-info/entry_points.txt0000644000175000017500000000007113310733217027533 0ustar dmitrydmitry00000000000000[markdown.extensions] mdx_math = mdx_math:MathExtension python-markdown-math-0.6/python_markdown_math.egg-info/dependency_links.txt0000644000175000017500000000000113310733217030305 0ustar dmitrydmitry00000000000000 python-markdown-math-0.6/python_markdown_math.egg-info/SOURCES.txt0000644000175000017500000000206513310733217026126 0ustar dmitrydmitry00000000000000LICENSE MANIFEST.in README.md changelog mdx_math.py setup.cfg setup.py test.py python_markdown_math.egg-info/PKG-INFO python_markdown_math.egg-info/SOURCES.txt python_markdown_math.egg-info/dependency_links.txt python_markdown_math.egg-info/entry_points.txt python_markdown_math.egg-info/top_level.txt test_data/beginend.html test_data/beginend.mkd test_data/beginend_preview.html test_data/inline.html test_data/inline_asciimath.html test_data/inline_asciimath.mkd test_data/inline_inside_standalone.html test_data/inline_inside_standalone.mkd test_data/inline_latex.mkd test_data/inline_latex_escaped.html test_data/inline_latex_escaped.mkd test_data/inline_latex_inside_code.html test_data/inline_latex_inside_code.mkd test_data/inline_preview.html test_data/inline_tex.mkd test_data/inline_tex_disabled.html test_data/inline_tex_escaped.html test_data/inline_tex_escaped.mkd test_data/standalone.html test_data/standalone_latex.mkd test_data/standalone_latex_escaped.html test_data/standalone_latex_escaped.mkd test_data/standalone_preview.html test_data/standalone_tex.mkdpython-markdown-math-0.6/python_markdown_math.egg-info/top_level.txt0000644000175000017500000000001113310733217026761 0ustar dmitrydmitry00000000000000mdx_math python-markdown-math-0.6/python_markdown_math.egg-info/PKG-INFO0000644000175000017500000000720613310733217025341 0ustar dmitrydmitry00000000000000Metadata-Version: 2.1 Name: python-markdown-math Version: 0.6 Summary: Math extension for Python-Markdown Home-page: https://github.com/mitya57/python-markdown-math Author: Dmitry Shachnev Author-email: mitya57@gmail.com License: BSD Description: [![Travis CI status](https://api.travis-ci.org/mitya57/python-markdown-math.svg)][Travis] [Travis]: https://travis-ci.org/mitya57/python-markdown-math Math extension for Python-Markdown ================================== This extension adds math formulas support to [Python-Markdown]. [Python-Markdown]: https://github.com/Python-Markdown/markdown Installation ------------ ### Install from PyPI ``` $ pip install python-markdown-math ``` ### Install locally Use `setup.py build` and `setup.py install` to build and install this extension, respectively. The extension name is `mdx_math`, so you need to add that name to your list of Python-Markdown extensions. Check [Python-Markdown documentation] for details on how to load extensions. [Python-Markdown documentation]: https://python-markdown.github.io/reference/#extensions Usage ----- To use this extension, you need to include [MathJax] library in HTML files, like: ```html ``` (replace `2.7.4` with the latest version if it is available). [MathJax]: https://www.mathjax.org/ Also, you need to specify a configuration for MathJax. Please note that most of standard configuratons include `tex2jax` extension, which is not needed with this code. Example of MathJax configuration: ```html ``` To pass the extension to Python-Markdown, use `mdx_math` as extension name. For example: ```python >>> md = markdown.Markdown(extensions=['mdx_math']) >>> md.convert('$$e^x$$') '

\n\n

' ``` Usage from the command line: ``` $ echo "\(e^x\)" | python3 -m markdown -x mdx_math

``` Math Delimiters --------------- For inline math, use `\(...\)`. For standalone math, use `$$...$$`, `\[...\]` or `\begin...\end`. The single-dollar delimiter (`$...$`) for inline math is disabled by default, but can be enabled by passing `enable_dollar_delimiter=True` in the extension configuration. If you want to this extension to generate a preview node (which will be shown when MathJax has not yet processed the node, or when JavaScript is unavailable), use `add_preview=True` configuration option. Notes ----- If you use [ReText](https://github.com/retext-project/retext), this extension is not needed as it is included by default. Platform: UNKNOWN Description-Content-Type: text/markdown python-markdown-math-0.6/setup.cfg0000644000175000017500000000010313310733217020124 0ustar dmitrydmitry00000000000000[bdist_wheel] universal = 1 [egg_info] tag_build = tag_date = 0 python-markdown-math-0.6/mdx_math.py0000644000175000017500000000634213310201364020462 0ustar dmitrydmitry00000000000000# -*- coding: utf-8 -*- ''' Math extension for Python-Markdown ================================== Adds support for displaying math formulas using [MathJax](http://www.mathjax.org/). Author: 2015-2017, Dmitry Shachnev . ''' from markdown.inlinepatterns import Pattern from markdown.extensions import Extension from markdown.util import AtomicString, etree class MathExtension(Extension): def __init__(self, *args, **kwargs): self.config = { 'enable_dollar_delimiter': [False, 'Enable single-dollar delimiter'], 'add_preview': [False, 'Add a preview node before each math node'], 'use_asciimath': [False, 'Use AsciiMath syntax instead of TeX syntax'], } super(MathExtension, self).__init__(*args, **kwargs) def _get_content_type(self): if self.getConfig('use_asciimath'): return 'math/asciimath' return 'math/tex' def extendMarkdown(self, md, md_globals): def _wrap_node(node, preview_text, wrapper_tag): if not self.getConfig('add_preview'): return node preview = etree.Element('span', {'class': 'MathJax_Preview'}) preview.text = AtomicString(preview_text) wrapper = etree.Element(wrapper_tag) wrapper.extend([preview, node]) return wrapper def handle_match_inline(m): node = etree.Element('script') node.set('type', self._get_content_type()) node.text = AtomicString(m.group(3)) return _wrap_node(node, ''.join(m.group(2, 3, 4)), 'span') def handle_match(m): node = etree.Element('script') node.set('type', '%s; mode=display' % self._get_content_type()) if '\\begin' in m.group(2): node.text = AtomicString(''.join(m.group(2, 4, 5))) return _wrap_node(node, ''.join(m.group(1, 2, 4, 5, 6)), 'div') else: node.text = AtomicString(m.group(3)) return _wrap_node(node, ''.join(m.group(2, 3, 4)), 'div') inlinemathpatterns = ( Pattern(r'(?. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. Neither the name of the author 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 REGENTS 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. python-markdown-math-0.6/PKG-INFO0000644000175000017500000000720613310733217017413 0ustar dmitrydmitry00000000000000Metadata-Version: 2.1 Name: python-markdown-math Version: 0.6 Summary: Math extension for Python-Markdown Home-page: https://github.com/mitya57/python-markdown-math Author: Dmitry Shachnev Author-email: mitya57@gmail.com License: BSD Description: [![Travis CI status](https://api.travis-ci.org/mitya57/python-markdown-math.svg)][Travis] [Travis]: https://travis-ci.org/mitya57/python-markdown-math Math extension for Python-Markdown ================================== This extension adds math formulas support to [Python-Markdown]. [Python-Markdown]: https://github.com/Python-Markdown/markdown Installation ------------ ### Install from PyPI ``` $ pip install python-markdown-math ``` ### Install locally Use `setup.py build` and `setup.py install` to build and install this extension, respectively. The extension name is `mdx_math`, so you need to add that name to your list of Python-Markdown extensions. Check [Python-Markdown documentation] for details on how to load extensions. [Python-Markdown documentation]: https://python-markdown.github.io/reference/#extensions Usage ----- To use this extension, you need to include [MathJax] library in HTML files, like: ```html ``` (replace `2.7.4` with the latest version if it is available). [MathJax]: https://www.mathjax.org/ Also, you need to specify a configuration for MathJax. Please note that most of standard configuratons include `tex2jax` extension, which is not needed with this code. Example of MathJax configuration: ```html ``` To pass the extension to Python-Markdown, use `mdx_math` as extension name. For example: ```python >>> md = markdown.Markdown(extensions=['mdx_math']) >>> md.convert('$$e^x$$') '

\n\n

' ``` Usage from the command line: ``` $ echo "\(e^x\)" | python3 -m markdown -x mdx_math

``` Math Delimiters --------------- For inline math, use `\(...\)`. For standalone math, use `$$...$$`, `\[...\]` or `\begin...\end`. The single-dollar delimiter (`$...$`) for inline math is disabled by default, but can be enabled by passing `enable_dollar_delimiter=True` in the extension configuration. If you want to this extension to generate a preview node (which will be shown when MathJax has not yet processed the node, or when JavaScript is unavailable), use `add_preview=True` configuration option. Notes ----- If you use [ReText](https://github.com/retext-project/retext), this extension is not needed as it is included by default. Platform: UNKNOWN Description-Content-Type: text/markdown python-markdown-math-0.6/test_data/0000755000175000017500000000000013310733217020261 5ustar dmitrydmitry00000000000000python-markdown-math-0.6/test_data/inline_latex.mkd0000644000175000017500000000004013272376735023442 0ustar dmitrydmitry00000000000000Inline math: \(e^{i \varphi}\). python-markdown-math-0.6/test_data/inline_asciimath.mkd0000644000175000017500000000004513272376735024274 0ustar dmitrydmitry00000000000000\( sum_(i=1)^n i^3=((n(n+1))/2)^2 \) python-markdown-math-0.6/test_data/inline_latex_escaped.html0000644000175000017500000000004713272376735025326 0ustar dmitrydmitry00000000000000

Inline math: \(e^{i \varphi}\).

python-markdown-math-0.6/test_data/standalone_latex_escaped.html0000644000175000017500000000007513272376735026201 0ustar dmitrydmitry00000000000000

\[ e^{i \varphi} = \cos \varphi + i \sin \varphi \]

python-markdown-math-0.6/test_data/inline_latex_inside_code.mkd0000644000175000017500000000002413272376735025771 0ustar dmitrydmitry00000000000000`\(e^{i \varphi}\)` python-markdown-math-0.6/test_data/beginend.html0000644000175000017500000000021413272376735022736 0ustar dmitrydmitry00000000000000

python-markdown-math-0.6/test_data/beginend.mkd0000644000175000017500000000012413272376735022545 0ustar dmitrydmitry00000000000000\begin{equation*} \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix} \end{equation*} python-markdown-math-0.6/test_data/inline_inside_standalone.html0000644000175000017500000000014013272376735026202 0ustar dmitrydmitry00000000000000

python-markdown-math-0.6/test_data/inline_tex_escaped.html0000644000175000017500000000011513272376735025005 0ustar dmitrydmitry00000000000000

Escaped $ dollar sign and real .

python-markdown-math-0.6/test_data/standalone_latex_escaped.mkd0000644000175000017500000000007013272376735026003 0ustar dmitrydmitry00000000000000\\[ e^{i \varphi} = \cos \varphi + i \sin \varphi \\] python-markdown-math-0.6/test_data/standalone_preview.html0000644000175000017500000000032013272376735025052 0ustar dmitrydmitry00000000000000

\[ e^{i \varphi} = \cos \varphi + i \sin \varphi \]

python-markdown-math-0.6/test_data/inline_preview.html0000644000175000017500000000020713272376735024204 0ustar dmitrydmitry00000000000000

Inline math: \(e^{i \varphi}\).

python-markdown-math-0.6/test_data/standalone_latex.mkd0000644000175000017500000000006613272376735024324 0ustar dmitrydmitry00000000000000\[ e^{i \varphi} = \cos \varphi + i \sin \varphi \] python-markdown-math-0.6/test_data/standalone.html0000644000175000017500000000015213272376735023314 0ustar dmitrydmitry00000000000000

python-markdown-math-0.6/test_data/inline_tex_disabled.html0000644000175000017500000000004513272376735025152 0ustar dmitrydmitry00000000000000

Inline math: $e^{i \varphi}$.

python-markdown-math-0.6/test_data/inline_latex_escaped.mkd0000644000175000017500000000004213272376735025130 0ustar dmitrydmitry00000000000000Inline math: \\(e^{i \varphi}\\). python-markdown-math-0.6/test_data/standalone_tex.mkd0000644000175000017500000000006613272376735024007 0ustar dmitrydmitry00000000000000$$ e^{i \varphi} = \cos \varphi + i \sin \varphi $$ python-markdown-math-0.6/test_data/inline_tex_escaped.mkd0000644000175000017500000000005013272376735024612 0ustar dmitrydmitry00000000000000Escaped \$ dollar sign and real $math$. python-markdown-math-0.6/test_data/inline_tex.mkd0000644000175000017500000000003613272376735023132 0ustar dmitrydmitry00000000000000Inline math: $e^{i \varphi}$. python-markdown-math-0.6/test_data/inline_inside_standalone.mkd0000644000175000017500000000005413272376735026015 0ustar dmitrydmitry00000000000000\[ \sqrt{\text{ number of \(B\)-words }} \] python-markdown-math-0.6/test_data/inline_asciimath.html0000644000175000017500000000012113272376735024460 0ustar dmitrydmitry00000000000000

python-markdown-math-0.6/test_data/beginend_preview.html0000644000175000017500000000043013272376735024477 0ustar dmitrydmitry00000000000000

\begin{equation*} \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix} \end{equation*}

python-markdown-math-0.6/test_data/inline.html0000644000175000017500000000010413272376735022437 0ustar dmitrydmitry00000000000000

Inline math: .

python-markdown-math-0.6/test_data/inline_latex_inside_code.html0000644000175000017500000000004613272376735026166 0ustar dmitrydmitry00000000000000

\(e^{i \varphi}\)