-
Notifications
You must be signed in to change notification settings - Fork 48
/
title.go
85 lines (67 loc) · 2.11 KB
/
title.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package xml2
import (
"io"
"github.com/gomarkdown/markdown/ast"
"github.com/gomarkdown/markdown/html"
"github.com/mmarkdown/mmark/mast"
"github.com/mmarkdown/mmark/xml"
)
func (r *Renderer) titleBlock(w io.Writer, t *mast.Title) {
// Order is fixed in RFC 7749.
d := t.TitleData
if d == nil {
return
}
consensusToTerm := map[bool]string{
false: "no",
true: "yes",
}
attrs := xml.Attributes(
[]string{"ipr", "submissionType", "category", "xml:lang", "consensus"},
[]string{d.Ipr, d.SeriesInfo.Stream, xml.StatusToCategory[d.SeriesInfo.Status], "en", consensusToTerm[d.Consensus]},
)
attrs = append(attrs, xml.Attributes(
[]string{"updates", "obsoletes"},
[]string{xml.IntSliceToString(d.Updates), xml.IntSliceToString(d.Obsoletes)},
)...)
// Depending on the SeriesInfo.Name we're dealing with an RFC or Internet-Draft.
switch d.SeriesInfo.Name {
case "RFC":
attrs = append(attrs, `number="`+d.SeriesInfo.Value+"\"")
case "Internet-Draft": // case sensitive? Or throw error in toml checker?
attrs = append(attrs, `docName="`+d.SeriesInfo.Value+"\"")
case "DOI":
// ?
}
r.outTag(w, "<rfc", attrs)
r.cr(w)
r.outs(w, `<?rfc toc="yes"?>`)
r.outs(w, `<?rfc symrefs="yes"?>`)
r.outs(w, `<?rfc sortrefs="yes"?>`)
r.outs(w, `<?rfc compact="yes"?>`)
r.outs(w, `<?rfc subcompact="no"?>`)
r.outs(w, `<?rfc comments="no"?>`)
r.matter(w, &ast.DocumentMatter{Matter: ast.DocumentMatterFront})
attrs = xml.Attributes([]string{"abbrev"}, []string{d.Abbrev})
r.outTag(w, "<title", attrs)
html.EscapeHTML(w, []byte(d.Title))
r.outs(w, "</title>")
// use a fake xml rendering to hook into the generation of these title elements
// defined there.
faker := xml.NewRenderer(xml.RendererOptions{})
for _, author := range d.Author {
faker.TitleAuthor(w, author)
}
faker.TitleDate(w, d.Date)
r.outs(w, "<area>")
html.EscapeHTML(w, []byte(d.Area))
r.outs(w, "</area>")
r.outs(w, "<workgroup>")
html.EscapeHTML(w, []byte(d.Workgroup))
r.outs(w, "</workgroup>")
faker.TitleKeyword(w, d.Keyword)
// abstract - handled by paragraph
// note - handled by paragraph
// boilerplate - not supported.
return
}