MCPcopy Create free account
hub / github.com/fastapi/fastapi / extract_markdown_links

Function extract_markdown_links

scripts/doc_parsing_utils.py:252–276  ·  view source on GitHub ↗

Extract all markdown links from the given lines. Return list of MarkdownLinkInfo, where each dict contains: - `line_no` - line number (1-based) - `url` - link URL - `text` - link text - `title` - link title (if any)

(lines: list[str])

Source from the content-addressed store, hash-verified

250
251
252def extract_markdown_links(lines: list[str]) -> list[MarkdownLinkInfo]:
253 """
254 Extract all markdown links from the given lines.
255
256 Return list of MarkdownLinkInfo, where each dict contains:
257 - `line_no` - line number (1-based)
258 - `url` - link URL
259 - `text` - link text
260 - `title` - link title (if any)
261 """
262
263 links: list[MarkdownLinkInfo] = []
264 for line_no, line in enumerate(lines, start=1):
265 for m in MARKDOWN_LINK_RE.finditer(line):
266 links.append(
267 MarkdownLinkInfo(
268 line_no=line_no,
269 url=m.group("url"),
270 text=m.group("text"),
271 title=m.group("title"),
272 attributes=m.group("attrs"),
273 full_match=m.group(0),
274 )
275 )
276 return links
277
278
279def _add_lang_code_to_url(url: str, lang_code: str) -> str:

Callers 1

check_translationFunction · 0.85

Calls 1

MarkdownLinkInfoClass · 0.85

Tested by

no test coverage detected