Skip to content

Commit 143d0a8

Browse files
authored
Fix Markup-returning functions' return type (#771)
Markup is a sub-class of string, so this wasn't strictly *wrong*, but it's more correct this way and clearer when extending these filters.
1 parent 001b166 commit 143d0a8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pdoc/render_helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100

101101
@cache
102-
def highlight(doc: pdoc.doc.Doc) -> str:
102+
def highlight(doc: pdoc.doc.Doc) -> Markup:
103103
"""Highlight the source code of a documentation object using pygments."""
104104
if isinstance(doc, str): # pragma: no cover
105105
warnings.warn(
@@ -114,7 +114,7 @@ def highlight(doc: pdoc.doc.Doc) -> str:
114114
return Markup(pygments.highlight(doc.source, lexer, formatter))
115115

116116

117-
def format_signature(sig: inspect.Signature, colon: bool) -> str:
117+
def format_signature(sig: inspect.Signature, colon: bool) -> Markup:
118118
"""Format and highlight a function signature using pygments. Returns HTML."""
119119
# First get a list with all params as strings.
120120
result = pdoc.doc._PrettySignature._params(sig) # type: ignore
@@ -308,7 +308,7 @@ def module_candidates(identifier: str, current_module: str) -> Iterable[str]:
308308
@pass_context
309309
def linkify(
310310
context: Context, code: str, namespace: str = "", shorten: bool = True
311-
) -> str:
311+
) -> Markup:
312312
"""
313313
Link all identifiers in a block of text. Identifiers referencing unknown modules or modules that
314314
are not rendered at the moment will be ignored.
@@ -436,7 +436,7 @@ def linkify_repl(m: re.Match):
436436

437437

438438
@pass_context
439-
def link(context: Context, spec: tuple[str, str], text: str | None = None) -> str:
439+
def link(context: Context, spec: tuple[str, str], text: str | None = None) -> Markup:
440440
"""Create a link for a specific `(modulename, qualname)` tuple."""
441441
mod: pdoc.doc.Module = context["module"]
442442
modulename, qualname = spec
@@ -469,7 +469,7 @@ def link(context: Context, spec: tuple[str, str], text: str | None = None) -> st
469469
return Markup(
470470
f'<a href="{relative_link(context["module"].modulename, modulename)}{qualname}">{text or fullname}</a>'
471471
)
472-
return text or fullname
472+
return Markup.escape(text or fullname)
473473

474474

475475
def edit_url(
@@ -507,7 +507,7 @@ def root_module_name(all_modules: Mapping[str, pdoc.doc.Module]) -> str | None:
507507
return None
508508

509509

510-
def minify_css(css: str) -> str:
510+
def minify_css(css: str) -> Markup:
511511
"""Do some very basic CSS minification."""
512512
css = re.sub(r"[ ]{4}|\n|(?<=[:{}]) | (?=[{}])", "", css)
513513
css = re.sub(

0 commit comments

Comments
 (0)