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

Function image

markdown_it/rules_inline/image.py:9–148  ·  view source on GitHub ↗
(state: StateInline, silent: bool)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…