feat: 添加markdown保存到文件的方法和程序入口

This commit is contained in:
fengxxc
2021-12-02 19:30:33 +08:00
parent bf54eb7fc5
commit 2c52c00f82
2 changed files with 23 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package format
import (
"io/ioutil"
"strconv"
"github.com/fengxxc/wechatmp2markdown/parse"
@@ -19,6 +20,11 @@ func Format(article parse.Article) string {
return result
}
func FormatAndSave(article parse.Article, filePath string) {
var result string = Format(article)
ioutil.WriteFile(filePath, []byte(result), 0644)
}
func formatTitle(piece parse.Piece) string {
var prefix string
level, _ := strconv.Atoi(piece.Attrs["level"])

19
main.go
View File

@@ -1,8 +1,23 @@
package main
import "github.com/fengxxc/wechatmp2markdown/test"
import (
"fmt"
"os"
"github.com/fengxxc/wechatmp2markdown/format"
"github.com/fengxxc/wechatmp2markdown/parse"
)
func main() {
// test.Test1()
test.Test2()
// test.Test2()
args := os.Args
if len(args) <= 2 {
panic("not enough args")
}
url := args[1]
filename := args[2]
fmt.Printf("url: %s, filename: %s\n", url, filename)
var articleStruct parse.Article = parse.ParseFromURL(url)
format.FormatAndSave(articleStruct, filename)
}