File: elem_image.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 (36 lines) | stat: -rw-r--r-- 658 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
package escape

func IsImageOrLink(chars []byte, index int) int {
	if chars[index] == '!' {
		return isImageOrLinkStartExclamation(chars, index)
	}
	if chars[index] == '[' {
		return isImageOrLinkStartBracket(chars, index)
	}

	return -1
}

func isImageOrLinkStartExclamation(chars []byte, index int) int {
	nextIndex := index + 1
	if nextIndex < len(chars) && chars[nextIndex] == '[' {
		// It could be the start of an image
		return 1
	}

	return -1
}

func isImageOrLinkStartBracket(chars []byte, index int) int {
	for i := index + 1; i < len(chars); i++ {
		if chars[i] == '\n' {
			return -1
		}

		if chars[i] == ']' {
			return 1
		}
	}

	return -1
}