Skip to content

Commit

Permalink
Fix mythmon#145: Rendering errs have wrong line nums
Browse files Browse the repository at this point in the history
Prepend page content with X newlines, where X is the number of lines
of YAML metadata.  This is to fix issue mythmon#145: reStructuredText rendering
errors have incorrect line numbers.

Note: cherry-picked from 2cd19ed,
re-creating branch to cleanup my git mess.

Conflicts:
	test_site/content/tests/rest_error.rst
  • Loading branch information
matt-garman committed Dec 14, 2015
1 parent 8924172 commit cc6b1ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions test_site/content/tests/rest_error.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ filename, just "string"
The following will trigger a rst rendering error:
- Should be an extra newline between the
- first bullet point and the preceeding paragraph
<<<<<<< HEAD

End of deliberate error document.
=======
This is line 15 but wok will report line 11 due to four lines of
metadata above.
>>>>>>> 2cd19ed... Prepend page content with X newlines, where X is the number of lines of metadata. This is to fix issue #145: reStructuredText rendering errors have incorrect line numbers

12 changes: 9 additions & 3 deletions wok/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@ def from_file(cls, path, options, engine, renderer=renderers.Plain):
elif len(splits) == 2:
header = splits[0]
page.meta = yaml.load(header)
page.original = splits[1]
# prepend X newlines to original document, where X
# is number of lines of metadata (including "---"
# delimiter). Fix for issue #145: rendering error
# line numbers are incorrect.
newlines = '\n' * (2+header.count('\n'))
page.original = newlines + splits[1]
page.original_preview = page.meta.get('preview', '')

elif len(splits) >= 3:
header = splits[0]
page.meta = {}
page.original = '\n'.join(splits[1:])
page.original_preview = splits[1]
newlines = '\n' * (2+header.count('\n'))
page.original = newlines + '\n'.join(splits[1:])
page.original_preview = newlines + splits[1]
page.meta.update(yaml.load(header))
logging.debug('Got preview')

Expand Down

0 comments on commit cc6b1ca

Please sign in to comment.