Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/mistune/plugins/url.py: 35%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from typing import TYPE_CHECKING, Match
3from ..util import escape_url
5if TYPE_CHECKING:
6 from ..core import InlineState
7 from ..inline_parser import InlineParser
8 from ..markdown import Markdown
10__all__ = ["url"]
12URL_LINK_PATTERN = r"""https?:\/\/[^\s<]+[^<.,:;"')\]\s]"""
15def parse_url_link(inline: "InlineParser", m: Match[str], state: "InlineState") -> int:
16 text = m.group(0)
17 pos = m.end()
18 if state.brackets:
19 close = text.find("]")
20 if close >= 0:
21 text = text[:close]
22 pos = m.start() + close
23 if state.in_link or state.depth >= inline.max_nested_level:
24 inline.process_text(text, state)
25 return pos
26 state.append_token(
27 {
28 "type": "link",
29 "children": [{"type": "text", "raw": text}],
30 "attrs": {"url": escape_url(text)},
31 "_autolink": text,
32 }
33 )
34 return pos
37def url(md: "Markdown") -> None:
38 md.inline.register("url_link", URL_LINK_PATTERN, parse_url_link)