Better support for XML and HTML

Keep <?xml and <!doctype declarations.
This commit is contained in:
alex
2018-07-21 16:57:39 +02:00
parent fbdca00396
commit 071b332aa8
4 changed files with 39 additions and 3 deletions

14
main.go
View File

@@ -24,6 +24,7 @@ import (
"log"
"os"
"path/filepath"
"strings"
"sync"
"time"
)
@@ -155,6 +156,12 @@ func addLicense(path string, fmode os.FileMode, typ string, data *copyrightData)
return ioutil.WriteFile(path, b, fmode)
}
var head = []string{
"#!", // shell script
"<?xml", // XML declaratioon
"<!doctype", // HTML doctype
}
func hashBang(b []byte) []byte {
var line []byte
for _, c := range b {
@@ -163,8 +170,11 @@ func hashBang(b []byte) []byte {
break
}
}
if bytes.HasPrefix(line, []byte("#!")) {
return line
first := strings.ToLower(string(line))
for _, h := range head {
if strings.HasPrefix(first, h) {
return line
}
}
return nil
}