Add more info to LinkData
parent
d3b5b032dc
commit
4e8c643f8f
41
inline.go
41
inline.go
|
@ -262,10 +262,11 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
data = data[offset:]
|
||||
|
||||
var (
|
||||
i = 1
|
||||
noteID int
|
||||
title, link, altContent []byte
|
||||
textHasNl = false
|
||||
i = 1
|
||||
noteID int
|
||||
refID, title, link, altContent []byte
|
||||
isRef = false
|
||||
textHasNl = false
|
||||
)
|
||||
|
||||
if t == linkDeferredFootnote {
|
||||
|
@ -401,7 +402,7 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
|
||||
// reference style link
|
||||
case isReferenceStyleLink(data, i, t):
|
||||
var id []byte
|
||||
isRef = true
|
||||
altContentConsidered := false
|
||||
|
||||
// look for the id
|
||||
|
@ -429,17 +430,17 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
}
|
||||
}
|
||||
|
||||
id = b.Bytes()
|
||||
refID = b.Bytes()
|
||||
} else {
|
||||
id = data[1:txtE]
|
||||
refID = data[1:txtE]
|
||||
altContentConsidered = true
|
||||
}
|
||||
} else {
|
||||
id = data[linkB:linkE]
|
||||
refID = data[linkB:linkE]
|
||||
}
|
||||
|
||||
// find the reference with matching id
|
||||
lr, ok := p.getRef(string(id))
|
||||
lr, ok := p.getRef(string(refID))
|
||||
if !ok {
|
||||
return 0, nil
|
||||
}
|
||||
|
@ -454,7 +455,7 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
|
||||
// shortcut reference style link or reference or inline footnote
|
||||
default:
|
||||
var id []byte
|
||||
isRef = true
|
||||
|
||||
// craft the id
|
||||
if textHasNl {
|
||||
|
@ -469,12 +470,12 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
}
|
||||
}
|
||||
|
||||
id = b.Bytes()
|
||||
refID = b.Bytes()
|
||||
} else {
|
||||
if t == linkDeferredFootnote {
|
||||
id = data[2:txtE] // get rid of the ^
|
||||
refID = data[2:txtE] // get rid of the ^
|
||||
} else {
|
||||
id = data[1:txtE]
|
||||
refID = data[1:txtE]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,13 +485,13 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
noteID = len(p.notes) + 1
|
||||
|
||||
var fragment []byte
|
||||
if len(id) > 0 {
|
||||
if len(id) < 16 {
|
||||
fragment = make([]byte, len(id))
|
||||
if len(refID) > 0 {
|
||||
if len(refID) < 16 {
|
||||
fragment = make([]byte, len(refID))
|
||||
} else {
|
||||
fragment = make([]byte, 16)
|
||||
}
|
||||
copy(fragment, slugify(id))
|
||||
copy(fragment, slugify(refID))
|
||||
} else {
|
||||
fragment = append([]byte("footnote-"), []byte(strconv.Itoa(noteID))...)
|
||||
}
|
||||
|
@ -499,7 +500,7 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
noteID: noteID,
|
||||
hasBlock: false,
|
||||
link: fragment,
|
||||
title: id,
|
||||
title: refID,
|
||||
footnote: footnoteNode,
|
||||
}
|
||||
|
||||
|
@ -509,7 +510,7 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
title = ref.title
|
||||
} else {
|
||||
// find the reference with matching id
|
||||
lr, ok := p.getRef(string(id))
|
||||
lr, ok := p.getRef(string(refID))
|
||||
if !ok {
|
||||
return 0, nil
|
||||
}
|
||||
|
@ -583,6 +584,8 @@ func link(p *Markdown, data []byte, offset int) (int, *Node) {
|
|||
default:
|
||||
return 0, nil
|
||||
}
|
||||
linkNode.IsRefLink = isRef
|
||||
linkNode.RefID = refID
|
||||
|
||||
return i, linkNode
|
||||
}
|
||||
|
|
2
node.go
2
node.go
|
@ -85,6 +85,8 @@ type LinkData struct {
|
|||
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
|
||||
Footnote *Node // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil.
|
||||
IsRefLink bool // True if this is a reference style link.
|
||||
RefID []byte // The ID used for looking up the reference in ref style links.
|
||||
}
|
||||
|
||||
// CodeBlockData contains fields relevant to a CodeBlock node type.
|
||||
|
|
Loading…
Reference in New Issue