diff options
| author | Shulhan <ms@kilabit.info> | 2025-02-16 15:43:05 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-02-16 15:43:05 +0700 |
| commit | 5aac8b7676140dcb803fc1614334a92698e35429 (patch) | |
| tree | e9066a340db4fd39ce92cb023589c132add70724 /document.go | |
| parent | 8daebbd6b41177ee1e0de79257f162aa4b486766 (diff) | |
| download | asciidoctor-go-5aac8b7676140dcb803fc1614334a92698e35429.tar.xz | |
all: move setting attribute to Document
Some of attribute may depends on property of the Document.
Diffstat (limited to 'document.go')
| -rw-r--r-- | document.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/document.go b/document.go index 29d589e..2ddb3fc 100644 --- a/document.go +++ b/document.go @@ -274,6 +274,43 @@ func (doc *Document) haveHeader() bool { return false } +// setAttribute store the document attribute val by its key. +func (doc *Document) setAttribute(key, val string) (err error) { + if key[0] == '!' { + key = strings.TrimSpace(key[1:]) + delete(doc.Attributes.Entry, key) + return nil + } + var n = len(key) + if key[n-1] == '!' { + key = strings.TrimSpace(key[:n-1]) + delete(doc.Attributes.Entry, key) + return nil + } + + val = strings.TrimSpace(val) + + switch key { + case docAttrLevelOffset: + var offset int64 + offset, err = strconv.ParseInt(val, 10, 32) + if err != nil { + return fmt.Errorf(`Document: setAttribute: %s invalid value %q`, key, val) + } + if val[0] == '+' || val[0] == '-' { + doc.Attributes.LevelOffset += int(offset) + } else { + doc.Attributes.LevelOffset = int(offset) + } + doc.Attributes.Entry[key] = val + + default: + doc.Attributes.Entry[key] = val + } + + return nil +} + func (doc *Document) toHTMLBody(buf *bytes.Buffer, withHeaderFooter bool) { var ( ok bool |
