File: callout.go

package info (click to toggle)
golang-github-gomarkdown-markdown 0.0~git20231115.a660076-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,168 kB
  • sloc: sh: 26; makefile: 5
file content (29 lines) | stat: -rw-r--r-- 546 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package parser

import (
	"bytes"
	"strconv"
)

// IsCallout detects a callout in the following format: <<N>> Where N is a integer > 0.
func IsCallout(data []byte) (id []byte, consumed int) {
	if !bytes.HasPrefix(data, []byte("<<")) {
		return nil, 0
	}
	start := 2
	end := bytes.Index(data[start:], []byte(">>"))
	if end < 0 {
		return nil, 0
	}

	b := data[start : start+end]
	b = bytes.TrimSpace(b)
	i, err := strconv.Atoi(string(b))
	if err != nil {
		return nil, 0
	}
	if i <= 0 {
		return nil, 0
	}
	return b, start + end + 2 // 2 for >>
}