Skip to content

Commit

Permalink
Allow STD and BCP to be easily referenced
Browse files Browse the repository at this point in the history
Signed-off-by: Miek Gieben <miek@miek.nl>
  • Loading branch information
miekg committed Nov 4, 2023
1 parent f11e061 commit 5df4a77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Syntax.md
Expand Up @@ -575,11 +575,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, I-D or W3C document the reference will be added automatically (no need to
muck about with an `<reference>` block). This is to say:
If you reference an RFC, I-D, BCP or STD 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.
Any reference starting with *RFC*, *BCP*, *STD*, *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
25 changes: 24 additions & 1 deletion render/xml/bibliography.go
Expand Up @@ -63,11 +63,17 @@ func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
tag := ""
switch {
case bytes.HasPrefix(node.Anchor, []byte("RFC")):
tag = makeXiInclude(BibRFC, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))
tag = makeXiInclude(BibRFC, fmt.Sprintf("reference.RFC.%s.xml", prefixWithZero(node.Anchor[3:])))

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

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

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

case bytes.HasPrefix(node.Anchor, []byte("I-D.")):
hash := bytes.Index(node.Anchor, []byte("#"))
draft := ""
Expand Down Expand Up @@ -96,8 +102,25 @@ func makeXiInclude(url, reference string) string {
return fmt.Sprintf("<xi:include href=\"%s/%s\"/>", url, reference)
}

func prefixWithZero(num []byte) []byte {
switch len(num) {
case 0:
return num
case 1:
return append([]byte("000"), num...)
case 2:
return append([]byte("00"), num...)
case 3:
return append([]byte("00"), num...)
default:
return num
}
}

var (
BibRFC = "https://bib.ietf.org/public/rfc/bibxml"
BibID = "https://bib.ietf.org/public/rfc/bibxml3"
BibW3C = "https://bib.ietf.org/public/rfc/bibxml4"
BibBCP = "https://bib.ietf.org/public/rfc/bibxml9" // reference.BCP.0014.xml
BibSTD = "https://bib.ietf.org/public/rfc/bibxml9" // reference.STD.0094.xml
)

0 comments on commit 5df4a77

Please sign in to comment.