mirror of
https://github.com/fengxxc/wechatmp2markdown.git
synced 2026-04-20 18:57:53 +08:00
feat: 添加markdown保存到文件的方法和程序入口
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package format
|
package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/fengxxc/wechatmp2markdown/parse"
|
"github.com/fengxxc/wechatmp2markdown/parse"
|
||||||
@@ -19,6 +20,11 @@ func Format(article parse.Article) string {
|
|||||||
return result
|
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 {
|
func formatTitle(piece parse.Piece) string {
|
||||||
var prefix string
|
var prefix string
|
||||||
level, _ := strconv.Atoi(piece.Attrs["level"])
|
level, _ := strconv.Atoi(piece.Attrs["level"])
|
||||||
|
|||||||
19
main.go
19
main.go
@@ -1,8 +1,23 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/fengxxc/wechatmp2markdown/test"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fengxxc/wechatmp2markdown/format"
|
||||||
|
"github.com/fengxxc/wechatmp2markdown/parse"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// test.Test1()
|
// 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user