Skip to content
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

Fix Markup-returning functions' return type #771

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pdoc/render_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@


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


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


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


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


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