forked from miekg/mmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toml.go
105 lines (89 loc) · 2.23 KB
/
toml.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package mmark
import (
"bytes"
"time"
"github.com/BurntSushi/toml"
)
const (
// Sentinal for not set.
piNotSet = "__mmark_toml_pi_not_set"
DefaultIpr = "trust200902"
DefaultArea = "Internet"
)
type author struct {
Initials string
Surname string
Fullname string
Organization string
OrganizationAbbrev string `toml:"abbrev"`
Role string
Ascii string
Address address
}
type address struct {
Phone string
Email string
Uri string
Postal addressPostal
}
type addressPostal struct {
Street string
City string
Code string
Country string
Region string
PostalLine []string
// Plurals when these need to be specified multiple times.
Streets []string
Cities []string
Codes []string
Countries []string
Regions []string
}
// PIs the processing instructions.
var PIs = []string{"toc", "symrefs", "sortrefs", "compact", "subcompact", "private", "topblock", "header", "footer", "comments"}
type pi struct {
Toc string
Symrefs string
Sortrefs string
Compact string
Subcompact string
Private string
Topblock string
Comments string // Typeset cref's in the text.
Header string // Top-Left header, usually Internet-Draft.
Footer string // Bottom-Center footer, usually Expires ...
}
type title struct {
Title string
Abbrev string
DocName string
Ipr string
Category string
Number int // RFC number
Obsoletes []int
Updates []int
PI pi // Processing Instructions
SubmissionType string
Date time.Time
Area string
Workgroup string
Keyword []string
Author []author
}
func (p *parser) titleBlockTOML(out *bytes.Buffer, data []byte) title {
data = bytes.TrimPrefix(data, []byte("%"))
data = bytes.Replace(data, []byte("\n%"), []byte("\n"), -1)
// Set some sentinels and defaults.
var block title
block.PI.Header = piNotSet
block.PI.Footer = piNotSet
block.Area = DefaultArea
block.Ipr = DefaultIpr
block.Date = time.Now()
if _, err := toml.Decode(string(data), &block); err != nil {
printf(p, "error in TOML titleblock: %s", err.Error())
return block // never an error when encoding markdown
}
return block
}