diff --git a/zh/build.go b/zh/build.go index 63ac526d..175cc789 100644 --- a/zh/build.go +++ b/zh/build.go @@ -1,17 +1,14 @@ package main import ( + "bufio" "fmt" + "github.com/a8m/mark" "io/ioutil" "os" "path/filepath" "regexp" "strings" - "bufio" - // "net/http" - // "github.com/fairlyblank/md2min" - "github.com/a8m/mark" - ) // 定义一个访问者结构体 @@ -71,35 +68,11 @@ func (self *Visitor) md2html(arg map[string]string) error { opts.Smartypants = true opts.Fractions = true // r1 := []rune(s1) - m := mark.New(input, opts) - // md := md2min.New("none") - // err = md.Parse([]byte(input), out) - // client := &http.Client{} - - // req, err := http.NewRequest("POST", "https://api.github.com/markdown/raw", strings.NewReader(input)) - // if err != nil { - // handle error - // } - - // req.Header.Set("Content-Type", "text/plain") - // req.Header.Set("charset", "utf-8") - // req.Header.Set("User-Agent", "m2shad0w") - // - // resp, err := client.Do(req) - - // defer resp.Body.Close() - - // body, err := ioutil.ReadAll(resp.Body) - // if err != nil { - // handle error - // } - + m := mark.New(input, opts w := bufio.NewWriter(out) - n4, err := w.WriteString(s + m.Render()) - fmt.Printf("wrote %d bytes\n", n4) - // fmt.Printf("wrote %d bytes\n", n4) - //使用 Flush 来确保所有缓存的操作已写入底层写入器。 - w.Flush() + n4, err := w.WriteString(s + m.Render()) + fmt.Printf("wrote %d bytes\n", n4) + w.Flush() if err != nil { fmt.Fprintln(os.Stderr, "Parsing Error", err) os.Exit(-1) diff --git a/zh/build.sh b/zh/build.sh index bf383065..2deb646c 100755 --- a/zh/build.sh +++ b/zh/build.sh @@ -15,7 +15,7 @@ WORKDIR="$(cd $(dirname $0); pwd -P)" # MSG_INSTALL_PANDOC_FIRST='请先安装pandoc,然后再次运行' MSG_SUCCESSFULLY_GENERATED='build-web-application-with-golang.epub 已经建立' -MSG_CREATOR='M2shad0w' +MSG_CREATOR='Astaxie' MSG_DESCRIPTION='一本开源的Go Web编程书籍' MSG_LANGUAGE='zh-CN' MSG_TITLE='Go Web编程' diff --git a/zh/build_new.go b/zh/build_new.go index a74bb4d4..d4400fb9 100644 --- a/zh/build_new.go +++ b/zh/build_new.go @@ -3,15 +3,16 @@ package main import ( "fmt" "io/ioutil" + "net/http" "os" "path/filepath" "regexp" "strings" - "bufio" - "net/http" ) +// 开发者 github token const token = "" + // 定义一个访问者结构体 type Visitor struct{} @@ -66,31 +67,31 @@ func (self *Visitor) md2html(arg map[string]string) error { } defer out.Close() client := &http.Client{} - - req, err := http.NewRequest("POST", "https://api.github.com/markdown/raw", strings.NewReader(input)) - if err != nil { - // handle error - } - - req.Header.Set("Content-Type", "text/plain") - req.Header.Set("charset", "utf-8") - req.Header.Set("Authorization", "token " + token) - // - resp, err := client.Do(req) - - defer resp.Body.Close() - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - // handle error - } + + req, err := http.NewRequest("POST", "https://api.github.com/markdown/raw", strings.NewReader(input)) + if err != nil { + // handle error + } + + req.Header.Set("Content-Type", "text/plain") + req.Header.Set("charset", "utf-8") + req.Header.Set("Authorization", "token "+token) + // + resp, err := client.Do(req) + + defer resp.Body.Close() + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + // handle error + } w := bufio.NewWriter(out) - n4, err := w.WriteString(s + string(body)) //m.Render() - fmt.Printf("wrote %d bytes\n", n4) - // fmt.Printf("wrote %d bytes\n", n4) - //使用 Flush 来确保所有缓存的操作已写入底层写入器。 - w.Flush() + n4, err := w.WriteString(s + string(body)) //m.Render() + fmt.Printf("wrote %d bytes\n", n4) + // fmt.Printf("wrote %d bytes\n", n4) + //使用 Flush 来确保所有缓存的操作已写入底层写入器。 + w.Flush() if err != nil { fmt.Fprintln(os.Stderr, "Parsing Error", err) os.Exit(-1)