##// END OF EJS Templates
Merge pull request #3514 from minrk/ui-state-disabled...
Merge pull request #3514 from minrk/ui-state-disabled use bootstrap `disabled` instead of `ui-state-disabled`

File last commit:

r11088:a50cba11
r11138:0ab1d3d4 merge
Show More
markdown.py
85 lines | 2.4 KiB | text/x-python | PythonLexer
Jonathan Frederic
Cleanup and refactor of filters
r10676 """Markdown filters
This file contains a collection of utility filters for dealing with
markdown within Jinja templates.
Jonathan Frederic
Transformer refactor
r10436 """
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
# Stdlib imports
Jonathan Frederic
Post code-review, extended refactor.
r10485 import sys
Jonathan Frederic
Transformer refactor
r10436 import subprocess
#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
Jonathan Frederic
Post code-review, extended refactor.
r10485
Brian E. Granger
Fixing import logic.
r11088 __all__ = [
'markdown2latex',
'markdown2rst'
]
Jonathan Frederic
Cleanup and refactor of filters
r10676 def markdown2latex(source):
Jonathan Frederic
Transformer refactor
r10436 """Convert a markdown string to LaTeX via pandoc.
This function will raise an error if pandoc is not installed.
Any error messages generated by pandoc are printed to stderr.
Parameters
----------
Jonathan Frederic
Cleanup and refactor of filters
r10676 source : string
Jonathan Frederic
Transformer refactor
r10436 Input string, assumed to be valid markdown.
Returns
-------
out : string
Output as returned by pandoc.
"""
p = subprocess.Popen('pandoc -f markdown -t latex'.split(),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
Jonathan Frederic
Cleanup and refactor of filters
r10676
out, err = p.communicate(source.encode('utf-8'))
Jonathan Frederic
Transformer refactor
r10436 if err:
print(err, file=sys.stderr)
#print('*'*20+'\n', out, '\n'+'*'*20) # dbg
Jonathan Frederic
Cleanup and refactor of filters
r10676
Bussonnier Matthias
fix overescaped underscores
r10881 return unicode(out, 'utf-8')[:-1]
Jonathan Frederic
Transformer refactor
r10436
Jonathan Frederic
Cleanup and refactor of filters
r10676 def markdown2rst(source):
Jonathan Frederic
Transformer refactor
r10436 """Convert a markdown string to LaTeX via pandoc.
This function will raise an error if pandoc is not installed.
Any error messages generated by pandoc are printed to stderr.
Parameters
----------
Jonathan Frederic
Cleanup and refactor of filters
r10676 source : string
Jonathan Frederic
Transformer refactor
r10436 Input string, assumed to be valid markdown.
Returns
-------
out : string
Output as returned by pandoc.
"""
p = subprocess.Popen('pandoc -f markdown -t rst'.split(),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
Jonathan Frederic
Cleanup and refactor of filters
r10676
out, err = p.communicate(source.encode('utf-8'))
Jonathan Frederic
Transformer refactor
r10436 if err:
print(err, file=sys.stderr)
#print('*'*20+'\n', out, '\n'+'*'*20) # dbg
Jonathan Frederic
Cleanup and refactor of filters
r10676
return unicode(out, 'utf-8')