Markups-0.4/0000755000175000017500000000000012246327450013646 5ustar dmitrydmitry00000000000000Markups-0.4/markups/0000755000175000017500000000000012246327450015330 5ustar dmitrydmitry00000000000000Markups-0.4/markups/textile.py0000644000175000017500000000164212246326672017370 0ustar dmitrydmitry00000000000000# This file is part of python-markups module # License: BSD # Copyright: (C) Dmitry Shachnev, 2013 from __future__ import absolute_import import markups.common as common from markups.abstract import AbstractMarkup class TextileMarkup(AbstractMarkup): """Textile language""" name = 'Textile' attributes = { common.LANGUAGE_HOME_PAGE: 'http://textile.sitemonks.com/', common.MODULE_HOME_PAGE: 'https://github.com/sebix/python-textile', common.SYNTAX_DOCUMENTATION: 'http://movabletype.org/documentation/author/textile-2-syntax.html' } file_extensions = ('.textile',) default_extension = '.textile' @staticmethod def available(): try: import textile except ImportError: return False return True def __init__(self, filename=None): AbstractMarkup.__init__(self, filename) from textile import Textile self.parser = Textile() def get_document_body(self, text): return self.parser.textile(text) Markups-0.4/markups/markdown.py0000644000175000017500000001172512244065403017525 0ustar dmitrydmitry00000000000000# This file is part of python-markups module # License: BSD # Copyright: (C) Dmitry Shachnev, 2012 from __future__ import absolute_import import os import sys import markups.common as common from markups.abstract import AbstractMarkup MATHJAX_CONFIG = \ ''' ''' class MarkdownMarkup(AbstractMarkup): """Markdown language""" name = 'Markdown' attributes = { common.LANGUAGE_HOME_PAGE: 'http://daringfireball.net/projects/markdown/', common.MODULE_HOME_PAGE: 'https://github.com/Waylan/Python-Markdown/', common.SYNTAX_DOCUMENTATION: 'http://daringfireball.net/projects/markdown/syntax' } file_extensions = ('.md', '.mkd', '.mkdn', '.mdwn', '.mdown', '.markdown') default_extension = '.mkd' @staticmethod def available(): try: import markdown except ImportError: return False return True def _load_extensions_list_from_file(self, filename): try: extensions_file = open(filename) except IOError: return [] else: extensions = [line.rstrip() for line in extensions_file] extensions_file.close() return extensions def _check_extension_exists(self, extension_name): try: __import__('markdown.extensions.'+extension_name, {}, {}, ['markdown.extensions']) except ImportError: try: __import__('mdx_'+extension_name) except ImportError: return False return True def _get_mathjax_patterns(self, markdown): def handle_match_inline(m): node = markdown.util.etree.Element('script') node.set('type', 'math/tex') node.text = markdown.util.AtomicString(m.group(3)) return node def handle_match(m): node = markdown.util.etree.Element('script') node.set('type', 'math/tex; mode=display') node.text = markdown.util.AtomicString(m.group(3)) if '\\begin' in m.group(2): node.text = markdown.util.AtomicString(m.group(2) + m.group(3) + m.group(4)) return node inlinemathpatterns = ( markdown.inlinepatterns.Pattern(r'(?') def get_document_body(self, text): self.md.reset() converted_text = self.md.convert(text) + '\n' if self.enable_cache: self.cache['body'] = converted_text return converted_text Markups-0.4/markups/restructuredtext.py0000644000175000017500000000422112244065403021334 0ustar dmitrydmitry00000000000000# This file is part of python-markups module # License: BSD # Copyright: (C) Dmitry Shachnev, 2012 import markups.common as common from markups.abstract import AbstractMarkup class ReStructuredTextMarkup(AbstractMarkup): """reStructuredText language""" name = 'reStructuredText' attributes = { common.LANGUAGE_HOME_PAGE: 'http://docutils.sourceforge.net/rst.html', common.MODULE_HOME_PAGE: 'http://docutils.sourceforge.net/', common.SYNTAX_DOCUMENTATION: 'http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html' } file_extensions = ('.rst', '.rest') default_extension = '.rst' @staticmethod def available(): try: import docutils.core except ImportError: return False return True def __init__(self, filename=None, settings_overrides=None): self.overrides = settings_overrides or {} self.overrides.update({'math_output': 'MathJax'}) AbstractMarkup.__init__(self, filename) from docutils.core import publish_parts self._publish_parts = publish_parts def publish_parts(self, text): if 'rest_parts' in self.cache: return self.cache['rest_parts'] parts = self._publish_parts(text, source_path=self.filename, writer_name='html', settings_overrides=self.overrides) if self.enable_cache: self.cache['rest_parts'] = parts return parts def get_document_title(self, text): return self.publish_parts(text)['title'] def get_document_body(self, text): return self.publish_parts(text)['body'] def get_stylesheet(self, text=''): origstyle = self.publish_parts(text)['stylesheet'] # Cut off tags stylestart = '')] return stylesheet + common.get_pygments_stylesheet('.code') def get_javascript(self, text='', webenv=False): head = self.publish_parts(text)['head'] start_position = head.find(' some text \$escaped\$

\(escaped)

text

text

text

text

\$$escaped\$$ \[escaped]

