-
-
Notifications
You must be signed in to change notification settings - Fork 143
Leave trailing line break in reST directives #385
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clunky indeed, but unless we have a way to fix the regex:
Lines 325 to 328 in 4aa70de
substitute = partial(re.compile(r'^(?P<indent> *)\.\. ?(\w+)::(?: *(.*))?' | |
r'((?:\n(?:(?P=indent) +.*| *$))*)', re.MULTILINE).sub, | |
partial(_ToMarkdown._admonition, module=module, | |
limit_types=limit_types)) |
I don't have a really better idea.
As suggested by kernc. Co-authored-by: kernc <[email protected]>
Another possibly way of neatening this up would be to somehow detect the context of where the reST directive is (i.e whether or not it's within a code block) and only add the trailing new-line where appropriate. This context could be detected in, or outside of and passed in, to |
Another way would be to actually amend the culprit regex. It's posed as: ^(?P<indent> *)\.\. ?(\w+)::(?: *(.*))?
((?:\n(?:(?P=indent) +.*| *$))*) for its second line to matche any indented paragraphs (separated with a line break). E.g.: Outside admonition.
.. warning:: Title
First paragraph.
Second paragraph. # Our regex matches this final line break. But if it didn't ...
Outside admonition. As can be seen here (trailing I think we could rewrite the regex to not consume the line break unless another indented paragraph follows it ... 🤔 |
Not quite fully isolated to just changing the regex, but I think that's the closest you'll get (though I'm by no means an expert when it comes to regex!). Let me know what you think - if you're happy with that then I'll squash the redundant commits and let you merge :) |
Excellent find of the regex! Many thanks! 🍰 |
* Add to `pdoc.test.Docformats.test_reST_include` to catch issue. * Add a single line-break at the end of `.. include::`ed files - except for when in a code block. * Minor change comment * Revert last 2 commits. * Don't consume trailing newline from reST directives. * [] itself a disjunctive list of characters
* Add to `pdoc.test.Docformats.test_reST_include` to catch issue. * Add a single line-break at the end of `.. include::`ed files - except for when in a code block. * Minor change comment * Revert last 2 commits. * Don't consume trailing newline from reST directives. * [] itself a disjunctive list of characters
Closes #384.
Feels a little clunky adding a trailing line break when processing reST directives, to then have to remove it again for reST directives in code blocks, but I couldn't see any other way. Figured I'd submit a PR anyway for feedback and go from there.