-
Notifications
You must be signed in to change notification settings - Fork 1
/
thesislint.go
58 lines (54 loc) · 1.28 KB
/
thesislint.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"path/filepath"
"sync"
"regexp"
)
func main() {
if err := os.Mkdir("tmp", 0777); err != nil {
if err := os.RemoveAll("tmp"); err != nil {
fmt.Println(err)
}
}
files, err := ioutil.ReadDir("./")
if err != nil {
fmt.Println(err)
os.Exit(1)
} else {
var filenames []string
var wg sync.WaitGroup
for _, f := range files {
file_path := f.Name()
ext := filepath.Ext(file_path)
if ext == ".tex" {
s := strings.Split(file_path, ".")
filename := s[0]
name := filename
filenames = append(filenames, "tmp/" + filename + ".md")
wg.Add(1)
go func() {
exec.Command("cp", name + ".tex", "tmp/" + name + ".md").Run()
// exec.Command("pandoc", "-s", name + ".tex", "-o", "tmp/" + name + ".md").Run()
wg.Done()
}()
}
}
wg.Wait()
var cmd = exec.Command("node_modules/.bin/textlint", "--dry-run")
cmd.Args = filenames
out, _ := cmd.CombinedOutput()
var o = string(out)
var rep = regexp.MustCompile("✖.*\n")
o = rep.ReplaceAllString(o, "\x1b[31m$0\x1b[0m")
rep = regexp.MustCompile(".*.md\n")
o = rep.ReplaceAllString(o, "\x1b[35m$0\x1b[0m")
rep = regexp.MustCompile(" error ")
o = rep.ReplaceAllString(o, "\x1b[31m error \x1b[0m")
fmt.Println(o)
}
}