Skip to content

Commit

Permalink
better citations
Browse files Browse the repository at this point in the history
Signed-off-by: Miek Gieben <[email protected]>
  • Loading branch information
miekg committed Sep 3, 2018
1 parent 3d8f1b3 commit 59b50e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 5 additions & 2 deletions Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,11 @@ citation to the references, but does not show up in the document as a citation.
The first seen modifier determines the type (suppressed, normative or informative).
Multiple citation can separated with a semicolon: `[@RFC1034; @RFC1035]`.

If you reference an RFC or I-D the reference will be added automatically (no need to muck about
with an `<reference>` block.
If you reference an RFC, I-D or W3C document the reference will be added automatically (no need to
muck about with an `<reference>` block. This is to say:

Any reference starting with *RFC*, *I-D.* or *W3C.* will be automatically added to the correct
reference section.

For I-Ds you may want to add a draft sequence number, which can be done as such: `[@?I-D.blah#06]`.
If you reference an I-D *without* a sequence number it will create a reference to the *last* I-D in
Expand Down
13 changes: 10 additions & 3 deletions xml/bibliography.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
tag := ""
switch {
case bytes.HasPrefix(node.Anchor, []byte("RFC")):
tag = makeXiInclude(toolsIetfOrg, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))
tag = makeXiInclude(ToolsRFC, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))

case bytes.HasPrefix(node.Anchor, []byte("W3C.")):
tag = makeXiInclude(ToolsW3C, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))

case bytes.HasPrefix(node.Anchor, []byte("I-D.")):
hash := bytes.Index(node.Anchor, []byte("#"))
Expand All @@ -48,7 +51,7 @@ func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
node.Anchor[hash] = '-'
defer func() { node.Anchor[hash] = '#' }() // never know if this will be used again
}
tag = makeXiInclude(toolsIetfOrg, fmt.Sprintf("reference.I-D.draft-%s.xml", node.Anchor[4:]))
tag = makeXiInclude(ToolsID, fmt.Sprintf("reference.I-D.draft-%s.xml", node.Anchor[4:]))
}
r.outs(w, tag)
r.cr(w)
Expand All @@ -59,4 +62,8 @@ func makeXiInclude(url, reference string) string {
return fmt.Sprintf("<xi:include href=\"%s/%s\"/>", url, reference)
}

var toolsIetfOrg = "https://xml2rfc.tools.ietf.org/public/rfc/bibxml"
var (
ToolsRFC = "https://xml2rfc.ietf.org/public/rfc/bibxml/"
ToolsID = "https://xml2rfc.ietf.org/public/rfc/bibxml-ids/"
ToolsW3C = "https://xml2rfc.ietf.org/public/rfc/bibxml-w3c/"
)
11 changes: 7 additions & 4 deletions xml2/bibliography.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/gomarkdown/markdown/ast"
"github.com/mmarkdown/mmark/mast"
"github.com/mmarkdown/mmark/xml"
)

func (r *Renderer) bibliography(w io.Writer, node *mast.Bibliography, entering bool) {
Expand Down Expand Up @@ -40,15 +41,19 @@ func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
tag := ""
switch {
case bytes.HasPrefix(node.Anchor, []byte("RFC")):
tag = makeRFCInclude(toolsIetfOrg, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))
tag = makeRFCInclude(xml.ToolsRFC, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))

case bytes.HasPrefix(node.Anchor, []byte("W3C.")):
tag = makeRFCInclude(xml.ToolsW3C, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))

case bytes.HasPrefix(node.Anchor, []byte("I-D.")):
hash := bytes.Index(node.Anchor, []byte("#"))
if hash > 0 {
// rewrite # to - and we have our link
node.Anchor[hash] = '-'
defer func() { node.Anchor[hash] = '#' }() // never know if this will be used again
}
tag = makeRFCInclude(toolsIetfOrg, fmt.Sprintf("reference.I-D.draft-%s.xml", node.Anchor[4:]))
tag = makeRFCInclude(xml.ToolsID, fmt.Sprintf("reference.I-D.draft-%s.xml", node.Anchor[4:]))
}
r.outs(w, tag)
r.cr(w)
Expand All @@ -57,5 +62,3 @@ func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
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"

0 comments on commit 59b50e3

Please sign in to comment.