Actually print markdown content to output :)

This commit is contained in:
Fred Pauchet 2022-09-18 21:58:41 +02:00
parent 1724b9664c
commit 647e9b546d
1 changed files with 33 additions and 0 deletions

33
main.go
View File

@ -6,6 +6,11 @@ import (
"log"
"os"
"path/filepath"
"bytes"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
)
func walk(rootDir string) ([]string, error) {
@ -27,6 +32,32 @@ func walk(rootDir string) ([]string, error) {
return files, err
}
func convertMarkdownToHtml(file string) {
content, err := os.ReadFile(file)
if err != nil {
log.Fatal(err)
}
md := goldmark.New(
goldmark.WithExtensions(extension.GFM),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithHardWraps(),
html.WithXHTML(),
),
)
var buf bytes.Buffer
if err := md.Convert(content, &buf); err != nil {
panic(err)
}
fmt.Println(buf.String())
}
func main() {
var rootDir *string
@ -42,5 +73,7 @@ func main() {
for _, file := range files {
fmt.Println(file)
convertMarkdownToHtml(file)
}
}