all repos — grayfriday @ 8e10236be5dd3b43b5a38f041e500dec837b6df5

blackfriday fork with a few changes

support replacing [refid][] syntax link content with alternate content
JT Olds hello@jtolds.com
Thu, 18 Dec 2014 17:36:46 -0700
commit

8e10236be5dd3b43b5a38f041e500dec837b6df5

parent

5e8b222b6980d15fae51c859ca79b97cc679168d

2 files changed, 20 insertions(+), 6 deletions(-)

jump to
M inline.goinline.go

@@ -211,10 +211,10 @@

data = data[offset:] var ( - i = 1 - noteId int - title, link []byte - textHasNl = false + i = 1 + noteId int + title, link, alt_content []byte + textHasNl = false ) if t == linkDeferredFootnote {

@@ -350,6 +350,7 @@

// reference style link case i < len(data) && data[i] == '[': var id []byte + alt_content_considered := false // look for the id i++

@@ -379,6 +380,7 @@

id = b.Bytes() } else { id = data[1:txtE] + alt_content_considered = true } } else { id = data[linkB:linkE]

@@ -394,6 +396,9 @@

// keep link and title from reference link = lr.link title = lr.title + if alt_content_considered { + alt_content = lr.text + } i++ // shortcut reference style link or reference or inline footnote

@@ -503,7 +508,11 @@

// call the relevant rendering function switch t { case linkNormal: - p.r.Link(out, uLink, title, content.Bytes()) + if len(alt_content) > 0 { + p.r.Link(out, uLink, title, alt_content) + } else { + p.r.Link(out, uLink, title, content.Bytes()) + } case linkImg: outSize := out.Len()
M markdown.gomarkdown.go

@@ -222,7 +222,8 @@ return &reference{

link: []byte(r.Link), title: []byte(r.Title), noteId: 0, - hasBlock: false}, true + hasBlock: false, + text: []byte(r.Text)}, true } } // refs are case insensitive

@@ -243,6 +244,9 @@ // Link is usually the URL the reference points to.

Link string // Title is the alternate text describing the link in more detail. Title string + // Text is the optional text to override the ref with if the syntax used was + // [refid][] + Text string } // ReferenceOverrideFunc is expected to be called with a reference string and

@@ -508,6 +512,7 @@ link []byte

title []byte noteId int // 0 if not a footnote ref hasBlock bool + text []byte } // Check whether or not data starts with a reference link.