File: domutils.go

package info (click to toggle)
golang-github-johanneskaufmann-html-to-markdown 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: makefile: 3
file content (43 lines) | stat: -rw-r--r-- 836 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package domutils

import (
	"github.com/JohannesKaufmann/dom"
	"golang.org/x/net/html"
)

func getNextTextNode(startNode *html.Node) *html.Node {
	node := dom.GetNextNeighborNodeExcludingOwnChild(startNode)

	for node != nil {
		if node.Type == html.TextNode {
			return node
		}

		if dom.NodeName(node) == "span" {
			// A span has no special meaning. So we just skip it...
			node = dom.GetNextNeighborNode(node)
			continue
		}

		return nil
	}
	return nil
}
func getPrevTextNode(startNode *html.Node) *html.Node {
	node := dom.GetPrevNeighborNodeExcludingOwnChild(startNode)

	for node != nil {
		if node.Type == html.TextNode {
			return node
		}

		if dom.NodeName(node) == "span" {
			// A span has no special meaning. So we just skip it...
			node = dom.GetPrevNeighborNode(node)
			continue
		}

		return nil
	}
	return nil
}