This commit is contained in:
Andrey Parhomenko 2024-03-02 19:33:24 +05:00
parent 9e69d1bd28
commit 6ba3cc394e

View file

@ -2,6 +2,8 @@ package server
import (
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
"vultras.su/core/bond"
"vultras.su/core/bond/contents"
"vultras.su/util/pp"
@ -38,6 +40,21 @@ type Server struct {
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 {
srv := &Server{}
srv.handler = makeRootHandler(opts)
@ -72,7 +89,8 @@ func (srv *Server) pageFooter() string {
func (srv *Server) ProcessToHtml(urlPath, filePath string, bts []byte) ([]byte, error) {
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())
if srv.options.AddFileNavigation {