diff options
| author | Shulhan <ms@kilabit.info> | 2024-10-15 12:36:20 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-10-15 12:37:13 +0700 |
| commit | 2ea376671b1975392252bc6f70497c54d4bbab16 (patch) | |
| tree | e2f88ef4203c82e21d0b27e593dca92f18bfdf92 /element.go | |
| parent | c8eb463345633a1816f97cc967d104127cc4c5f4 (diff) | |
| download | asciidoctor-go-2ea376671b1975392252bc6f70497c54d4bbab16.tar.xz | |
all: group all image related method and functions into single file
This is to make it easy to see how it parsed and how it written to HTML,
make the code more searchable.
While at it, add test for block image.
Diffstat (limited to 'element.go')
| -rw-r--r-- | element.go | 94 |
1 files changed, 0 insertions, 94 deletions
@@ -301,100 +301,6 @@ func (el *element) parseBlockAudio(doc *Document, line []byte) bool { return true } -// parseBlockImage parse the image block or line. -// The line parameter must not have "image::" block or "image:" macro prefix. -func (el *element) parseBlockImage(doc *Document, line []byte) bool { - var ( - attrBegin = bytes.IndexByte(line, '[') - - attr string - key string - val string - kv []string - - attrs [][]byte - src []byte - battr []byte - alt []byte - - attrEnd int - dot int - x int - ) - - if attrBegin < 0 { - return false - } - attrEnd = bytes.IndexByte(line, ']') - if attrEnd < 0 { - return false - } - - src = bytes.TrimRight(line[:attrBegin], " \t") - - if el.Attrs == nil { - el.Attrs = make(map[string]string) - } - src = applySubstitutions(doc, src) - el.Attrs[attrNameSrc] = string(src) - - attrs = bytes.Split(line[attrBegin+1:attrEnd], []byte(`,`)) - if el.Attrs == nil { - el.Attrs = make(map[string]string) - } - var hasWidth bool - for x, battr = range attrs { - attr = string(battr) - if x == 0 { - alt = bytes.TrimSpace(attrs[0]) - if len(alt) == 0 { - dot = bytes.IndexByte(src, '.') - if dot > 0 { - alt = src[:dot] - } - } - el.Attrs[attrNameAlt] = string(alt) - continue - } - if x == 1 { - if ascii.IsDigits(attrs[1]) { - el.Attrs[attrNameWidth] = string(attrs[1]) - hasWidth = true - continue - } - } - if hasWidth && x == 2 { - if ascii.IsDigits(attrs[2]) { - el.Attrs[attrNameHeight] = string(attrs[2]) - } - } - kv = strings.SplitN(attr, `=`, 2) - if len(kv) != 2 { - continue - } - key = strings.TrimSpace(kv[0]) - val = strings.Trim(kv[1], `"`) - switch key { - case attrNameFloat, attrNameAlign, attrNameRole: - if val == `center` { - val = `text-center` - } - el.addRole(val) - default: - el.Attrs[key] = val - } - } - - for key, val = range el.Attrs { - if key == attrNameLink { - val = string(applySubstitutions(doc, []byte(val))) - el.Attrs[key] = val - } - } - - return true -} - func (el *element) parseInlineMarkup(doc *Document, kind int) { if len(el.raw) == 0 { return |
