Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/mistune/plugins/url.py: 72%

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

18 statements  

1from typing import TYPE_CHECKING, Match 

2 

3from ..util import escape_url 

4 

5if TYPE_CHECKING: 

6 from ..core import InlineState 

7 from ..inline_parser import InlineParser 

8 from ..markdown import Markdown 

9 

10__all__ = ["url"] 

11 

12URL_LINK_PATTERN = r"""https?:\/\/[^\s<]+[^<.,:;"')\]\s]""" 

13 

14 

15def parse_url_link(inline: "InlineParser", m: Match[str], state: "InlineState") -> int: 

16 text = m.group(0) 

17 pos = m.end() 

18 if state.in_link: 

19 inline.process_text(text, state) 

20 return pos 

21 state.append_token( 

22 { 

23 "type": "link", 

24 "children": [{"type": "text", "raw": text}], 

25 "attrs": {"url": escape_url(text)}, 

26 } 

27 ) 

28 return pos 

29 

30 

31def url(md: "Markdown") -> None: 

32 md.inline.register("url_link", URL_LINK_PATTERN, parse_url_link)