1// Functions and definition to be backwards compatible with RFC7328 markdown. 2 3package mmark 4 5import "bytes" 6 7func (p *parser) rfc7328Index(out *bytes.Buffer, text []byte) int { 8 if p.flags&EXTENSION_RFC7328 == 0 { 9 return 0 10 } 11 text = bytes.TrimSpace(text) 12 // look for ^item1^ subitem 13 if text[0] != '^' || len(text) < 3 { 14 return 0 15 } 16 17 itemEnd := 0 18 for i := 1; i < len(text); i++ { 19 if text[i] == '^' { 20 itemEnd = i 21 break 22 } 23 } 24 if itemEnd == 0 { 25 return 0 26 } 27 28 // Check the sub item, if there. 29 // skip whitespace 30 i := itemEnd + 1 31 for i < len(text) && isspace(text[i]) { 32 i++ 33 } 34 35 // rewind 36 outSize := out.Len() 37 outBytes := out.Bytes() 38 if outSize > 0 && outBytes[outSize-1] == '^' { 39 out.Truncate(outSize - 1) 40 } 41 42 subItemStart := i 43 if subItemStart != len(text) { 44 printf(p, "rfc 7328 style index parsed to: ((%s, %s))", string(text[1:itemEnd]), text[subItemStart:]) 45 p.r.Index(out, text[1:itemEnd], text[subItemStart:], false) 46 return len(text) 47 } 48 printf(p, "rfc 7328 style index parsed to: ((%s))", string(text[1:itemEnd])) 49 p.r.Index(out, text[1:itemEnd], nil, false) 50 return len(text) 51} 52 53func (p *parser) rfc7328Caption(out *bytes.Buffer, text []byte) int { 54 if p.flags&EXTENSION_RFC7328 == 0 { 55 return 0 56 } 57 // Parse stuff like: 58 // ^[fig:minimal::A minimal template.xml.] 59 // If we don't find double colon it is not a inline note masking as a caption 60 text = bytes.TrimSpace(text) 61 colons := bytes.Index(text, []byte("::")) 62 if colons == -1 { 63 return 0 64 } 65 caption := []byte{} 66 anchor := text[:colons] 67 if colons+2 < len(text) { 68 caption = text[colons+2:] 69 } 70 if len(anchor) == 0 && len(caption) == 0 { 71 return 0 72 } 73 74 // rewind 75 outSize := out.Len() 76 outBytes := out.Bytes() 77 if outSize > 0 && outBytes[outSize-1] == '^' { 78 out.Truncate(outSize - 1) 79 } 80 // It is somewhat hard to now go back to the original start of the figure 81 // and marge this new content in (there already may be a #id, etc. etc.). 82 // For now just log that we have seen this line and return a positive integer 83 // indicating this wasn't a footnote. 84 if len(anchor) > 0 { 85 printf(p, "rfc 7328 style anchor seen: consider adding '{#%s}' IAL before the figure/table", string(anchor)) 86 } 87 if len(caption) > 0 { 88 printf(p, "rfc 7328 style caption seen: consider adding 'Figure: %s' or 'Table: %s' after the figure/table", string(caption), string(caption)) 89 } 90 return len(text) 91} 92