htmltools

Various command line tools to transform HTML documents
git clone git://git.entf.net/htmltools
Log | Files | Refs | README | LICENSE

main.go (555B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"os"
      6 	"strconv"
      7 
      8 	"golang.org/x/net/html"
      9 
     10 	"entf.net/htmltools"
     11 	"entf.net/htmltools/cmd"
     12 )
     13 
     14 const usage = "usage: htmlindentheadings INDENT_LEVELS [FILES...]"
     15 
     16 func main() {
     17 	args := os.Args[1:]
     18 	if len(args) == 0 {
     19 		fmt.Println(usage)
     20 		os.Exit(1)
     21 	}
     22 	lvls, err := strconv.Atoi(args[0])
     23 	if err != nil {
     24 		fmt.Println(usage)
     25 		os.Exit(1)
     26 	}
     27 	cmd.Main(args[1:], func(doc *html.Node) {
     28 		for node := range htmltools.FindRecursive(doc, nil) {
     29 			htmltools.IndentHeadings(lvls, node)
     30 		}
     31 		html.Render(os.Stdout, doc)
     32 	})
     33 }