MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / link

Function link

markdown_it/rules_inline/link.py:7–149  ·  view source on GitHub ↗
(state: StateInline, silent: bool)

Source from the content-addressed store, hash-verified

5
6
7def link(state: StateInline, silent: bool) -> bool:
8 href = ""
9 title = ""
10 label = None
11 oldPos = state.pos
12 maximum = state.posMax
13 start = state.pos
14 parseReference = True
15
16 if state.src[state.pos] != "[":
17 return False
18
19 labelStart = state.pos + 1
20 labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, True)
21
22 # parser failed to find ']', so it's not a valid link
23 if labelEnd < 0:
24 return False
25
26 pos = labelEnd + 1
27
28 if pos < maximum and state.src[pos] == "(":
29 #
30 # Inline link
31 #
32
33 # might have found a valid shortcut link, disable reference parsing
34 parseReference = False
35
36 # [link]( <href> "title" )
37 # ^^ skipping these spaces
38 pos += 1
39 while pos < maximum:
40 ch = state.src[pos]
41 if not isStrSpace(ch) and ch != "\n":
42 break
43 pos += 1
44
45 if pos >= maximum:
46 return False
47
48 # [link]( <href> "title" )
49 # ^^^^^^ parsing link destination
50 start = pos
51 res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax)
52 if res.ok:
53 href = state.md.normalizeLink(res.str)
54 if state.md.validateLink(href):
55 pos = res.pos
56 else:
57 href = ""
58
59 # [link]( <href> "title" )
60 # ^^ skipping these spaces
61 start = pos
62 while pos < maximum:
63 ch = state.src[pos]
64 if not isStrSpace(ch) and ch != "\n":

Callers

nothing calls this directly

Calls 7

isStrSpaceFunction · 0.85
normalizeReferenceFunction · 0.85
normalizeLinkMethod · 0.80
validateLinkMethod · 0.80
attrSetMethod · 0.80
pushMethod · 0.45
tokenizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…