markdown.py
74 lines
| 2.0 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r10676 | """Markdown filters | ||
This file contains a collection of utility filters for dealing with | ||||
markdown within Jinja templates. | ||||
Jonathan Frederic
|
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
|
r10485 | import sys | ||
Jonathan Frederic
|
r10436 | import subprocess | ||
MinRK
|
r11268 | from IPython.nbconvert.utils.pandoc import pandoc | ||
Jonathan Frederic
|
r10436 | #----------------------------------------------------------------------------- | ||
# Functions | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r10485 | |||
Brian E. Granger
|
r11088 | __all__ = [ | ||
MinRK
|
r11268 | 'markdown2html', | ||
Brian E. Granger
|
r11088 | 'markdown2latex', | ||
'markdown2rst' | ||||
] | ||||
Jonathan Frederic
|
r10676 | def markdown2latex(source): | ||
Jonathan Frederic
|
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
|
r10676 | source : string | ||
Jonathan Frederic
|
r10436 | Input string, assumed to be valid markdown. | ||
Returns | ||||
------- | ||||
out : string | ||||
Output as returned by pandoc. | ||||
""" | ||||
MinRK
|
r11268 | return pandoc(source, 'markdown', 'latex') | ||
Jonathan Frederic
|
r10436 | |||
MinRK
|
r11268 | def markdown2html(source): | ||
"""Convert a markdown string to HTML via pandoc""" | ||||
return pandoc(source, 'markdown', 'html') | ||||
Jonathan Frederic
|
r10676 | def markdown2rst(source): | ||
Jonathan Frederic
|
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
|
r10676 | source : string | ||
Jonathan Frederic
|
r10436 | Input string, assumed to be valid markdown. | ||
Returns | ||||
------- | ||||
out : string | ||||
Output as returned by pandoc. | ||||
""" | ||||
MinRK
|
r11268 | return pandoc(source, 'markdown', 'rst') | ||