''' mathjax_multiline_source = \ r''' $$ \TeX \LaTeX $$ ''' mathjax_multiline_output = \ '''

''' @unittest.skipUnless(MarkdownMarkup.available(), 'Markdown not available') class MarkdownTest(unittest.TestCase): maxDiff = None def test_extensions_loading(self): markup = MarkdownMarkup() self.assertFalse(markup._check_extension_exists('nonexistent')) self.assertTrue(markup._check_extension_exists('meta')) def test_extra(self): markup = MarkdownMarkup() html = markup.get_document_body(tables_source) self.assertEqual(tables_output, html) html = markup.get_document_body(deflists_source) self.assertEqual(deflists_output, html) def test_remove_extra(self): markup = MarkdownMarkup(extensions=['remove_extra']) html = markup.get_document_body(tables_source) self.assertNotEqual(html, tables_output) def test_meta(self): markup = MarkdownMarkup(extensions=['meta']) title = markup.get_document_title('Title: Hello, world!\n\nSome text here.') self.assertEqual('Hello, world!', title) def test_mathjax(self): markup = MarkdownMarkup(extensions=['mathjax']) # Escaping should work self.assertEqual('', markup.get_javascript('Hello, \\$2+2$!')) js = markup.get_javascript(mathjax_source) self.assertIn(' %PAGENAME% %CONTENT%

Generated by %APPINFO% from %MARKUPNAME% source.
Generation time: %TIME%.

Markups-0.4/setup.py0000755000175000017500000000436612244065403015367 0ustar dmitrydmitry00000000000000#!/usr/bin/python import sys from distutils.core import setup, Command from markups import __version__ as version long_description = \ """This module provides a wrapper around the various text markup languages, such as Markdown_ and reStructuredText_ (these two are supported by default). Usage example: >>> markup = markups.get_markup_for_file_name("myfile.rst") >>> markup.name 'reStructuredText' >>> markup.attributes[markups.SYNTAX_DOCUMENTATION] 'http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html' >>> text = "Hello, world!\\n=============\\n\\nThis is an example **reStructuredText** document." >>> markup.get_document_title(text) 'Hello, world!' >>> markup.get_document_body(text) '

This is an example reStructuredText document.

\\n' .. _Markdown: http://daringfireball.net/projects/markdown/ .. _reStructuredText: http://docutils.sourceforge.net/rst.html """ classifiers = ['Development Status :: 4 - Beta', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.0', 'Programming Language :: Python :: 3.1', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Topic :: Text Processing :: Markup', 'Topic :: Text Processing :: General', 'Topic :: Software Development :: Libraries :: Python Modules' ] class run_tests(Command): user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run(self): import tests oldargv, sys.argv = sys.argv, ['setup.py test', '-v'] try: tests.main() except SystemExit as e: if e.code: raise sys.argv = oldargv setup_args = { 'name': 'Markups', 'version': version, 'description': 'A wrapper around various text markups', 'long_description': long_description, 'author': 'Dmitry Shachnev', 'author_email': 'mitya57@gmail.com', 'url': 'http://launchpad.net/python-markups', 'packages': ['markups'], 'license': 'BSD', 'classifiers': classifiers } if sys.version_info[0] >= 3: setup_args['cmdclass'] = {'test': run_tests} setup(**setup_args) Markups-0.4/README0000644000175000017500000000153512022661313014521 0ustar dmitrydmitry00000000000000This module provides a wrapper around the various text markup languages, such as Markdown_ and reStructuredText_ (these two are supported by default). Usage example: >>> markup = markups.get_markup_for_file_name("myfile.rst") >>> markup.name 'reStructuredText' >>> markup.attributes[markups.SYNTAX_DOCUMENTATION] 'http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html' >>> text = "Hello, world!\n=============\n\nThis is an example **reStructuredText** document." >>> markup.get_document_title(text) 'Hello, world!' >>> markup.get_document_body(text) '

This is an example reStructuredText document.

\n' .. _Markdown: http://daringfireball.net/projects/markdown/ .. _reStructuredText: http://docutils.sourceforge.net/rst.html The release version can be downloaded from PyPI_. .. _PyPI: http://pypi.python.org/pypi/Markups Markups-0.4/changelog0000644000175000017500000000205412246327107015520 0ustar dmitrydmitry00000000000000Version 0.4, 2013-11-30 ======================= * Add Textile markup * reStructuredText markup now supports file names and settings overrides * Web module now raises WebUpdateError when updating fails Version 0.3, 2013-07-25 ======================= * MathJax support in Markdown has been improved and no longer relies on tex2jax extension * It is now possible to pass extensions list to MarkdownMarkup constructor * Pygments style is now configurable * Testsuite improvements Version 0.2.3, 2012-11-02 ========================= * Fix support for custom working directory in web module * Bug fixes in Markdown module and tests Version 0.2.2, 2012-10-02 ========================= * Re-written math support for Markdown * Add tests to the tarball * Add example template for web module * Bug fixes in Markdown and web modules Version 0.2.1, 2012-09-09 ========================= * Add caching support, to speed up get_document_body function * Add testsuite * Fix some bugs in markdown module Version 0.2, 2012-09-04 ======================= * Initial release Markups-0.4/LICENSE0000644000175000017500000000273112052336211014644 0ustar dmitrydmitry00000000000000Copyright 2012 Dmitry Shachnev . 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.