diff options
| author | Shulhan <ms@kilabit.info> | 2022-10-20 04:48:20 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-10-20 22:09:31 +0700 |
| commit | 26c0d32b05eefb9b7040be69717d58e62bbdac2f (patch) | |
| tree | 86d02f3bd444b5148733cee1dca2756bff1c1f3a /inline_parser.go | |
| parent | dc6f1e2a3e720b706dbf945ae6b608199f630fb4 (diff) | |
| download | asciidoctor-go-26c0d32b05eefb9b7040be69717d58e62bbdac2f.tar.xz | |
all: implement macro "footnote:"
Macro footnote grammar,
----
"footnote:" [ REF_ID ] "[" STRING "]"
----
In asciidoctor, footnote can be placed anywhere, even after WORD without
space in between.
The REF_ID, define the unique ID for footnote and can be used to reference
the previous footnote.
The first footnote with REF_ID, should have the STRING defined.
The next footnote with the same REF_ID, should not have the STRING
defined; if its defined, the STRING is ignored.
Diffstat (limited to 'inline_parser.go')
| -rw-r--r-- | inline_parser.go | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/inline_parser.go b/inline_parser.go index 881374e..eea1e39 100644 --- a/inline_parser.go +++ b/inline_parser.go @@ -397,20 +397,6 @@ func (pi *inlineParser) escape() { pi.prev = pi.c } -func (pi *inlineParser) getBackMacroName() (macroName string, lastc byte) { - var ( - raw []byte = pi.current.raw - start int = len(raw) - 1 - ) - for start >= 0 { - if !ascii.IsAlpha(raw[start]) { - return string(raw[start+1:]), raw[start] - } - start-- - } - return string(raw), 0 -} - func (pi *inlineParser) parseCrossRef() bool { var ( raw []byte = pi.content[pi.x+2:] @@ -729,51 +715,48 @@ func (pi *inlineParser) parseInlineImage() *element { func (pi *inlineParser) parseMacro() bool { var ( - el *element - name string - lastc byte + el *element + name string + n int ) - name, lastc = pi.getBackMacroName() - if lastc == '\\' || len(name) == 0 { + name = pi.parseMacroName(pi.current.raw) + if len(name) == 0 { return false } switch name { - case ``: - return false - case macroFTP, macroHTTPS, macroHTTP, macroIRC, macroLink, macroMailto: - el = pi.parseURL(name) + case macroFootnote: + el, n = pi.parseMacroFootnote(pi.content[pi.x+1:]) if el == nil { return false } - pi.current.raw = pi.current.raw[:len(pi.current.raw)-len(name)] + pi.x += n + pi.prev = 0 - pi.current.addChild(el) - el = &element{ - kind: elKindText, + case macroFTP, macroHTTPS, macroHTTP, macroIRC, macroLink, macroMailto: + el = pi.parseURL(name) + if el == nil { + return false } - pi.current.addChild(el) - pi.current = el - return true + case macroImage: el = pi.parseInlineImage() if el == nil { return false } + } - pi.current.raw = pi.current.raw[:len(pi.current.raw)-len(name)] + pi.current.raw = pi.current.raw[:len(pi.current.raw)-len(name)] - pi.current.addChild(el) - el = &element{ - kind: elKindText, - } - pi.current.addChild(el) - pi.current = el - return true + pi.current.addChild(el) + el = &element{ + kind: elKindText, } - return false + pi.current.addChild(el) + pi.current = el + return true } func (pi *inlineParser) parsePassthrough() bool { |
