all repos — grayfriday @ c5943e068510d99ad28d07865734667a4b260775

blackfriday fork with a few changes

Reformat a dustball of ifs into a switch statement
Vytautas Ĺ altenis vytas@rtfb.lt
Wed, 04 Nov 2015 21:32:53 +0200
commit

c5943e068510d99ad28d07865734667a4b260775

parent

ca8c21a297ad75731d76c97059f3a5231eb061f2

1 files changed, 12 insertions(+), 10 deletions(-)

jump to
M inline.goinline.go

@@ -205,24 +205,26 @@ if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') {

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:]