Explore other html renders but find nothing
parent
0e9150b8f6
commit
b975a7c103
|
|
@ -12,10 +12,13 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/fairlyblank/md2min"
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/ast"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
"github.com/yuin/goldmark"
|
||||
blackfriday "gopkg.in/russross/blackfriday.v2"
|
||||
)
|
||||
|
||||
func (n *Notes) File(urlPath string) (string, error) {
|
||||
|
|
@ -24,10 +27,36 @@ func (n *Notes) File(urlPath string) (string, error) {
|
|||
return "", errors.New("path is dir")
|
||||
}
|
||||
b, _ := ioutil.ReadFile(p.Local)
|
||||
return n.gomarkdown(urlPath, b) + "\n", nil
|
||||
return n.gomarkdown(urlPath, b)
|
||||
return n.blackfriday(urlPath, b)
|
||||
return n.goldmark(urlPath, b)
|
||||
return n.md2min(urlPath, b)
|
||||
}
|
||||
|
||||
func (n *Notes) gomarkdown(urlPath string, b []byte) string {
|
||||
func (n *Notes) blackfriday(urlPath string, b []byte) (string, error) {
|
||||
renderer := blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{
|
||||
Flags: blackfriday.TOC | blackfriday.Smartypants | blackfriday.SmartypantsFractions | blackfriday.SmartypantsDashes | blackfriday.SmartypantsQuotesNBSP | blackfriday.CompletePage,
|
||||
})
|
||||
return string(blackfriday.Run(
|
||||
b,
|
||||
blackfriday.WithRenderer(renderer),
|
||||
)), nil
|
||||
}
|
||||
|
||||
func (n *Notes) goldmark(urlPath string, b []byte) (string, error) {
|
||||
buff := bytes.NewBuffer(nil)
|
||||
err := goldmark.Convert(b, buff)
|
||||
return string(buff.Bytes()), err
|
||||
}
|
||||
|
||||
func (n *Notes) md2min(urlPath string, b []byte) (string, error) {
|
||||
mdc := md2min.New("h1")
|
||||
buff := bytes.NewBuffer(nil)
|
||||
err := mdc.Parse(b, buff)
|
||||
return string(buff.Bytes()), err
|
||||
}
|
||||
|
||||
func (n *Notes) gomarkdown(urlPath string, b []byte) (string, error) {
|
||||
renderer := html.NewRenderer(html.RendererOptions{
|
||||
Flags: html.CommonFlags | html.TOC,
|
||||
RenderNodeHook: n.commentFormer(urlPath, b),
|
||||
|
|
@ -52,7 +81,7 @@ func (n *Notes) gomarkdown(urlPath string, b []byte) string {
|
|||
}
|
||||
parser := parser.NewWithExtensions(ext)
|
||||
content := markdown.ToHTML(b, parser, renderer)
|
||||
return string(content)
|
||||
return string(content) + "\n", nil
|
||||
}
|
||||
|
||||
func (n *Notes) commentFormer(urlPath string, md []byte) html.RenderNodeFunc {
|
||||
|
|
|
|||
Loading…
Reference in New Issue