summaryrefslogtreecommitdiff
path: root/inline_parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'inline_parser.go')
-rw-r--r--inline_parser.go61
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 {