add citations

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben 2018-08-03 09:23:22 +01:00
parent e790b0d6b8
commit 67d6503d9a
3 changed files with 33 additions and 1 deletions

View File

@ -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

1
parser/citation.go Normal file
View File

@ -0,0 +1 @@
package parser

View File

@ -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