parent
e790b0d6b8
commit
67d6503d9a
18
ast/node.go
18
ast/node.go
|
@ -39,6 +39,16 @@ const (
|
|||
DocumentMatterBack
|
||||
)
|
||||
|
||||
// CitationTypes holds the type of a citation, informative, normative or suppressed
|
||||
type CitationTypes int
|
||||
|
||||
const (
|
||||
CitationTypeNone CitationTypes = iota
|
||||
CitationTypeSuppressed
|
||||
CitationTypeInformative
|
||||
CitationTypeNormative
|
||||
)
|
||||
|
||||
// Node defines an ast node
|
||||
type Node interface {
|
||||
AsContainer() *Container
|
||||
|
@ -240,6 +250,14 @@ type CrossReference struct {
|
|||
Destination []byte // Destination is where the reference points to
|
||||
}
|
||||
|
||||
// Citation is a citation node.
|
||||
type Citation struct {
|
||||
Container
|
||||
|
||||
Destination [][]byte // Destination is where the citation points to. Multiple ones are allowed.
|
||||
Type []CitationTypes // 1:1 mapping of destination and citation type
|
||||
}
|
||||
|
||||
// Image represents markdown image node
|
||||
type Image struct {
|
||||
Container
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
package parser
|
|
@ -177,6 +177,7 @@ const (
|
|||
linkImg
|
||||
linkDeferredFootnote
|
||||
linkInlineFootnote
|
||||
linkCitation
|
||||
)
|
||||
|
||||
func isReferenceStyleLink(data []byte, pos int, t linkType) bool {
|
||||
|
@ -200,7 +201,7 @@ func maybeInlineFootnote(p *Parser, data []byte, offset int) (int, ast.Node) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
// '[': parse a link or an image or a footnote
|
||||
// '[': parse a link or an image or a footnote or a citation
|
||||
func link(p *Parser, data []byte, offset int) (int, ast.Node) {
|
||||
// no links allowed inside regular links, footnote, and deferred footnotes
|
||||
if p.insideLink && (offset > 0 && data[offset-1] == '[' || len(data)-1 > offset && data[offset+1] == '^') {
|
||||
|
@ -226,6 +227,14 @@ func link(p *Parser, data []byte, offset int) (int, ast.Node) {
|
|||
} else if len(data)-1 > offset && data[offset+1] == '^' {
|
||||
t = linkDeferredFootnote
|
||||
}
|
||||
// [@citation], [-@citation] support
|
||||
case p.extensions&Mmark != 0:
|
||||
if len(data)-1 > offset && data[offset+1] == '@' {
|
||||
t = linkCitation
|
||||
}
|
||||
if len(data)-2 > offset && data[offset+1] == '-' && data[offset+2] == '@' {
|
||||
t = linkCitation
|
||||
}
|
||||
// [text] == regular link
|
||||
default:
|
||||
t = linkNormal
|
||||
|
@ -233,6 +242,10 @@ func link(p *Parser, data []byte, offset int) (int, ast.Node) {
|
|||
|
||||
data = data[offset:]
|
||||
|
||||
if t == linkCitation {
|
||||
return citation(p, data, 0)
|
||||
}
|
||||
|
||||
var (
|
||||
i = 1
|
||||
noteID int
|
||||
|
|
Loading…
Reference in New Issue