Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: skip over unknown directives #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 16 additions & 1 deletion rstfmt/rstfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,25 @@ class IgnoreMessagesReporter(docutils.utils.Reporter):
"Title overline too short.",
"Title underline too short.",
}
ignored_messages_regex = (
r'No directive entry for "([\w|\-|:]+)"|'
r'Unknown directive type "([\w|\-|:]+)"|'
r'No role entry for "([\w|\-|:]+)"|'
r'Unknown interpreted text role "([\w|\-|:]+)"'
)

def system_message(
self, level: int, message: str, *children: Any, **kwargs: Any
) -> docutils.nodes.system_message:
orig_level = self.halt_level # type: ignore
if message in self.ignored_messages:
res = re.search(self.ignored_messages_regex, message)

# TODO: Add support for sphinx directives after fix
# https://github.com/twolfson/restructuredtext-lint/issues/29
if res or message in self.ignored_messages:
self.halt_level = docutils.utils.Reporter.SEVERE_LEVEL + 1
else:
print(message)
msg = super().system_message(level, message, *children, **kwargs)
self.halt_level = orig_level
return msg
Expand Down Expand Up @@ -724,7 +736,10 @@ def fmt(node: docutils.nodes.Node, ctx: FormatContext) -> Iterator[str]:
try:
func = getattr(Formatters, type(node).__name__)
except AttributeError:
if type(node) == docutils.nodes.problematic:
return [inline_markup(node.rawsource),]
raise ValueError(f"Unknown node type {type(node).__name__}!")

return func(node, ctx) # type: ignore


Expand Down