MCPcopy
hub / github.com/russross/blackfriday / link

Function link

inline.go:232–588  ·  view source on GitHub ↗

'[': parse a link or an image or a footnote

(p *Markdown, data []byte, offset int)

Source from the content-addressed store, hash-verified

230
231// '[': parse a link or an image or a footnote
232func link(p *Markdown, data []byte, offset int) (int, *Node) {
233 // no links allowed inside regular links, footnote, and deferred footnotes
234 if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') {
235 return 0, nil
236 }
237
238 var t linkType
239 switch {
240 // special case: ![^text] == deferred footnote (that follows something with
241 // an exclamation point)
242 case p.extensions&Footnotes != 0 && len(data)-1 > offset && data[offset+1] == '^':
243 t = linkDeferredFootnote
244 // ![alt] == image
245 case offset >= 0 && data[offset] == '!':
246 t = linkImg
247 offset++
248 // ^[text] == inline footnote
249 // [^refId] == deferred footnote
250 case p.extensions&Footnotes != 0:
251 if offset >= 0 && data[offset] == '^' {
252 t = linkInlineFootnote
253 offset++
254 } else if len(data)-1 > offset && data[offset+1] == '^' {
255 t = linkDeferredFootnote
256 }
257 // [text] == regular link
258 default:
259 t = linkNormal
260 }
261
262 data = data[offset:]
263
264 var (
265 i = 1
266 noteID int
267 title, link, altContent []byte
268 textHasNl = false
269 )
270
271 if t == linkDeferredFootnote {
272 i++
273 }
274
275 // look for the matching closing bracket
276 for level := 1; level > 0 && i < len(data); i++ {
277 switch {
278 case data[i] == '\n':
279 textHasNl = true
280
281 case isBackslashEscaped(data, i):
282 continue
283
284 case data[i] == '[':
285 level++
286
287 case data[i] == ']':
288 level--
289 if level <= 0 {

Callers 2

maybeImageFunction · 0.85
maybeInlineFootnoteFunction · 0.85

Calls 11

AppendChildMethod · 0.95
isBackslashEscapedFunction · 0.85
isspaceFunction · 0.85
isReferenceStyleLinkFunction · 0.85
NewNodeFunction · 0.85
slugifyFunction · 0.85
unescapeTextFunction · 0.85
normalizeURIFunction · 0.85
textFunction · 0.85
getRefMethod · 0.80
inlineMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…