Skip to content

Commit

Permalink
refactor: Allow first name in a separate signature to be highlighted …
Browse files Browse the repository at this point in the history
…as a function name
  • Loading branch information
pawamoy committed Mar 24, 2024
1 parent d62daa7 commit f798a1e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/mkdocstrings_handlers/python/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ def do_format_signature(
),
)

# Since we highlight the signature without `def`,
# Pygments sees it as a function call and not a function definition.
# The result is that the function name is not parsed as such,
# but instead as a regular name: `n` CSS class instead of `nf`.
# To fix it, we replace the first occurrence of an `n` CSS class
# with an `nf` one, unless we found `nf` already.
if signature.find('class="nf"') == -1:
signature = signature.replace('class="n"', 'class="nf"', 1)

if stash:
for key, value in stash.items():
signature = re.sub(rf"\b{key}\b", value, signature)
Expand Down

0 comments on commit f798a1e

Please sign in to comment.