From cc6b1ca60ba2a3e1ef609a9ae0812a13ddc1f054 Mon Sep 17 00:00:00 2001 From: matt-garman Date: Mon, 7 Dec 2015 17:10:02 -0600 Subject: [PATCH] Fix #145: Rendering errs have wrong line nums Prepend page content with X newlines, where X is the number of lines of YAML metadata. This is to fix issue #145: reStructuredText rendering errors have incorrect line numbers. Note: cherry-picked from 2cd19ed2a5a7295eb7a249dfd8e3094b33bcffa4, re-creating branch to cleanup my git mess. Conflicts: test_site/content/tests/rest_error.rst --- test_site/content/tests/rest_error.rst | 5 +++++ wok/page.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test_site/content/tests/rest_error.rst b/test_site/content/tests/rest_error.rst index 125d332..c7163ab 100644 --- a/test_site/content/tests/rest_error.rst +++ b/test_site/content/tests/rest_error.rst @@ -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 diff --git a/wok/page.py b/wok/page.py index d2bc930..85f1299 100644 --- a/wok/page.py +++ b/wok/page.py @@ -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')