Merge commit 'ba897245c3f633fb45d2370eb270283f31a0dd80' into ja
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
*~
|
*~
|
||||||
pkg/*
|
pkg/*
|
||||||
*.html
|
*.html
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/russross/blackfriday"
|
"github.com/fairlyblank/md2min"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// 定义一个访问者结构体
|
// 定义一个访问者结构体
|
||||||
type Visitor struct{}
|
type Visitor struct {}
|
||||||
|
|
||||||
func (self *Visitor) visit(path string, f os.FileInfo, err error) error {
|
func (self *Visitor) visit(path string, f os.FileInfo, err error) error {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
@@ -30,21 +30,18 @@ func (self *Visitor) visit(path string, f os.FileInfo, err error) error {
|
|||||||
}
|
}
|
||||||
input, _ := ioutil.ReadAll(file)
|
input, _ := ioutil.ReadAll(file)
|
||||||
input = regexp.MustCompile("\\[(.*?)\\]\\(<?(.*?)\\.md>?\\)").ReplaceAll(input, []byte("[$1](<$2.html>)"))
|
input = regexp.MustCompile("\\[(.*?)\\]\\(<?(.*?)\\.md>?\\)").ReplaceAll(input, []byte("[$1](<$2.html>)"))
|
||||||
output := blackfriday.MarkdownCommon(input)
|
|
||||||
var out *os.File
|
var out *os.File
|
||||||
if out, err = os.Create(strings.Replace(f.Name(), ".md", ".html", -1)); err != nil {
|
if out, err = os.Create(strings.Replace(f.Name(), ".md", ".html", -1)); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error creating %s: %v", f.Name(), err)
|
fmt.Fprintf(os.Stderr, "Error creating %s: %v", f.Name(), err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
defer out.Close()
|
defer out.Close()
|
||||||
header := "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\"/>\n</head>\n"
|
md := md2min.New("none")
|
||||||
footer := "</html>\n"
|
err = md.Parse(input, out)
|
||||||
out.Write([]byte(header))
|
if err != nil {
|
||||||
if _, err = out.Write(output); err != nil {
|
fmt.Fprintln(os.Stderr, "Parsing Error", err)
|
||||||
fmt.Fprintln(os.Stderr, "Error writing output:", err)
|
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
out.Write([]byte(footer))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user