##// END OF EJS Templates
Merge pull request #3732 from minrk/slow-save-on-close...
Merge pull request #3732 from minrk/slow-save-on-close add delay to autosave in beforeunload allows forceful 'discard changes' by reloading the page and dismissing the warning. The timer doesn't start until after the dialog is dismissed, so if you decide to nav away without saving changes, the changes will actually not be saved.

File last commit:

r11626:66d4c053
r11690:bd4cc056 merge
Show More
pandoc.py
60 lines | 2.0 KiB | text/x-python | PythonLexer
"""Utility for calling pandoc"""
#-----------------------------------------------------------------------------
# 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
import sys
import subprocess
# IPython imports
from IPython.utils.py3compat import cast_bytes
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):
"""Convert an input string in format `from` to format `to` via pandoc.
This function will raise an error if pandoc is not installed.
Any error messages generated by pandoc are printed to stderr.
Parameters
----------
source : string
Input string, assumed to be valid format `from`.
fmt : string
The name of the input format (markdown, etc.)
to : string
The name of the output format (html, etc.)
Returns
-------
out : unicode
Output as returned by pandoc.
"""
command = ['pandoc', '-f', fmt, '-t', to]
if extra_args:
command.extend(extra_args)
try:
p = subprocess.Popen(command,
stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
except OSError:
sys.exit("ERROR: Unable to launch pandoc. Please install pandoc:\n"
"(http://johnmacfarlane.net/pandoc/installing.html)")
out, _ = p.communicate(cast_bytes(source, encoding))
out = out.decode(encoding, 'replace')
return out[:-1]