all repos — grayfriday @ a110088781ed1fabba4a59d6355a9058dc4fdf6a

blackfriday fork with a few changes

Optional image width and height
Anirudh Oppiliappan x@icyphox.sh
Tue, 21 Jun 2022 21:45:25 +0530
commit

a110088781ed1fabba4a59d6355a9058dc4fdf6a

parent

f1d36e6d67c68a28869588c0505283b300729419

4 files changed, 44 insertions(+), 0 deletions(-)

jump to
M html.gohtml.go

@@ -614,6 +614,10 @@ if node.LinkData.Title != nil {

r.out(w, []byte(`" title="`)) escapeHTML(w, node.LinkData.Title) } + if node.LinkData.Width != 0 { + r.out(w, []byte(fmt.Sprintf(`" width="%d" height="%d`, + node.LinkData.Width, node.LinkData.Height))) + } r.out(w, []byte(`" />`)) } }
M inline.goinline.go

@@ -17,6 +17,7 @@ import (

"bytes" "regexp" "strconv" + "strings" ) var (

@@ -265,6 +266,7 @@ var (

i = 1 noteID int title, link, altContent []byte + widthHeight []byte textHasNl = false )

@@ -399,6 +401,32 @@ }

i++ + var whE, whB int + if i < len(data) && data[i] == '{' { + i++ + whB = i + + findwidthheight: + for i < len(data) { + switch { + case data[i] == '}': + break findwidthheight + default: + i++ + } + } + + if i >= len(data) { + return 0, nil + } + + whE = i + + if whE > whB { + widthHeight = data[whB:whE] + } + i++ + } // reference style link case isReferenceStyleLink(data, i, t): var id []byte

@@ -565,6 +593,12 @@ }

case linkImg: linkNode = NewNode(Image) + if len(widthHeight) > 0 { + wh := strings.Split(string(widthHeight), "x") + w, _ := strconv.Atoi(wh[0]) + h, _ := strconv.Atoi(wh[1]) + linkNode.Width, linkNode.Height = w, h + } linkNode.Destination = uLink linkNode.Title = title linkNode.AppendChild(text(data[1:txtE]))
M node.gonode.go

@@ -84,6 +84,8 @@ type LinkData struct {

Destination []byte // Destination is what goes into a href Title []byte // Title is the tooltip thing that goes in a title attribute NoteID int // NoteID contains a serial number of a footnote, zero if it's not a footnote + Width int // Width attribute for an img + Height int // Height attribute for an img Footnote *Node // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil. }
M readmereadme

@@ -8,6 +8,10 @@ This is more typographically accurate, while allowing for cleaner looking plaintext.

• En-dashes only between numbers. For example: "8-9 years" becomes "8ndash;9 years". Again, this keeps the plaintext more natural (as opposed to writing "8 - 9" years in blackfriday for an en-dash). + • Optional image width/height. For example: + ![foo image](http://example.com/bar.png){400x800} + This renders as: + <p><img src="http://example.com/bar.png" alt="foo image" width="400" height="800" /></p> INSTALL