]> git.lizzy.rs Git - micro.git/blobdiff - runtime/syntax/syntax_converter.go
Merge branch 'python-highlight-zero' of https://github.com/a11ce/micro into a11ce...
[micro.git] / runtime / syntax / syntax_converter.go
index eb1f426219fc737bf0ab8c6f1073292f9f326cb6..037a4bd4aa48f6c7a41732bf09dae5ed3c6b1188 100644 (file)
@@ -24,7 +24,6 @@ type MultiRule struct {
 func JoinRule(rule string) string {
        split := strings.Split(rule, `" "`)
        joined := strings.Join(split, "|")
-       joined = joined
        return joined
 }
 
@@ -105,11 +104,9 @@ func parseFile(text, filename string) (filetype, syntax, header string, rules []
                        var start string
                        var end string
                        // Use m and s flags by default
-                       flags := "ms"
                        if len(submatch) == 5 {
                                // If len is 5 the user provided some additional flags
                                color = string(submatch[1])
-                               flags += string(submatch[2])
                                start = string(submatch[3])
                                end = string(submatch[4])
                        } else if len(submatch) == 4 {
@@ -135,22 +132,22 @@ func generateFile(filetype, syntax, header string, rules []interface{}) string {
        output := ""
 
        output += fmt.Sprintf("filetype: %s\n\n", filetype)
-       output += fmt.Sprintf("detect: \n\tfilename: \"%s\"\n", strings.Replace(syntax, "\\", "\\\\", -1))
+       output += fmt.Sprintf("detect: \n    filename: \"%s\"\n", strings.Replace(strings.Replace(syntax, "\\", "\\\\", -1), "\"", "\\\"", -1))
 
        if header != "" {
-               output += fmt.Sprintf("\theader: \"%s\"\n", strings.Replace(header, "\\", "\\\\", -1))
+               output += fmt.Sprintf("    header: \"%s\"\n", strings.Replace(strings.Replace(header, "\\", "\\\\", -1), "\"", "\\\"", -1))
        }
 
        output += "\nrules:\n"
 
        for _, r := range rules {
                if rule, ok := r.(SingleRule); ok {
-                       output += fmt.Sprintf("\t- %s: \"%s\"\n", rule.color, strings.Replace(strings.Replace(rule.regex, "\\", "\\\\", -1), "\"", "\\\"", -1))
+                       output += fmt.Sprintf("    - %s: \"%s\"\n", rule.color, strings.Replace(strings.Replace(rule.regex, "\\", "\\\\", -1), "\"", "\\\"", -1))
                } else if rule, ok := r.(MultiRule); ok {
-                       output += fmt.Sprintf("\t- %s:\n", rule.color)
-                       output += fmt.Sprintf("\t\tstart: \"%s\"\n", rule.start)
-                       output += fmt.Sprintf("\t\tend: \"%s\"\n", rule.end)
-                       output += fmt.Sprintf("\t\trules: []\n\n")
+                       output += fmt.Sprintf("    - %s:\n", rule.color)
+                       output += fmt.Sprintf("        start: \"%s\"\n", strings.Replace(strings.Replace(rule.start, "\\", "\\\\", -1), "\"", "\\\"", -1))
+                       output += fmt.Sprintf("        end: \"%s\"\n", strings.Replace(strings.Replace(rule.end, "\\", "\\\\", -1), "\"", "\\\"", -1))
+                       output += fmt.Sprintf("        rules: []\n\n")
                }
        }