Fix .md export losing method names, signatures and section labels - #810
Merged
Conversation
`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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
.md(llms / plain-text) twin of every[[autodoc]]class page lost all of its method headings. E.g.hf_api.mdhas 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:Cause
strip_html_from_markdownmatched 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 matchedprocess_docstring_block; everything fell through tostrip_remaining_html, which deleted the<Docstring …>opening tag wholesale (name + anchor + signature) and the section tags along with it.Fix
extract_docstring_infoparses the current form: props from the opening tag, sections from the body. Prop values are decoded withjson.JSONDecoder().raw_decode, so}/>inside type annotations and defaults can't truncate the parse.strip_html_from_markdownmatches<Docstring …>…</Docstring>(the opening tag ends at the last>on its line — the same single-line-JSON contractkit/preprocessors/docstring.jsrelies on) and keeps a blank line before the description that follows it.process_docstring_blockrenders the call signature from theparametersprop, 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 getsfoo().Section order (signature → parameters → returns → description) matches how
Docstring.svelterenders the page.Result
Verified end-to-end with a real
[[autodoc]] HfApibuild: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 emitsDocstring for: {anchor}— but that predates Simplify docstring pipeline: python emits the <Docstring> component directly #797 and doesn't affect the.mdexport, so it's left alone.<https://huggingface.co>) are eaten by the generic tag regex instrip_remaining_html(hence "Defaults to ." in parameter descriptions). Separate pre-existing bug.🤖 Generated with Claude Code