5// Convert eid html file, e.g. https://www.rfc-editor.org/errata/eid3192 to text with leading blank line for references.
 
6// See Makefile, run with "go run errata.go < eid.html >eid.txt"
 
7// I could not find a source for the text version of errata.
 
15	"golang.org/x/net/html"
 
18func xcheckf(err error, format string, args ...any) {
 
20		log.Fatalf("%s: %s", fmt.Sprintf(format, args...), err)
 
26	doc, err := html.Parse(os.Stdin)
 
27	xcheckf(err, "parsing html")
 
28	out := bufio.NewWriter(os.Stdout)
 
29	_, err = out.WriteString("\n") // First line for references.
 
32	// We will visit the html nodes. We skip <form>'s. We turn on text
 
33	// output when we encounter an h4, and we stop again when we see a div
 
34	// or form. This works at the moment, but may break in the future.
 
36	var walk func(*html.Node)
 
37	walk = func(n *html.Node) {
 
38		if n.Type == html.ElementNode {
 
42			if !output && n.Data == "h4" {
 
44			} else if output && (n.Data == "div" || n.Data == "form") {
 
48		if output && n.Type == html.TextNode {
 
49			_, err := out.WriteString(n.Data)
 
52		for c := n.FirstChild; c != nil; c = c.NextSibling {