Skip to content
This repository has been archived by the owner on Aug 7, 2020. It is now read-only.

Commit

Permalink
Improve warning reports
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Mar 12, 2020
1 parent fb259c1 commit 5ac4d41
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 9 additions & 0 deletions mistletoe/base_elements.py
Expand Up @@ -266,6 +266,15 @@ def from_source_lines(cls, lines: SourceLines, start_line=None) -> "Position":
data=lines.metadata,
)

def make_loc_str(self) -> str:
"""Create a location string ``<uri>:<line_start>:<line_end>``"""
string = "{0}:{1}:{2}".format(
self.uri or "", self.line_start, self.line_end or ""
)
if self.data:
string += " {}".format(self.data)
return string

def __repr__(self):
args = ""
if self.line_end is not None:
Expand Down
9 changes: 5 additions & 4 deletions mistletoe/block_tokens.py
Expand Up @@ -104,8 +104,9 @@ def read(cls, lines: SourceLines):
position = Position.from_source_lines(lines, start_line=start_line)
if log_warning:
get_parse_context().logger.warning(
"No closing `---` was found for initial metadata block: "
"{}".format(position)
"{} No closing `---` was found for initial metadata block".format(
position.make_loc_str()
)
)

return cls(content="".join(line_buffer), position=position)
Expand Down Expand Up @@ -968,8 +969,8 @@ def append_link_definitions(matches, position):
link_definitions[key] = dest, title
else:
get_parse_context().logger.warning(
"ignoring duplicate link definition '{}' at: {}\n".format(
key, position
"{} ignoring duplicate link definition '{}'".format(
position.make_loc_str(), key
)
)

Expand Down
4 changes: 2 additions & 2 deletions mistletoe/block_tokens_ext.py
Expand Up @@ -75,8 +75,8 @@ def read(cls, lines: SourceLines):
get_parse_context().foot_definitions[target] = token
else:
get_parse_context().logger.warning(
"ignoring duplicate footnote definition '{}' at: {}".format(
target, position
"{} ignoring duplicate footnote definition '{}'".format(
position.make_loc_str(), target
)
)
return token
Expand Down

0 comments on commit 5ac4d41

Please sign in to comment.