-
Notifications
You must be signed in to change notification settings - Fork 0
/
document_attribute.go
112 lines (102 loc) · 3.07 KB
/
document_attribute.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
106
107
108
109
110
111
112
// SPDX-FileCopyrightText: 2020 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package asciidoctor
import (
"fmt"
"strconv"
"strings"
)
// List of document attribute.
const (
DocAttrAuthor = `author` // May contain the first author full name only.
DocAttrAuthorNames = `author_names` // List of author full names, separated by comma.
DocAttrDescription = `description`
DocAttrGenerator = `generator`
DocAttrKeywords = `keywords`
docAttrAuthorInitials = `authorinitials`
docAttrDocTitle = `doctitle`
docAttrEmail = attrValueEmail
docAttrFirstName = `firstname`
docAttrIDPrefix = `idprefix`
docAttrIDSeparator = `idseparator`
docAttrLastName = `lastname`
docAttrLastUpdateLabel = `last-update-label`
docAttrLastUpdateValue = `last-update-value`
docAttrLevelOffset = `leveloffset`
docAttrMiddleName = `middlename`
docAttrNoFooter = `nofooter`
docAttrNoHeader = `noheader`
docAttrNoHeaderFooter = `no-header-footer`
docAttrNoTitle = `notitle`
docAttrRevDate = `revdate`
docAttrRevNumber = `revnumber`
docAttrRevRemark = `revremark`
docAttrSectAnchors = `sectanchors`
docAttrSectIDs = `sectids`
docAttrSectLinks = `sectlinks`
docAttrSectNumLevel = `sectnumlevels`
docAttrSectNums = `sectnums`
docAttrShowTitle = `showtitle`
docAttrTOC = `toc`
docAttrTOCLevels = `toclevels`
docAttrTOCTitle = `toc-title`
docAttrTableCaption = `table-caption`
docAttrTitle = attrNameTitle
docAttrTitleSeparator = `title-separator`
docAttrVersionLabel = `version-label`
)
// List of possible document attribute value.
const (
docAttrValueAuto = `auto`
docAttrValueMacro = `macro`
docAttrValuePreamble = `preamble`
docAttrValueLeft = `left`
docAttrValueRight = `right`
)
// DocumentAttribute contains the mapping of global attribute keys in the
// headers with its value.
type DocumentAttribute struct {
Entry map[string]string
LevelOffset int
}
func newDocumentAttribute() DocumentAttribute {
return DocumentAttribute{
Entry: map[string]string{
DocAttrGenerator: `asciidoctor-go ` + Version,
docAttrLastUpdateLabel: `Last updated`,
docAttrLastUpdateValue: ``,
docAttrSectIDs: ``,
docAttrShowTitle: ``,
docAttrTableCaption: ``,
docAttrVersionLabel: ``,
},
}
}
func (docAttr *DocumentAttribute) apply(key, val string) (err error) {
if key[0] == '!' {
key = strings.TrimSpace(key[1:])
delete(docAttr.Entry, key)
return nil
}
var n = len(key)
if key[n-1] == '!' {
key = strings.TrimSpace(key[:n-1])
delete(docAttr.Entry, key)
return nil
}
if key == docAttrLevelOffset {
var offset int64
offset, err = strconv.ParseInt(val, 10, 32)
if err != nil {
return fmt.Errorf(`DocumentAttribute: %s: invalid value %q`, key, val)
}
if val[0] == '+' || val[0] == '-' {
docAttr.LevelOffset += int(offset)
goto valid
}
docAttr.LevelOffset = int(offset)
}
valid:
docAttr.Entry[key] = val
return nil
}