Created
October 1, 2016 03:04
-
-
Save ronoaldo/b9080df67208bfb8e99b7e76816f3c4b to your computer and use it in GitHub Desktop.
datamine2html.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"bufio" | |
"os" | |
"strings" | |
"regexp" | |
) | |
var ( | |
openColorRe = regexp.MustCompile("\\[c\\]\\[([a-zA-Z0-9]+)\\]") | |
closeColorRe = regexp.MustCompile("\\[-\\]\\[/c\\]") | |
) | |
func formatMsg(src string) string { | |
src = strings.Replace(src, "\\n", "<br>", -1) | |
src = openColorRe.ReplaceAllString(src, "<b>") | |
src = closeColorRe.ReplaceAllString(src, "</b>") | |
return src | |
} | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
line := scanner.Text() | |
parts := strings.Split(line, "|") | |
var key, msg string | |
switch len(parts) { | |
case 0: | |
continue | |
case 1: | |
key, msg = parts[0], "" | |
case 2: | |
key, msg = parts[0], parts[1] | |
default: | |
key, msg = parts[0], strings.Join(parts[1:], "|") | |
} | |
fmt.Printf("<i><code>%s</code></i><br/>", key) | |
fmt.Printf("<p>%s</p>", formatMsg(msg)) | |
fmt.Printf("<hr>") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment