Skip to content

Commit

Permalink
Stop mangling document titles
Browse files Browse the repository at this point in the history
Fixes #15.
  • Loading branch information
mgedmin committed Apr 28, 2014
1 parent 8906be1 commit 02b3e7c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Changelog
- Show a clear error when external command fails.
Fixes https://github.com/mgedmin/restview/issues/14.

- Stop mangling document titles.
Fixes https://github.com/mgedmin/restview/issues/15.


2.0.3 (2014-02-01)
------------------
Expand Down
17 changes: 7 additions & 10 deletions src/restview/restviewhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,18 @@ def rest_to_html(self, rest_input, settings=None, mtime=None):
docutils.core.publish_string(rest_input, writer=writer,
settings_overrides=settings_overrides)
except Exception as e:
return self.render_exception(e.__class__.__name__, str(e),
rest_input)
return self.get_markup(writer.output, mtime=mtime)
html = self.render_exception(e.__class__.__name__, str(e), rest_input)
else:
html = writer.output
return self.inject_ajax(html, mtime=mtime)

def render_exception(self, title, error, source):
html = (ERROR_TEMPLATE.replace('$title', escape(title))
return (ERROR_TEMPLATE.replace('$title', escape(title))
.replace('$error', escape(error))
.replace('$source', escape(source)))
return self.get_markup(html)

def get_markup(self, markup, mtime=None):
if self.command is not None:
return markup.replace('</title>',
' -e "' + escape(self.command) + '"</title>')
elif mtime is not None:
def inject_ajax(self, markup, mtime=None):
if mtime is not None:
return markup.replace('</body>', (AJAX_STR % mtime) + '</body>')
else:
return markup
Expand Down
38 changes: 6 additions & 32 deletions src/restview/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,11 @@ def doctest_RestViewer_rest_to_html_strict_and_error_handling():
"""


def doctest_RestViewer_get_markup():
"""Test for RestViewer.get_markup
def doctest_RestViewer_inject_ajax():
"""Test for RestViewer.inject_ajax
>>> viewer = RestViewer('.')
>>> print(viewer.get_markup('''
>>> print(viewer.inject_ajax('''
... <html>
... <head>
... <title>Title</title>
Expand All @@ -607,11 +607,11 @@ def doctest_RestViewer_get_markup():
"""


def doctest_RestViewer_get_markup_adds_ajax():
"""Test for RestViewer.get_markup
def doctest_RestViewer_inject_ajax_adds_ajax():
"""Test for RestViewer.inject_ajax
>>> viewer = RestViewer('.')
>>> print(viewer.get_markup('''
>>> print(viewer.inject_ajax('''
... <html>
... <head>
... <title>Title</title>
Expand Down Expand Up @@ -656,32 +656,6 @@ def doctest_RestViewer_get_markup_adds_ajax():
"""


def doctest_RestViewer_get_markup_command_output():
"""Test for RestViewer.get_markup
>>> viewer = RestViewer('.', command='python setup.py --long-description')
>>> print(viewer.get_markup('''
... <html>
... <head>
... <title>restview</title>
... </head>
... <body>
... <p>Some body text</p>
... </body>
... </html>
... ''').strip())
<html>
<head>
<title>restview -e "python setup.py --long-description"</title>
</head>
<body>
<p>Some body text</p>
</body>
</html>
"""


class TestRestViewer(unittest.TestCase):

def test_serve(self):
Expand Down

0 comments on commit 02b3e7c

Please sign in to comment.