Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
refactor: Improve XML parsing error handling
- Loading branch information
Showing
with
13 additions
and
7 deletions.
-
+13
−7
src/mkdocstrings/extension.py
|
|
@@ -254,19 +254,25 @@ def log_xml_parse_error(error: str, xml_text: str) -> None: |
|
|
xml_text: The XML text that generated the parsing error. |
|
|
""" |
|
|
message = error |
|
|
if "mismatched tag" in error: |
|
|
mismatched_tag = "mismatched tag" in error |
|
|
undefined_entity = "undefined entity" in error |
|
|
|
|
|
if mismatched_tag or undefined_entity: |
|
|
line_column = error[error.rfind(":") + 1 :] |
|
|
line, column = line_column.split(", ") |
|
|
lineno = int(line[line.rfind(" ") + 1 :]) |
|
|
columnno = int(column[column.rfind(" ") + 1 :]) |
|
|
|
|
|
line = xml_text.split("\n")[lineno - 1] |
|
|
character = line[columnno] |
|
|
message += ( |
|
|
f" (character {character}):\n{line}\n" |
|
|
"If your Markdown contains angle brackets < >, try to wrap them between backticks `< >`, " |
|
|
"or replace them with < and >" |
|
|
) |
|
|
if mismatched_tag: |
|
|
character = line[columnno] |
|
|
message += ( |
|
|
f" (character {character}):\n{line}\n" |
|
|
"If your Markdown contains angle brackets < >, try to wrap them between backticks `< >`, " |
|
|
"or replace them with < and >" |
|
|
) |
|
|
elif undefined_entity: |
|
|
message += f":\n{line}\n" |
|
|
log.error(message) |
|
|
|
|
|
|
|
|
|