Skip to content

Commit 09460d7

Browse files
committed
Implement the @rfc@RFC syntax
Closes: #209 This implements the final bits and adds a testcase. What is not tested is the generation of xi-includes. Signed-off-by: Miek Gieben <[email protected]>
1 parent 36ee9e8 commit 09460d7

File tree

7 files changed

+43
-21
lines changed

7 files changed

+43
-21
lines changed

Syntax.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@ If you reference an RFC, I-D, BCP or STD or W3C document the reference will be a
581581
Any reference starting with *RFC*, *BCP*, *STD*, *I-D.* or *W3C.* will be automatically added to the
582582
correct reference section.
583583
584+
Referring to a specific RFC of an STD/BCP can be done using the following syntax:
585+
`[@RFCxxx@STDyy]`, this expands `<xref target="RFCxxx"></xref> of <xref target="STDxx"></xref>`
586+
where both will be added to the automatically generated references. The word "of" will be
587+
translated according to the document language. Note: no attempt is made to validate if the RFC is
588+
actually part of the STD or BCP, i.e. `[@RFCxxx@RFCyyy]` will be happily accepted.
589+
584590
For I-Ds you may want to add a draft sequence number, which can be done as such: `[@?I-D.blah#06]`.
585591
If you reference an I-D *without* a sequence number it will create a reference to the *last* I-D in
586592
citation index. I.e. a draft named "draft-gieben-pandoc2rfc", the I-D reference becomes:

lang/lang.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"strings"
55
)
66

7+
// TODO(miek): functions below getting a bit long in the tooth.
8+
79
// New returns a new and initialized Lang.
810
func New(language string) Lang {
911
l := Lang{language: strings.ToLower(language)} // case insensitivity
@@ -13,6 +15,7 @@ func New(language string) Lang {
1315
l.m = map[string]Term{
1416
"en": {
1517
And: "and",
18+
Of: "of",
1619
Authors: "Authors",
1720
Bibliography: "Bibliography",
1821
Footnotes: "Footnotes",
@@ -25,6 +28,7 @@ func New(language string) Lang {
2528
},
2629
"nl": {
2730
And: "en",
31+
Of: "of",
2832
Bibliography: "Bibliografie",
2933
Footnotes: "Voetnoten",
3034
Index: "Index",
@@ -35,6 +39,7 @@ func New(language string) Lang {
3539
},
3640
"de": {
3741
And: "und",
42+
Of: "von",
3843
Bibliography: "Literaturverzeichnis",
3944
Footnotes: "Fußnoten",
4045
Index: "Index",
@@ -71,6 +76,7 @@ type Lang struct {
7176
// Term contains the specific terms for translation.
7277
type Term struct {
7378
And string
79+
Of string
7480
Authors string
7581
Bibliography string
7682
Footnotes string
@@ -124,6 +130,14 @@ func (l Lang) And() string {
124130
return t.And
125131
}
126132

133+
func (l Lang) Of() string {
134+
t, ok := l.m[l.language]
135+
if !ok {
136+
return l.m["en"].Of
137+
}
138+
return t.Of
139+
}
140+
127141
func (l Lang) WrittenBy() string {
128142
t, ok := l.m[l.language]
129143
if !ok {

mparser/bibliography.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func CitationToBibliography(doc ast.Node) (normative ast.Node, informative ast.N
5656
}
5757

5858
ref := &mast.BibliographyItem{}
59-
println("ANCHOR", string(d))
6059
ref.Anchor = d
6160
ref.Type = c.Type[i]
6261

render/xml/bibliography.go

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ 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", prefixWithZero(node.Anchor[3:])))
66+
tag = makeXiInclude(BibRFC, fmt.Sprintf("reference.RFC.%s.xml", 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

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

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

7777
case bytes.HasPrefix(node.Anchor, []byte("I-D.")):
7878
hash := bytes.Index(node.Anchor, []byte("#"))
@@ -102,25 +102,10 @@ func makeXiInclude(url, reference string) string {
102102
return fmt.Sprintf("<xi:include href=\"%s/%s\"/>", url, reference)
103103
}
104104

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-
120105
var (
121106
BibRFC = "https://bib.ietf.org/public/rfc/bibxml"
122107
BibID = "https://bib.ietf.org/public/rfc/bibxml3"
123108
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
109+
BibBCP = "https://bib.ietf.org/public/rfc/bibxml9"
110+
BibSTD = "https://bib.ietf.org/public/rfc/bibxml9"
126111
)

render/xml/renderer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ func (r *Renderer) citation(w io.Writer, node *ast.Citation, entering bool) {
263263
c = c[:hash]
264264
}
265265
}
266+
var stdattr []string
267+
// Detect and parse RFC@STD14, make 'c' contain the first dest and then add a second xref that we
268+
// prepare with the (translated) word of 'of' 'RFC xxxx' <xref ...>
269+
if n := bytes.Index(c, []byte("@")); n > 0 && len(c[n+1:]) > 2 {
270+
stdattr = []string{fmt.Sprintf(`target="%s"`, c[n+1:])}
271+
c = c[:n]
272+
}
266273

267274
attr := []string{fmt.Sprintf(`target="%s"`, c)}
268275

@@ -298,6 +305,14 @@ func (r *Renderer) citation(w io.Writer, node *ast.Citation, entering bool) {
298305

299306
r.outTag(w, "<xref", attr)
300307
r.outs(w, "</xref>")
308+
309+
if stdattr != nil {
310+
r.outs(w, " ")
311+
r.outs(w, r.opts.Language.Of())
312+
r.outs(w, " ")
313+
r.outTag(w, "<xref", stdattr)
314+
r.outs(w, "</xref>")
315+
}
301316
}
302317
}
303318

testdata/citation-std.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See [@RFC8948@STD14]

testdata/citation-std.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<t>See <xref target="RFC8948"></xref> of <xref target="STD14"></xref></t>
2+

0 commit comments

Comments
 (0)