MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / _block_markdown

Function _block_markdown

scripts/docs/generate_rust_library_reference.py:371–474  ·  view source on GitHub ↗
(node: PageElement, page: Page, pages_by_html: dict[Path, Page], depth: int = 0)

Source from the content-addressed store, hash-verified

369
370
371def _block_markdown(node: PageElement, page: Page, pages_by_html: dict[Path, Page], depth: int = 0) -> str:
372 if isinstance(node, NavigableString):
373 return ""
374 if not isinstance(node, Tag):
375 return ""
376
377 classes = _tag_classes(node)
378 if node.name in {"script", "style", "rustdoc-toolbar"} or classes & {"anchor", "doc-anchor", "src"}:
379 return ""
380 if node.name == "div" and "main-heading" in classes:
381 return ""
382 if node.name == "span" and "item-info" in classes:
383 return ""
384 if node.get("id") in {"synthetic-implementations-list", "blanket-implementations-list"}:
385 return ""
386
387 if node.name in {"h2", "h3", "h4", "h5"} and "code-header" in classes:
388 return _code_header_markdown(node, page, pages_by_html)
389
390 if node.name in {"h2", "h3", "h4", "h5"}:
391 level = {"h2": "##", "h3": "###", "h4": "####", "h5": "#####"}[node.name]
392 text = _heading_text(node)
393 if text in {"Auto Trait Implementations", "Blanket Implementations"}:
394 return ""
395 return f"{level} {text}\n\n" if text else ""
396
397 if node.name == "span" and "section-header" in classes:
398 text = _plain_code(node)
399 return f"### {_inline_code(text)}\n\n" if text else ""
400
401 if node.name == "p":
402 text = re.sub(r"\s+", " ", _inline_markdown(node, page, pages_by_html)).strip()
403 return f"{text}\n\n" if text else ""
404
405 if node.name == "pre":
406 if node.find("a", href=True) is not None:
407 return _linked_signature_block(node, page, pages_by_html)
408 return _rust_fence(_plain_code(node))
409
410 if node.name == "ul":
411 lines: list[str] = []
412 for li in node.find_all("li", recursive=False):
413 text = re.sub(r"\s+", " ", _inline_markdown(li, page, pages_by_html)).strip()
414 if text:
415 lines.append(f"{' ' * depth}- {text}")
416 return "\n".join(lines) + ("\n\n" if lines else "")
417
418 if node.name == "ol":
419 lines = []
420 for index, li in enumerate(node.find_all("li", recursive=False), start=1):
421 text = re.sub(r"\s+", " ", _inline_markdown(li, page, pages_by_html)).strip()
422 if text:
423 lines.append(f"{' ' * depth}{index}. {text}")
424 return "\n".join(lines) + ("\n\n" if lines else "")
425
426 if node.name == "dl":
427 parts: list[str] = []
428 children = [child for child in node.children if isinstance(child, Tag)]

Callers 1

_render_pageFunction · 0.85

Calls 11

_tag_classesFunction · 0.85
_code_header_markdownFunction · 0.85
_heading_textFunction · 0.85
_plain_codeFunction · 0.85
_inline_codeFunction · 0.85
_inline_markdownFunction · 0.85
_linked_signature_blockFunction · 0.85
_rust_fenceFunction · 0.85
getMethod · 0.80
joinMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected