From 2c52c00f8287e2b6764bbb1f14c9b07f1d2ccb3b Mon Sep 17 00:00:00 2001 From: fengxxc Date: Thu, 2 Dec 2021 19:30:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0markdown=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=88=B0=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=92=8C=E7=A8=8B=E5=BA=8F=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- format/format.go | 6 ++++++ main.go | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/format/format.go b/format/format.go index 1393803..0e885a9 100644 --- a/format/format.go +++ b/format/format.go @@ -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"]) diff --git a/main.go b/main.go index 9a1eb29..a92b3f1 100644 --- a/main.go +++ b/main.go @@ -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) }