diff --git a/server/main.go b/server/main.go index ed45c49..cec5b7e 100644 --- a/server/main.go +++ b/server/main.go @@ -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 {