Skip to content

Commit d2e3262

Browse files
authored
Broader handling of glued roles. (#61)
1 parent 4ec2ecb commit d2e3262

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

sphinxlint/checkers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,15 @@ def check_missing_space_after_role(file, lines, options=None):
169169
# While this is not:
170170
# The :literal:`:exc:`Exceptions``s
171171
role_body = rf"([^`]|\s`+|\\`|:{rst.SIMPLENAME}:`([^`]|\s`+|\\`)+`)+"
172-
suspicious_role = re.compile(f":{rst.SIMPLENAME}:`{role_body}`s")
172+
allowed_after_role = (
173+
rst.ASCII_ALLOWED_AFTER_INLINE_MARKUP
174+
+ rst.UNICODE_ALLOWED_AFTER_INLINE_MARKUP
175+
+ r"|\s"
176+
)
177+
178+
suspicious_role = re.compile(
179+
f":{rst.SIMPLENAME}:`{role_body}`[^{allowed_after_role}]"
180+
)
173181
for lno, line in enumerate(lines, start=1):
174182
line = clean_paragraph(line)
175183
role = suspicious_role.search(line)

sphinxlint/rst.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@
145145
ROLE_TAG = rf":{SIMPLENAME}:"
146146
ROLE_HEAD = rf"({BEFORE_ROLE}:{SIMPLENAME}:)" # A role, with a clean start
147147

148-
ASCII_ALLOWED_BEFORE_INLINE_MARKUP = r"""[-:/'"<(\[{]"""
149-
UNICODE_ALLOWED_BEFORE_INLINE_MARKUP = r"[\p{Ps}\p{Pi}\p{Pf}\p{Pd}\p{Po}]"
150-
ASCII_ALLOWED_AFTER_INLINE_MARKUP = r"""[-.,:;!?/'")\]}>]"""
151-
UNICODE_ALLOWED_AFTER_INLINE_MARKUP = r"[\p{Pe}\p{Pi}\p{Pf}\p{Pd}\p{Po}]"
148+
ASCII_ALLOWED_BEFORE_INLINE_MARKUP = r"""-:/'"<(\[{"""
149+
UNICODE_ALLOWED_BEFORE_INLINE_MARKUP = r"\p{Ps}\p{Pi}\p{Pf}\p{Pd}\p{Po}"
150+
ASCII_ALLOWED_AFTER_INLINE_MARKUP = r"""-.,:;!?/'")\]}>"""
151+
UNICODE_ALLOWED_AFTER_INLINE_MARKUP = r"\p{Pe}\p{Pi}\p{Pf}\p{Pd}\p{Po}"
152152

153153

154154
def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
@@ -167,9 +167,9 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
167167
(?<= # Inline markup start-strings must:
168168
^| # start a text block
169169
\s| # or be immediately preceded by whitespace,
170-
{ASCII_ALLOWED_BEFORE_INLINE_MARKUP}| # one of the ASCII characters
171-
{UNICODE_ALLOWED_BEFORE_INLINE_MARKUP} # or a similar non-ASCII
172-
# punctuation character.
170+
[{ASCII_ALLOWED_BEFORE_INLINE_MARKUP}]| # one of the ASCII characters
171+
[{UNICODE_ALLOWED_BEFORE_INLINE_MARKUP}] # or a similar non-ASCII
172+
# punctuation character.
173173
{extra_allowed_before}
174174
)
175175
@@ -181,7 +181,7 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
181181
# character from the start-string.
182182
{QUOTE_PAIRS_NEGATIVE_LOOKBEHIND}
183183
.*?
184-
(?<=\S) # Inline markup end-strings must be immediately preceded
184+
(?<=\x00\ |\S)# Inline markup end-strings must be immediately preceded
185185
# by non-whitespace.
186186
{end_string} # Inline markup end
187187
)
@@ -190,9 +190,9 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
190190
$| # end a text block or
191191
\s| # be immediately followed by whitespace,
192192
\x00|
193-
{ASCII_ALLOWED_AFTER_INLINE_MARKUP}| # one of the ASCII characters
194-
{UNICODE_ALLOWED_AFTER_INLINE_MARKUP} # or a similar non-ASCII
195-
# punctuation character.
193+
[{ASCII_ALLOWED_AFTER_INLINE_MARKUP}]| # one of the ASCII characters
194+
[{UNICODE_ALLOWED_AFTER_INLINE_MARKUP}] # or a similar non-ASCII
195+
# punctuation character.
196196
)
197197
""",
198198
flags=re.VERBOSE | re.DOTALL,
@@ -213,9 +213,9 @@ def inline_markup_gen(start_string, end_string, extra_allowed_before=""):
213213
(?<= # Inline markup start-strings must:
214214
^| # start a text block
215215
\s| # or be immediately preceded by whitespace,
216-
{ASCII_ALLOWED_BEFORE_INLINE_MARKUP}| # one of the ASCII characters
217-
{UNICODE_ALLOWED_BEFORE_INLINE_MARKUP} # or a similar non-ASCII
218-
# punctuation character.
216+
[{ASCII_ALLOWED_BEFORE_INLINE_MARKUP}]| # one of the ASCII characters
217+
[{UNICODE_ALLOWED_BEFORE_INLINE_MARKUP}] # or a similar non-ASCII
218+
# punctuation character.
219219
)
220220
221221
:{SIMPLENAME}:{INTERPRETED_TEXT_RE.pattern}""",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.. expect: role missing (escaped) space
2+
3+
:ref:`"What's new in Python 3.12" <whatsnew-typing-py312>`for more details.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. expect: role missing (escaped) space after role: ':literal:`:manpage:`man(1)``s' (missing-space-after-role)
1+
.. expect: role missing (escaped) space after role: ':literal:`:manpage
22
.. expect: found an unbalanced inline literal markup. (unbalanced-inline-literals-delimiters)
33
44
The :literal:`:manpage:`man(1)``s roles...
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
+-------------------------+-------------------------------+-----------+
2+
| Attribute | Meaning | |
3+
+=========================+===============================+===========+
4+
| :attr:`~object.__dict__`| The namespace supporting | Writable |
5+
| | arbitrary function | |
6+
| | attributes. | |
7+
+-------------------------+-------------------------------+-----------+

0 commit comments

Comments
 (0)