@@ -7,8 +7,11 @@ import (
7
7
"path/filepath"
8
8
"regexp"
9
9
"strings"
10
+ "bufio"
11
+ // "net/http"
12
+ // "github.com/fairlyblank/md2min"
13
+ "github.com/a8m/mark"
10
14
11
- "github.com/fairlyblank/md2min"
12
15
)
13
16
14
17
// 定义一个访问者结构体
@@ -17,6 +20,8 @@ type Visitor struct{}
17
20
func (self * Visitor ) md2html (arg map [string ]string ) error {
18
21
from := arg ["from" ]
19
22
to := arg ["to" ]
23
+ s := `<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
24
+ `
20
25
err := filepath .Walk (from + "/" , func (path string , f os.FileInfo , err error ) error {
21
26
if f == nil {
22
27
return err
@@ -62,8 +67,39 @@ func (self *Visitor) md2html(arg map[string]string) error {
62
67
os .Exit (- 1 )
63
68
}
64
69
defer out .Close ()
65
- md := md2min .New ("none" )
66
- err = md .Parse ([]byte (input ), out )
70
+ opts := mark .DefaultOptions ()
71
+ opts .Smartypants = true
72
+ opts .Fractions = true
73
+ // r1 := []rune(s1)
74
+ m := mark .New (input , opts )
75
+ // md := md2min.New("none")
76
+ // err = md.Parse([]byte(input), out)
77
+ // client := &http.Client{}
78
+
79
+ // req, err := http.NewRequest("POST", "https://api.github.com/markdown/raw", strings.NewReader(input))
80
+ // if err != nil {
81
+ // handle error
82
+ // }
83
+
84
+ // req.Header.Set("Content-Type", "text/plain")
85
+ // req.Header.Set("charset", "utf-8")
86
+ // req.Header.Set("User-Agent", "m2shad0w")
87
+ //
88
+ // resp, err := client.Do(req)
89
+
90
+ // defer resp.Body.Close()
91
+
92
+ // body, err := ioutil.ReadAll(resp.Body)
93
+ // if err != nil {
94
+ // handle error
95
+ // }
96
+
97
+ w := bufio .NewWriter (out )
98
+ n4 , err := w .WriteString (s + m .Render ())
99
+ fmt .Printf ("wrote %d bytes\n " , n4 )
100
+ // fmt.Printf("wrote %d bytes\n", n4)
101
+ //使用 Flush 来确保所有缓存的操作已写入底层写入器。
102
+ w .Flush ()
67
103
if err != nil {
68
104
fmt .Fprintln (os .Stderr , "Parsing Error" , err )
69
105
os .Exit (- 1 )
0 commit comments