exporterer
parent
a26d34c2b3
commit
f9c28b3c45
|
|
@ -8,15 +8,14 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"local/notes-server/filetree"
|
"local/notes-server/filetree"
|
||||||
|
"local/notes-server/notes/md"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fairlyblank/md2min"
|
"github.com/fairlyblank/md2min"
|
||||||
"github.com/gomarkdown/markdown"
|
|
||||||
"github.com/gomarkdown/markdown/ast"
|
"github.com/gomarkdown/markdown/ast"
|
||||||
"github.com/gomarkdown/markdown/html"
|
"github.com/gomarkdown/markdown/html"
|
||||||
"github.com/gomarkdown/markdown/parser"
|
|
||||||
"github.com/yuin/goldmark"
|
"github.com/yuin/goldmark"
|
||||||
blackfriday "gopkg.in/russross/blackfriday.v2"
|
blackfriday "gopkg.in/russross/blackfriday.v2"
|
||||||
)
|
)
|
||||||
|
|
@ -57,35 +56,7 @@ func (n *Notes) md2min(urlPath string, b []byte) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notes) gomarkdown(urlPath string, b []byte) (string, error) {
|
func (n *Notes) gomarkdown(urlPath string, b []byte) (string, error) {
|
||||||
return Gomarkdown(b, n.commentFormer(urlPath, b))
|
return md.Gomarkdown(b, n.commentFormer(urlPath, b))
|
||||||
}
|
|
||||||
|
|
||||||
func Gomarkdown(b []byte, renderHook html.RenderNodeFunc) (string, error) {
|
|
||||||
renderer := html.NewRenderer(html.RendererOptions{
|
|
||||||
Flags: html.CommonFlags | html.TOC,
|
|
||||||
RenderNodeHook: renderHook,
|
|
||||||
})
|
|
||||||
ext := parser.NoExtensions
|
|
||||||
for _, extension := range []parser.Extensions{
|
|
||||||
parser.NoIntraEmphasis,
|
|
||||||
parser.Tables,
|
|
||||||
parser.FencedCode,
|
|
||||||
parser.Autolink,
|
|
||||||
parser.Strikethrough,
|
|
||||||
parser.SpaceHeadings,
|
|
||||||
parser.HeadingIDs,
|
|
||||||
parser.BackslashLineBreak,
|
|
||||||
parser.DefinitionLists,
|
|
||||||
parser.MathJax,
|
|
||||||
parser.Titleblock,
|
|
||||||
parser.AutoHeadingIDs,
|
|
||||||
parser.Includes,
|
|
||||||
} {
|
|
||||||
ext |= extension
|
|
||||||
}
|
|
||||||
parser := parser.NewWithExtensions(ext)
|
|
||||||
content := markdown.ToHTML(b, parser, renderer)
|
|
||||||
return string(content) + "\n", nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notes) commentFormer(urlPath string, md []byte) html.RenderNodeFunc {
|
func (n *Notes) commentFormer(urlPath string, md []byte) html.RenderNodeFunc {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package md
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gomarkdown/markdown"
|
||||||
|
"github.com/gomarkdown/markdown/html"
|
||||||
|
"github.com/gomarkdown/markdown/parser"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Gomarkdown(b []byte, renderHook html.RenderNodeFunc) (string, error) {
|
||||||
|
renderer := html.NewRenderer(html.RendererOptions{
|
||||||
|
Flags: html.CommonFlags | html.TOC,
|
||||||
|
RenderNodeHook: renderHook,
|
||||||
|
})
|
||||||
|
ext := parser.NoExtensions
|
||||||
|
for _, extension := range []parser.Extensions{
|
||||||
|
parser.NoIntraEmphasis,
|
||||||
|
parser.Tables,
|
||||||
|
parser.FencedCode,
|
||||||
|
parser.Autolink,
|
||||||
|
parser.Strikethrough,
|
||||||
|
parser.SpaceHeadings,
|
||||||
|
parser.HeadingIDs,
|
||||||
|
parser.BackslashLineBreak,
|
||||||
|
parser.DefinitionLists,
|
||||||
|
parser.MathJax,
|
||||||
|
parser.Titleblock,
|
||||||
|
parser.AutoHeadingIDs,
|
||||||
|
parser.Includes,
|
||||||
|
} {
|
||||||
|
ext |= extension
|
||||||
|
}
|
||||||
|
parser := parser.NewWithExtensions(ext)
|
||||||
|
content := markdown.ToHTML(b, parser, renderer)
|
||||||
|
return string(content) + "\n", nil
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue