Skip to content

Commit

Permalink
Add file name to shortcode errors
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Dec 28, 2015
1 parent cb86619 commit e2b09e9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nikola/nikola.py
Expand Up @@ -1316,9 +1316,9 @@ def register_shortcode(self, name, f):
return
self.shortcode_registry[name] = f

def apply_shortcodes(self, data):
def apply_shortcodes(self, data, filename=None):
"""Apply shortcodes from the registry on data."""
return shortcodes.apply_shortcodes(data, self.shortcode_registry)
return shortcodes.apply_shortcodes(data, self.shortcode_registry, self, filename)

def generic_rss_renderer(self, lang, title, link, description, timeline, output_path,
rss_teasers, rss_plain, feed_length=10, feed_url=None,
Expand Down
2 changes: 1 addition & 1 deletion nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -76,7 +76,7 @@ def compile_html(self, source, dest, is_two_file=True):
if not is_two_file:
_, data = self.split_metadata(data)
output = markdown(data, self.extensions)
output = apply_shortcodes(output, self.site.shortcode_registry, self.site)
output = apply_shortcodes(output, self.site.shortcode_registry, self.site, source)
out_file.write(output)

def create_post(self, path, **kw):
Expand Down
4 changes: 2 additions & 2 deletions nikola/shortcodes.py
Expand Up @@ -245,7 +245,7 @@ def _split_shortcodes(data):
return result


def apply_shortcodes(data, registry, site=None):
def apply_shortcodes(data, registry, site=None, filename=None):
"""Apply Hugo-style shortcodes on data.
{{% name parameters %}} will end up calling the registered "name" function with the given parameters.
Expand Down Expand Up @@ -303,5 +303,5 @@ def apply_shortcodes(data, registry, site=None):
result.append(res)
return empty_string.join(result)
except ParsingError as e:
LOGGER.error("{0}".format(e))
LOGGER.error("Shortcode error in file {0}: {1}".format(filename, e))

This comment has been minimized.

Copy link
@felixfontein

felixfontein Dec 28, 2015

Contributor

How about also making sure the error message sounds good when filename is None? After all, filename is optional.

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Dec 28, 2015

Author Member

Fixed in f8cccda. (note that filename is likely not to be empty in most cases)

sys.exit(1)

0 comments on commit e2b09e9

Please sign in to comment.