diff --git a/zh/build-web-application-with-golang.epub b/zh/build-web-application-with-golang.epub index bc463b43..324ff9d4 100644 Binary files a/zh/build-web-application-with-golang.epub and b/zh/build-web-application-with-golang.epub differ diff --git a/zh/build.go b/zh/build.go index fbf7e662..63ac526d 100644 --- a/zh/build.go +++ b/zh/build.go @@ -7,8 +7,11 @@ import ( "path/filepath" "regexp" "strings" + "bufio" + // "net/http" + // "github.com/fairlyblank/md2min" + "github.com/a8m/mark" - "github.com/fairlyblank/md2min" ) // 定义一个访问者结构体 @@ -17,6 +20,8 @@ type Visitor struct{} func (self *Visitor) md2html(arg map[string]string) error { from := arg["from"] to := arg["to"] + s := ` +` err := filepath.Walk(from+"/", func(path string, f os.FileInfo, err error) error { if f == nil { return err @@ -62,8 +67,39 @@ func (self *Visitor) md2html(arg map[string]string) error { os.Exit(-1) } defer out.Close() - md := md2min.New("none") - err = md.Parse([]byte(input), out) + opts := mark.DefaultOptions() + 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 + // } + + 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() if err != nil { fmt.Fprintln(os.Stderr, "Parsing Error", err) os.Exit(-1) diff --git a/zh/build.sh b/zh/build.sh index 4f4f7a76..bf383065 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='Astaxie' +MSG_CREATOR='M2shad0w' MSG_DESCRIPTION='一本开源的Go Web编程书籍' MSG_LANGUAGE='zh-CN' MSG_TITLE='Go Web编程' @@ -23,14 +23,15 @@ MSG_TITLE='Go Web编程' TMP=`mktemp -d 2>/dev/null || mktemp -d -t "${bn}"` || exit 1 -trap 'rm -rf "$TMP"' 0 1 2 3 15 +# TMP=./build +# trap 'rm -rf "$TMP"' 0 1 2 3 15 cd "$TMP" ( -[ go list github.com/fairlyblank/md2min >/dev/null 2>&1 ] || export GOPATH="$PWD" -go get -u github.com/fairlyblank/md2min +[ go list github.com/a8m/mark >/dev/null 2>&1 ] || export GOPATH="$PWD" +go get -u github.com/a8m/mark WORKDIR="$WORKDIR" TMP="$TMP" go run "$WORKDIR/build.go" ) @@ -51,6 +52,8 @@ mkdir -p $TMP/images cp -r $WORKDIR/images/* $TMP/images/ ls [0-9]*.html | xargs $SED -i "s/png?raw=true/png/g" -pandoc --reference-links -S --toc -f html -t epub --epub-metadata=metadata.txt --epub-cover-image="$WORKDIR/images/cover.png" -o "$WORKDIR/../build-web-application-with-golang.epub" `ls [0-9]*.html | sort` +echo "工作目录$WORKDIR, 临时目录$TMP" + +pandoc --reference-links -S --toc -f html -t epub --epub-metadata=metadata.txt --epub-cover-image="$WORKDIR/images/cover.png" -o "$WORKDIR/build-web-application-with-golang.epub" `ls [0-9]*.html | sort` echo "$MSG_SUCCESSFULLY_GENERATED"