mirror of
https://github.com/status-im/markdown.git
synced 2025-02-23 00:28:25 +00:00
Reformat a dustball of ifs into a switch statement
This commit is contained in:
parent
ca8c21a297
commit
c5943e0685
22
inline.go
22
inline.go
@ -205,24 +205,26 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// [text] == regular link
|
||||
var t linkType
|
||||
switch {
|
||||
// special case: ![^text] == deferred footnote (that follows something with
|
||||
// an exclamation point)
|
||||
case p.flags&EXTENSION_FOOTNOTES != 0 && len(data)-1 > offset && data[offset+1] == '^':
|
||||
t = linkDeferredFootnote
|
||||
// ![alt] == image
|
||||
case offset > 0 && data[offset-1] == '!':
|
||||
t = linkImg
|
||||
// ^[text] == inline footnote
|
||||
// [^refId] == deferred footnote
|
||||
var t linkType
|
||||
if offset > 0 && data[offset-1] == '!' {
|
||||
t = linkImg
|
||||
// if footnotes extension is ON and we've seen "![^", then it's not an
|
||||
// image, it's a deferred footnote:
|
||||
if p.flags&EXTENSION_FOOTNOTES != 0 && len(data)-1 > offset && data[offset+1] == '^' {
|
||||
t = linkDeferredFootnote
|
||||
}
|
||||
} else if p.flags&EXTENSION_FOOTNOTES != 0 {
|
||||
case p.flags&EXTENSION_FOOTNOTES != 0:
|
||||
if offset > 0 && data[offset-1] == '^' {
|
||||
t = linkInlineFootnote
|
||||
} else if len(data)-1 > offset && data[offset+1] == '^' {
|
||||
t = linkDeferredFootnote
|
||||
}
|
||||
// [text] == regular link
|
||||
default:
|
||||
t = linkNormal
|
||||
}
|
||||
|
||||
data = data[offset:]
|
||||
|
Loading…
x
Reference in New Issue
Block a user