Skip to content

Fix .md export losing method names, signatures and section labels - #810

Merged
mishig25 merged 1 commit into
mainfrom
fix-md-export-docstring-props
Jul 31, 2026
Merged

Fix .md export losing method names, signatures and section labels#810
mishig25 merged 1 commit into
mainfrom
fix-md-export-docstring-props

Conversation

@mishig25

Copy link
Copy Markdown
Contributor

Problem

The .md (llms / plain-text) twin of every [[autodoc]] class page lost all of its method headings. E.g. hf_api.md has zero #### headings: the docstring bodies are there, but names, anchors and signatures are gone, and **Parameters:** / **Returns:** are missing, so the return type gets glued onto the last parameter line:

To disable authentication, pass `False`.[DiscussionStatusChange](…)the status change event

Cause

strip_html_from_markdown matched the legacy autodoc markup:

r'<div[^>]*class="docstring[^"]*"[^>]*>.*?<docstring>.*?</docstring>.*?</div>'

but since #797 python emits the svelte component with metadata as props instead — <Docstring name={"…"} anchor={"…"} parameters={[…]}> — and no <docstring> tag exists anymore. So no block ever matched process_docstring_block; everything fell through to strip_remaining_html, which deleted the <Docstring …> opening tag wholesale (name + anchor + signature) and the section tags along with it.

Fix

  • extract_docstring_info parses the current form: props from the opening tag, sections from the body. Prop values are decoded with json.JSONDecoder().raw_decode, so } / > inside type annotations and defaults can't truncate the parse.
  • strip_html_from_markdown matches <Docstring …></Docstring> (the opening tag ends at the last > on its line — the same single-line-JSON contract kit/preprocessors/docstring.js relies on) and keeps a blank line before the description that follows it.
  • process_docstring_block renders the call signature from the parameters prop, and now also emits extra parameter groups, **Yields:** and **Raises:**, which were dropped entirely before. Types are backtick-wrapped only when they carry no markup — wrapping a resolved [Name](url) doc link would break it. Properties (isGetSetDescriptor) get no signature; a no-arg method still gets foo().

Section order (signature → parameters → returns → description) matches how Docstring.svelte renders the page.

Result

Verified end-to-end with a real [[autodoc]] HfApi build:

#### merge_pull_request[[huggingface_hub.HfApi.merge_pull_request]]

```python
merge_pull_request(repo_id: str, discussion_num: int, token: bool | str | None = None, comment: str | None = None, repo_type: str | None = None)
```

[Source](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/hf_api.py#L7921)

**Parameters:**

repo_id (`str`) : A namespace (user or an organization) and a repo name separated by a `/`.
…

**Returns:** `DiscussionStatusChange`

the status change event

Merges a Pull Request.

Four regression tests added (class-level block with a method, getset descriptor, > inside props, no-arg signature). Full suite passes.

Not fixed here

  • get_signature_component_markdown (the embeddings/meilisearch path) also has <name> commented out and only emits Docstring for: {anchor} — but that predates Simplify docstring pipeline: python emits the <Docstring> component directly #797 and doesn't affect the .md export, so it's left alone.
  • Markdown autolinks in prose (<https://huggingface.co>) are eaten by the generic tag regex in strip_remaining_html (hence "Defaults to ." in parameter descriptions). Separate pre-existing bug.

🤖 Generated with Claude Code

`strip_html_from_markdown` still looked for the legacy
`<div class="docstring">...<docstring>...</docstring>` markup, which
`autodoc` stopped emitting in #797 (it now emits the `<Docstring>`
component with metadata as props). Nothing matched, so the whole opening
tag was deleted by the generic tag cleanup -- taking the name, anchor and
signature with it -- and the `**Parameters:**` / `**Returns:**` labels
vanished too, gluing the return type onto the last parameter line.

Parse the current form instead: props from the opening tag (whose
attribute values are single-line JSON, decoded with `raw_decode` so `}`
and `>` inside type annotations can't truncate it), sections from the
component body. The signature is rendered from the `parameters` prop, and
the parameter groups / yields / raises sections -- previously dropped
entirely -- are emitted as well. Types are only wrapped in backticks when
they carry no markup, since that would break a resolved `[Name](url)` doc
link.

Section order (signature, parameters, returns, then the description that
follows the component) matches how `Docstring.svelte` renders the page.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mishig25
mishig25 merged commit 23dc84b into main Jul 31, 2026
4 checks passed
@mishig25
mishig25 deleted the fix-md-export-docstring-props branch July 31, 2026 09:17
Wauplin pushed a commit to huggingface/huggingface_hub that referenced this pull request Jul 31, 2026
Picks up huggingface/doc-builder#810, which restores method names,
anchors, signatures and the Parameters/Returns labels in the `.md`
(llms / plain-text) export of `[[autodoc]]` pages.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant