##// END OF EJS Templates
Summary of changes:...
Summary of changes: 1) IPython/core/compilerop.py: IronPython __future__ flags are non-standard, Solution try/except; comment added 2) IPython/core/completer.py: __main__ was undefined, due to local mistake in creating IronPython scope; removed this tweak 3) IPython/core/prompts.py: os.getuid() is not defined (IronPython bug; see: https://mail.python.org/pipermail/ironpython-users/2014-February/016812.html) 4) IPython/lib/inputhook.py: ctypes SystemError; comment added 5) IPython/utils/process.py and IPython/utils/_process_cli.py: adds a new _process_cli.py which would handle the processes under cli; fixed os.pathsep 6) IPython/utils/io.py: devnull opened in append mode; changed to "w" 7) New issue: IPython/external/decorator/_decorator.py: IronPython doesn't have _getframes, unless FullFrames is set to true; comment added

File last commit:

r14206:7a0e96e3
r15208:301956c6
Show More
markdown.py
107 lines | 3.2 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
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 import os
Jonathan Frederic
Transformer refactor
r10436 import subprocess
MinRK
prefer marked to pandoc for markdown2html...
r14203 from io import TextIOWrapper, BytesIO
Jonathan Frederic
Transformer refactor
r10436
MinRK
prefer marked to pandoc for markdown2html...
r14203 # IPython imports
MinRK
add markdown2html filter...
r11268 from IPython.nbconvert.utils.pandoc import pandoc
MinRK
prefer marked to pandoc for markdown2html...
r14203 from IPython.nbconvert.utils.exceptions import ConversionException
from IPython.utils.process import find_cmd, FindCmdError
from IPython.utils.py3compat import cast_bytes
MinRK
add markdown2html filter...
r11268
Jonathan Frederic
Transformer refactor
r10436 #-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 marked = os.path.join(os.path.dirname(__file__), "marked.js")
Jonathan Frederic
Post code-review, extended refactor.
r10485
Brian E. Granger
Fixing import logic.
r11088 __all__ = [
MinRK
add markdown2html filter...
r11268 'markdown2html',
MinRK
prefer marked to pandoc for markdown2html...
r14203 'markdown2html_pandoc',
'markdown2html_marked',
Brian E. Granger
Fixing import logic.
r11088 'markdown2latex',
MinRK
prefer marked to pandoc for markdown2html...
r14203 'markdown2rst',
Brian E. Granger
Fixing import logic.
r11088 ]
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 class NodeJSMissing(ConversionException):
"""Exception raised when node.js is missing."""
MinRK
prefer marked to pandoc for markdown2html...
r14203 pass
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
prefer marked to pandoc for markdown2html...
r14203 def markdown2html_pandoc(source):
MinRK
add markdown2html filter...
r11268 """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
MinRK
prefer marked to pandoc for markdown2html...
r14203 def markdown2html_marked(source, encoding='utf-8'):
"""Convert a markdown string to HTML via marked"""
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 command = ['node', marked]
MinRK
prefer marked to pandoc for markdown2html...
r14203 try:
p = subprocess.Popen(command,
stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
except OSError as e:
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 raise NodeJSMissing(
MinRK
prefer marked to pandoc for markdown2html...
r14203 "The command '%s' returned an error: %s.\n" % (" ".join(command), e) +
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 "Please check that Node.js is installed."
MinRK
prefer marked to pandoc for markdown2html...
r14203 )
out, _ = p.communicate(cast_bytes(source, encoding))
out = TextIOWrapper(BytesIO(out), encoding, 'replace').read()
return out.rstrip('\n')
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')
MinRK
prefer marked to pandoc for markdown2html...
r14203 try:
MinRK
add marked.js entry point for md2html in nbconvert...
r14206 find_cmd('node')
MinRK
prefer marked to pandoc for markdown2html...
r14203 except FindCmdError:
markdown2html = markdown2html_pandoc
else:
markdown2html = markdown2html_marked