##// END OF EJS Templates
Added overflow-y to the slides.
Added overflow-y to the slides.

File last commit:

r10881:83e7c718
r10949:0281961d
Show More
markdown.py
79 lines | 2.3 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
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')