Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Attempt to fix issue #145 - Rendering error line number offsets #149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test_site/content/tests/rest_error.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: reStructuredText Test Page with Deliberate Error
category: tests
tags: [rest, sample]
---

reStructuredText Page with Deliberate Error
===========================================

For issue #144: reStructuredText rendering errors don't show
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
This is line 15 but wok will report line 11 due to four lines of
metadata above.

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