-
Notifications
You must be signed in to change notification settings - Fork 48
/
bibliography.go
55 lines (45 loc) · 1.16 KB
/
bibliography.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package xml2
import (
"bytes"
"fmt"
"io"
"regexp"
"github.com/gomarkdown/markdown/ast"
"github.com/mmarkdown/mmark/mast"
)
// TODO, expand this to use regular expressions.
var (
rfcRe = regexp.MustCompile(`/RFC(/d+)/`)
)
func (r *Renderer) bibliography(w io.Writer, node *mast.Bibliography, entering bool) {
if !entering {
r.outs(w, "</references>\n")
return
}
r.sectionClose(w, nil)
switch node.Type {
case ast.CitationTypeInformative:
r.outs(w, `<references title="Informative References">`)
case ast.CitationTypeNormative:
r.outs(w, `<references title="Normative References">`)
}
r.cr(w)
}
func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
if node.Raw != nil {
r.out(w, node.Raw)
r.cr(w)
return
}
tag := ""
switch {
case bytes.HasPrefix(node.Anchor, []byte("RFC")): // TODO(miek): use regexp here.
tag = makeRFCInclude(toolsIetfOrg, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))
}
r.outs(w, tag)
r.cr(w)
}
func makeRFCInclude(url, reference string) string {
return fmt.Sprintf("<?rfc include=\"%s/%s\"?>", url, reference)
}
var toolsIetfOrg = "https://xml2rfc.tools.ietf.org/public/rfc/bibxml"