Skip to content

Commit 5df4a77

Browse files
committed
Allow STD and BCP to be easily referenced
Signed-off-by: Miek Gieben <[email protected]>
1 parent f11e061 commit 5df4a77

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Syntax.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ citation to the references, but does not show up in the document as a citation.
575575
The first seen modifier determines the type (suppressed, normative or informative). Multiple
576576
citation can separated with a semicolon: `[@RFC1034;@RFC1035]`.
577577
578-
If you reference an RFC, I-D or W3C document the reference will be added automatically (no need to
579-
muck about with an `<reference>` block). This is to say:
578+
If you reference an RFC, I-D, BCP or STD or W3C document the reference will be added automatically
579+
(no need to muck about with an `<reference>` block). This is to say:
580580
581-
Any reference starting with *RFC*, *I-D.* or *W3C.* will be automatically added to the correct
582-
reference section.
581+
Any reference starting with *RFC*, *BCP*, *STD*, *I-D.* or *W3C.* will be automatically added to the
582+
correct reference section.
583583
584584
For I-Ds you may want to add a draft sequence number, which can be done as such: `[@?I-D.blah#06]`.
585585
If you reference an I-D *without* a sequence number it will create a reference to the *last* I-D in

render/xml/bibliography.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,17 @@ func (r *Renderer) bibliographyItem(w io.Writer, node *mast.BibliographyItem) {
6363
tag := ""
6464
switch {
6565
case bytes.HasPrefix(node.Anchor, []byte("RFC")):
66-
tag = makeXiInclude(BibRFC, fmt.Sprintf("reference.RFC.%s.xml", node.Anchor[3:]))
66+
tag = makeXiInclude(BibRFC, fmt.Sprintf("reference.RFC.%s.xml", prefixWithZero(node.Anchor[3:])))
6767

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

71+
case bytes.HasPrefix(node.Anchor, []byte("BCP")):
72+
tag = makeXiInclude(BibBCP, fmt.Sprintf("reference.BCP.%s.xml", prefixWithZero(node.Anchor[3:])))
73+
74+
case bytes.HasPrefix(node.Anchor, []byte("STD")):
75+
tag = makeXiInclude(BibSTD, fmt.Sprintf("reference.STD.%s.xml", prefixWithZero(node.Anchor[3:])))
76+
7177
case bytes.HasPrefix(node.Anchor, []byte("I-D.")):
7278
hash := bytes.Index(node.Anchor, []byte("#"))
7379
draft := ""
@@ -96,8 +102,25 @@ func makeXiInclude(url, reference string) string {
96102
return fmt.Sprintf("<xi:include href=\"%s/%s\"/>", url, reference)
97103
}
98104

105+
func prefixWithZero(num []byte) []byte {
106+
switch len(num) {
107+
case 0:
108+
return num
109+
case 1:
110+
return append([]byte("000"), num...)
111+
case 2:
112+
return append([]byte("00"), num...)
113+
case 3:
114+
return append([]byte("00"), num...)
115+
default:
116+
return num
117+
}
118+
}
119+
99120
var (
100121
BibRFC = "https://bib.ietf.org/public/rfc/bibxml"
101122
BibID = "https://bib.ietf.org/public/rfc/bibxml3"
102123
BibW3C = "https://bib.ietf.org/public/rfc/bibxml4"
124+
BibBCP = "https://bib.ietf.org/public/rfc/bibxml9" // reference.BCP.0014.xml
125+
BibSTD = "https://bib.ietf.org/public/rfc/bibxml9" // reference.STD.0094.xml
103126
)

0 commit comments

Comments
 (0)