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