From b975a7c10311e80c8f9c9c82c495c3e7211ddf6c Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sun, 27 Sep 2020 11:35:55 -0600 Subject: [PATCH] Explore other html renders but find nothing --- notes/file.go | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/notes/file.go b/notes/file.go index cdcb0fa..23d8971 100755 --- a/notes/file.go +++ b/notes/file.go @@ -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 {