progdoc/mdsource.go

35 lines
589 B
Go
Raw Normal View History

2026-02-01 04:00:26 +00:00
package progdoc
import (
"io"
"os"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
)
type mdSource struct {
MDFile string
}
func (m mdSource) HTML(w io.Writer, srcCtx *SourceCtx) error {
srcBytes, err := os.ReadFile(m.MDFile)
if err != nil {
return err
}
md := goldmark.New(
goldmark.WithExtensions(extension.GFM),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithUnsafe(),
),
)
return md.Convert(srcBytes, w)
}