Skip to content

Commit f1cbf75

Browse files
brsonclaude
andcommitted
Fix short doc descriptions leaking raw markdown reference definitions
The extract_reference_definitions heuristic matched rustdoc-internal link lines (e.g. [`HandleErrorLayer`]: with no destination) that are not valid CommonMark. Comrak rendered them as visible text in a second paragraph, breaking the item listing display. Remove the ref-def extraction entirely since shortcut links are already resolved via the global index and pre-resolved links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a76fde7 commit f1cbf75

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

crates/rustmax-rustdoc/src/render/markdown.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,6 @@ fn html_escape(s: &str) -> String {
445445
.replace('"', "&quot;")
446446
}
447447

448-
/// Extract reference-style link definitions from markdown.
449-
fn extract_reference_definitions(md: &str) -> String {
450-
let mut defs = Vec::new();
451-
for line in md.lines() {
452-
let trimmed = line.trim();
453-
if trimmed.starts_with('[') && trimmed.contains("]:") {
454-
defs.push(trimmed);
455-
}
456-
}
457-
defs.join("\n")
458-
}
459-
460448
/// Extract first paragraph from markdown.
461449
fn extract_first_paragraph(md: &str) -> String {
462450
let trimmed = md.trim();
@@ -479,8 +467,11 @@ fn strip_paragraph_wrapper(html: &str) -> String {
479467

480468
/// Render the first paragraph of documentation as inline HTML.
481469
///
482-
/// Handles reference-style links by extracting definitions from the full doc,
483-
/// then rendering only the first paragraph with those definitions available.
470+
/// Only the first paragraph is rendered. Rustdoc-style shortcut links
471+
/// within it are resolved via the global index and pre-resolved links,
472+
/// so appending reference definitions from the full doc is unnecessary
473+
/// (and harmful, since many rustdoc ref-def lines are not valid
474+
/// CommonMark and get rendered as visible text).
484475
pub fn render_short_doc(
485476
full_docs: &str,
486477
highlighter: &Highlighter,
@@ -489,17 +480,10 @@ pub fn render_short_doc(
489480
current_depth: usize,
490481
pre_resolved_links: &HashMap<String, String>,
491482
) -> String {
492-
let ref_defs = extract_reference_definitions(full_docs);
493483
let first_para = extract_first_paragraph(full_docs);
494484

495-
let combined = if ref_defs.is_empty() {
496-
first_para
497-
} else {
498-
format!("{}\n\n{}", first_para, ref_defs)
499-
};
500-
501485
let html = render_markdown_with_links(
502-
&combined,
486+
&first_para,
503487
highlighter,
504488
global_index,
505489
current_crate,

0 commit comments

Comments
 (0)