Skip to content

Commit

Permalink
fix broken signature line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Jun 8, 2022
1 parent e1354fd commit a34e22c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

# Unreleased: pdoc next


- Extend auto-linking of URLs in Markdown.
([#401](https://github.com/mitmproxy/pdoc/issues/401), [@mhils](https://github.com/mhils))
- Mention which implementation of Markdown is supported, with what extras enabled
([#403](https://github.com/mitmproxy/pdoc/issues/403), [@f3ndot](https://github.com/f3ndot))
- Fix a bug where function signatures had weird line breaks.
([#404](https://github.com/mitmproxy/pdoc/issues/404), [@mhils](https://github.com/mhils))
- Exclude line numbers from text selection.
([#405](https://github.com/mitmproxy/pdoc/issues/405), [@mhils](https://github.com/mhils))

Expand Down
16 changes: 8 additions & 8 deletions pdoc/render_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ def linkify(context: Context, code: str, namespace: str = "") -> str:

def linkify_repl(m: re.Match):
text = m.group(0)
identifier = removesuffix(text, "()")
identifier = identifier.replace(
plain_text = text.replace(
'</span><span class="o">.</span><span class="n">', "."
)
identifier = removesuffix(plain_text, "()")

# Check if this is a local reference within this module?
mod: pdoc.doc.Module = context["module"]
for qualname in qualname_candidates(identifier, namespace):
doc = mod.get(qualname)
if doc and context["is_public"](doc).strip():
return f'<a href="#{qualname}">{text}</a>'
return f'<a href="#{qualname}">{plain_text}</a>'

module = ""
qualname = ""
Expand All @@ -300,11 +300,11 @@ def linkify_repl(m: re.Match):
and doc.taken_from == (module, qualname)
and context["is_public"](doc).strip()
):
if text.endswith("()"):
text = f"{doc.fullname}()"
if plain_text.endswith("()"):
plain_text = f"{doc.fullname}()"
else:
text = doc.fullname
return f'<a href="#{qualname}">{text}</a>'
plain_text = doc.fullname
return f'<a href="#{qualname}">{plain_text}</a>'
except ValueError:
# possible_sources did not find a parent module.
return text
Expand All @@ -320,7 +320,7 @@ def linkify_repl(m: re.Match):
if target_exists_and_public:
if qualname:
qualname = f"#{qualname}"
return f'<a href="{relative_link(context["module"].modulename, module)}{qualname}">{text}</a>'
return f'<a href="{relative_link(context["module"].modulename, module)}{qualname}">{plain_text}</a>'
else:
return text

Expand Down
4 changes: 2 additions & 2 deletions test/testdata/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,13 @@ <h1 class="modulename">

<div class="docstring"><p>You can either do</p>

<div class="pdoc-code codehilite"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n"><a href="#ClassmethodLink.bar">ClassmethodLink</span><span class="o">.</span><span class="n">bar</a></span><span class="p">()</span>
<div class="pdoc-code codehilite"><pre><span></span><code><span class="gp">&gt;&gt;&gt; </span><span class="n"><a href="#ClassmethodLink.bar">ClassmethodLink.bar</a></span><span class="p">()</span>
<span class="go">42</span>
</code></pre></div>

<p>or</p>

<div class="pdoc-code codehilite"><pre><span></span><code><span class="n"><a href="#ClassmethodLink.bar">ClassmethodLink</span><span class="o">.</span><span class="n">bar</a></span><span class="p">()</span>
<div class="pdoc-code codehilite"><pre><span></span><code><span class="n"><a href="#ClassmethodLink.bar">ClassmethodLink.bar</a></span><span class="p">()</span>
</code></pre></div>

<p>neither will be linked.</p>
Expand Down

0 comments on commit a34e22c

Please sign in to comment.