Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use TextIOWrapper when communicating with pandoc subprocess #4205

Merged
merged 3 commits into from Sep 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions IPython/nbconvert/tests/files/notebook2.ipynb
Expand Up @@ -123,6 +123,14 @@
],
"prompt_number": 10
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Here is a very long heading that pandoc will wrap and wrap and wrap and wrap and wrap and wrap and wrap and wrap and wrap and wrap and wrap and wrap"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
15 changes: 14 additions & 1 deletion IPython/nbconvert/tests/test_nbconvertapp.py
Expand Up @@ -103,6 +103,20 @@ def test_post_processor(self):
assert os.path.isfile('notebook1.tex')
assert os.path.isfile('notebook1.pdf')

@dec.onlyif_cmds_exist('pandoc')
def test_spurious_cr(self):
"""Check for extra CR characters"""
with self.create_temp_cwd(['notebook2.ipynb']):
self.call('nbconvert --log-level 0 --to latex notebook2')
assert os.path.isfile('notebook2.tex')
with open('notebook2.tex') as f:
tex = f.read()
self.call('nbconvert --log-level 0 --to html notebook2')
assert os.path.isfile('notebook2.html')
with open('notebook2.html') as f:
html = f.read()
self.assertEqual(tex.count('\r'), tex.count('\r\n'))
self.assertEqual(html.count('\r'), html.count('\r\n'))

@dec.onlyif_cmds_exist('pandoc')
def test_png_base64_html_ok(self):
Expand All @@ -114,7 +128,6 @@ def test_png_base64_html_ok(self):
with open('notebook2.html') as f:
assert "data:image/png;base64,b'" not in f.read()


@dec.onlyif_cmds_exist('pandoc')
def test_template(self):
"""
Expand Down
5 changes: 3 additions & 2 deletions IPython/nbconvert/utils/pandoc.py
Expand Up @@ -15,6 +15,7 @@

# Stdlib imports
import subprocess
from io import TextIOWrapper, BytesIO

# IPython imports
from IPython.utils.py3compat import cast_bytes
Expand Down Expand Up @@ -64,6 +65,6 @@ def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):
"http://johnmacfarlane.net/pandoc/installing.html"
)
out, _ = p.communicate(cast_bytes(source, encoding))
out = out.decode(encoding, 'replace')
return out[:-1]
out = TextIOWrapper(BytesIO(out), encoding, 'replace').read()
return out.rstrip('\n')