35 lines
589 B
Go
35 lines
589 B
Go
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)
|
|
}
|