-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlib.go
84 lines (72 loc) · 1.94 KB
/
lib.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"os"
"fmt"
"strings"
"io/ioutil"
)
func copyMap(mapOrignal map[string]string) map[string]string {
var mapCopy = make(map[string]string)
for key, value := range mapOrignal {
mapCopy[key] = value
}
return mapCopy
}
func strMultiply(strText string, times int) string {
var strFinal string
for loop := 0; loop < times; loop = loop + 1 {
strFinal = strFinal + strText
}
return strFinal
}
func setTheme(content string, themeName string) string {
for colName, colCode := range themes[themeName] {
content = strings.Replace(content, colName, colCode, -1)
}
pageProp["pBGcolor"] = themes[themeName]["bg"]
return content
}
func getSourceName() string {
if len(os.Args) == 1 {
return ""
}
return os.Args[1]
}
func makeHTML(file string) string {
fileName := strings.Split(file, ".")
if len(fileName) == 1 {
var htmlName string = file + ".html"
return htmlName
}
fileName[len(fileName) - 1] = ".html"
var htmlName string = strings.Join(fileName, "")
return htmlName
}
func splitFileText(file string) []string {
byteStream, err := ioutil.ReadFile(file)
if err != nil {
fmt.Printf("Invalid file address: %s\n", file)
os.Exit(2)
}
var script string = string(byteStream)
lines := strings.Split(strings.TrimSpace(script), "\n")
return lines
}
func makeHTMLfile(sourceFile string, htmlContent string) {
var htmlFileName string = makeHTML(sourceFile)
htmlFile, err := os.Create(htmlFileName)
if err != nil {
fmt.Printf(messageTemplates["fileNotFoundError"], htmlFileName, htmlContent)
os.Exit(3)
}
htmlFile.WriteString(htmlContent)
htmlFile.Close()
}
func readFileForHTML(file string, tabNo int) string {
textFile, _ := ioutil.ReadFile(file)
var fileContent string = string(textFile)
fileContent = strings.Replace(fileContent, "\n", "<br>", -1)
fileContent = strings.Replace(fileContent, " ", " ", -1)
fileContent = strings.Replace(fileContent, "\t", strMultiply(" ", tabNo), -1)
return fileContent
}