...
This commit is contained in:
parent
9e69d1bd28
commit
6ba3cc394e
1 changed files with 19 additions and 1 deletions
|
@ -2,6 +2,8 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gomarkdown/markdown"
|
"github.com/gomarkdown/markdown"
|
||||||
|
"github.com/gomarkdown/markdown/html"
|
||||||
|
"github.com/gomarkdown/markdown/parser"
|
||||||
"vultras.su/core/bond"
|
"vultras.su/core/bond"
|
||||||
"vultras.su/core/bond/contents"
|
"vultras.su/core/bond/contents"
|
||||||
"vultras.su/util/pp"
|
"vultras.su/util/pp"
|
||||||
|
@ -38,6 +40,21 @@ type Server struct {
|
||||||
prep *pp.Preprocessor
|
prep *pp.Preprocessor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *Server) makeMdParser() *parser.Parser {
|
||||||
|
return parser.NewWithExtensions(
|
||||||
|
parser.CommonExtensions | parser.AutoHeadingIDs |
|
||||||
|
parser.NoEmptyLineBeforeBlock,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (srv *Server) makeHtmlRenderer() *html.Renderer {
|
||||||
|
return html.NewRenderer(
|
||||||
|
html.RendererOptions{
|
||||||
|
Flags: html.CommonFlags | html.HrefTargetBlank,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func New(opts ServerOptions) *Server {
|
func New(opts ServerOptions) *Server {
|
||||||
srv := &Server{}
|
srv := &Server{}
|
||||||
srv.handler = makeRootHandler(opts)
|
srv.handler = makeRootHandler(opts)
|
||||||
|
@ -72,7 +89,8 @@ func (srv *Server) pageFooter() string {
|
||||||
|
|
||||||
func (srv *Server) ProcessToHtml(urlPath, filePath string, bts []byte) ([]byte, error) {
|
func (srv *Server) ProcessToHtml(urlPath, filePath string, bts []byte) ([]byte, error) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
main_section := markdown.ToHTML(bts, nil, nil)
|
doc := srv.makeMdParser().Parse(bts)
|
||||||
|
main_section := markdown.Render(doc, srv.makeHtmlRenderer())
|
||||||
fmt.Fprint(&b, srv.pageHead())
|
fmt.Fprint(&b, srv.pageHead())
|
||||||
|
|
||||||
if srv.options.AddFileNavigation {
|
if srv.options.AddFileNavigation {
|
||||||
|
|
Loading…
Reference in a new issue