##// END OF EJS Templates
add markdown2html filter...
MinRK -
Show More
@@ -24,7 +24,6 b' from copy import deepcopy'
24 24
25 25 # other libs/dependencies
26 26 from jinja2 import Environment, FileSystemLoader
27 from markdown import markdown
28 27
29 28 # IPython imports
30 29 from IPython.config.configurable import Configurable
@@ -45,7 +44,7 b" JINJA_EXTENSIONS = ['jinja2.ext.loopcontrols']"
45 44
46 45 default_filters = {
47 46 'indent': indent,
48 'markdown': markdown,
47 'markdown': filters.markdown2html,
49 48 'ansi2html': filters.ansi2html,
50 49 'filter_data_type': filters.DataTypeFilter,
51 50 'get_lines': filters.get_lines,
@@ -19,16 +19,18 b' from __future__ import print_function'
19 19 import sys
20 20 import subprocess
21 21
22 from IPython.nbconvert.utils.pandoc import pandoc
23
22 24 #-----------------------------------------------------------------------------
23 25 # Functions
24 26 #-----------------------------------------------------------------------------
25 27
26 28 __all__ = [
29 'markdown2html',
27 30 'markdown2latex',
28 31 'markdown2rst'
29 32 ]
30 33
31
32 34 def markdown2latex(source):
33 35 """Convert a markdown string to LaTeX via pandoc.
34 36
@@ -45,17 +47,12 b' def markdown2latex(source):'
45 47 out : string
46 48 Output as returned by pandoc.
47 49 """
48 p = subprocess.Popen('pandoc -f markdown -t latex'.split(),
49 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
50
51 out, err = p.communicate(source.encode('utf-8'))
50 return pandoc(source, 'markdown', 'latex')
52 51
53 if err:
54 print(err, file=sys.stderr)
55 #print('*'*20+'\n', out, '\n'+'*'*20) # dbg
56
57 return unicode(out, 'utf-8')[:-1]
58 52
53 def markdown2html(source):
54 """Convert a markdown string to HTML via pandoc"""
55 return pandoc(source, 'markdown', 'html')
59 56
60 57 def markdown2rst(source):
61 58 """Convert a markdown string to LaTeX via pandoc.
@@ -73,13 +70,5 b' def markdown2rst(source):'
73 70 out : string
74 71 Output as returned by pandoc.
75 72 """
76 p = subprocess.Popen('pandoc -f markdown -t rst'.split(),
77 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
78
79 out, err = p.communicate(source.encode('utf-8'))
80
81 if err:
82 print(err, file=sys.stderr)
83 #print('*'*20+'\n', out, '\n'+'*'*20) # dbg
73 return pandoc(source, 'markdown', 'rst')
84 74
85 return unicode(out, 'utf-8')
General Comments 0
You need to be logged in to leave comments. Login now