(node: PageElement, page: Page, pages_by_html: dict[Path, Page])
| 251 | |
| 252 | |
| 253 | def _inline_markdown(node: PageElement, page: Page, pages_by_html: dict[Path, Page]) -> str: |
| 254 | if isinstance(node, NavigableString): |
| 255 | return _escape_text(str(node)) |
| 256 | if not isinstance(node, Tag): |
| 257 | return "" |
| 258 | |
| 259 | classes = _tag_classes(node) |
| 260 | if classes & {"anchor", "doc-anchor", "src"} or node.name in {"script", "style", "wbr", "button"}: |
| 261 | return "" |
| 262 | if node.name == "br": |
| 263 | return "\n" |
| 264 | if node.name == "code": |
| 265 | return _inline_code(_clean_text(node.get_text("", strip=False))) |
| 266 | if node.name == "a": |
| 267 | label = "".join(_inline_markdown(child, page, pages_by_html) for child in node.children).strip() |
| 268 | if not label or label == "Source": |
| 269 | return label |
| 270 | target = _resolve_href(page, _tag_href(node), pages_by_html) |
| 271 | if target is None: |
| 272 | return label |
| 273 | return f"[{label}]({target})" |
| 274 | if node.name == "strong": |
| 275 | content = "".join(_inline_markdown(child, page, pages_by_html) for child in node.children).strip() |
| 276 | return f"**{content}**" if content else "" |
| 277 | if node.name == "em": |
| 278 | content = "".join(_inline_markdown(child, page, pages_by_html) for child in node.children).strip() |
| 279 | return f"*{content}*" if content else "" |
| 280 | return "".join(_inline_markdown(child, page, pages_by_html) for child in node.children) |
| 281 | |
| 282 | |
| 283 | def _plain_code(node: Tag) -> str: |
no test coverage detected