Show More
@@ -23,7 +23,7 from io import TextIOWrapper, BytesIO | |||||
23 | # IPython imports |
|
23 | # IPython imports | |
24 | from IPython.nbconvert.utils.pandoc import pandoc |
|
24 | from IPython.nbconvert.utils.pandoc import pandoc | |
25 | from IPython.nbconvert.utils.exceptions import ConversionException |
|
25 | from IPython.nbconvert.utils.exceptions import ConversionException | |
26 | from IPython.utils.process import find_cmd, FindCmdError |
|
26 | from IPython.utils.process import find_cmd, FindCmdError, getoutput | |
27 | from IPython.utils.py3compat import cast_bytes |
|
27 | from IPython.utils.py3compat import cast_bytes | |
28 |
|
28 | |||
29 | #----------------------------------------------------------------------------- |
|
29 | #----------------------------------------------------------------------------- | |
@@ -99,18 +99,39 def markdown2rst(source): | |||||
99 | """ |
|
99 | """ | |
100 | return pandoc(source, 'markdown', 'rst') |
|
100 | return pandoc(source, 'markdown', 'rst') | |
101 |
|
101 | |||
102 | # prefer md2html via marked if node.js is available |
|
102 | def _verify_node(cmd): | |
103 | # node is called nodejs on debian, so try that first |
|
103 | """Verify that the node command exists and is atleast the minimum supported | |
104 | node_cmd = 'nodejs' |
|
104 | version of node. | |
105 | try: |
|
105 | ||
106 | find_cmd(node_cmd) |
|
106 | Parameters | |
107 | except FindCmdError: |
|
107 | ---------- | |
108 | node_cmd = 'node' |
|
108 | cmd : string | |
|
109 | Node command to verify (i.e 'node').""" | |||
109 | try: |
|
110 | try: | |
110 | find_cmd(node_cmd) |
|
111 | find_cmd(node_cmd) | |
111 | except FindCmdError: |
|
112 | except FindCmdError: | |
112 | markdown2html = markdown2html_pandoc |
|
113 | return False | |
113 | else: |
|
114 | else: | |
114 | markdown2html = markdown2html_marked |
|
115 | # Remove the version 'v' prefix from the output and strip whitespace. | |
115 | else: |
|
116 | version_str = getoutput(cmd + ' --version').replace('v', '').strip() | |
|
117 | try: | |||
|
118 | # Make sure the node version is atleast 0.9.12 | |||
|
119 | version_numbers = [int(x) for x in version_str.split('.')] | |||
|
120 | if version_numbers[0] > 0 or version_numbers[1] > 9 or (version_numbers[1] == 9 and version_numbers[2] >= 12): | |||
|
121 | return True | |||
|
122 | else: | |||
|
123 | return False | |||
|
124 | except: | |||
|
125 | return False | |||
|
126 | ||||
|
127 | # prefer md2html via marked if node.js is available | |||
|
128 | # node is called nodejs on debian, so try that first | |||
|
129 | node_cmd = 'nodejs' | |||
|
130 | if _verify_node(node_cmd): | |||
116 | markdown2html = markdown2html_marked |
|
131 | markdown2html = markdown2html_marked | |
|
132 | else: | |||
|
133 | node_cmd = 'node' | |||
|
134 | if _verify_node(node_cmd): | |||
|
135 | markdown2html = markdown2html_marked | |||
|
136 | else: | |||
|
137 | markdown2html = markdown2html_pandoc |
General Comments 0
You need to be logged in to leave comments.
Login now