##// END OF EJS Templates
add Ctrl-M keyboard shortcut
add Ctrl-M keyboard shortcut

File last commit:

r11294:1316de0d
r13296:cdbacdcf
Show More
markdown.py
74 lines | 2.0 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
MinRK
add markdown2html filter...
r11268 from IPython.nbconvert.utils.pandoc import pandoc
Jonathan Frederic
Transformer refactor
r10436 #-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
Jonathan Frederic
Post code-review, extended refactor.
r10485
Brian E. Granger
Fixing import logic.
r11088 __all__ = [
MinRK
add markdown2html filter...
r11268 'markdown2html',
Brian E. Granger
Fixing import logic.
r11088 '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.
"""
MinRK
add markdown2html filter...
r11268 return pandoc(source, 'markdown', 'latex')
Jonathan Frederic
Transformer refactor
r10436
MinRK
add markdown2html filter...
r11268 def markdown2html(source):
"""Convert a markdown string to HTML via pandoc"""
MinRK
use mathjax-style for math passing through pandoc to html
r11294 return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])
MinRK
add markdown2html filter...
r11268
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.
"""
MinRK
add markdown2html filter...
r11268 return pandoc(source, 'markdown', 'rst')