File: elem_code.go

package info (click to toggle)
golang-github-johanneskaufmann-html-to-markdown 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,080 kB
  • sloc: makefile: 3
file content (45 lines) | stat: -rw-r--r-- 634 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package escape

func IsFencedCode(chars []byte, index int) int {
	if chars[index] != '`' && chars[index] != '~' {
		return -1
	}

	for i := index - 1; i >= 0; i-- {
		if chars[i] == ' ' || chars[i] == placeholderByte {
			continue
		}
		if chars[i] == '\n' {
			break
		}

		return -1
	}

	count := 1
	i := index + 1
	for ; i < len(chars); i++ {
		if chars[i] == placeholderByte {
			continue
		}
		if chars[i] == '`' || chars[i] == '~' {
			count++
			continue
		}

		break
	}
	if count < 3 {
		return -1
	}

	return i - index
}

func IsInlineCode(chars []byte, index int) int {
	if chars[index] != '`' {
		return -1
	}

	return 1
}