Implement cli argument for file path, path validation, file type validation
This commit is contained in:
parent
1667fb10ef
commit
26adec4a97
6 changed files with 111 additions and 2 deletions
22
internal/convert/mdToHtml.go
Normal file
22
internal/convert/mdToHtml.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package convert
|
||||
|
||||
import (
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
)
|
||||
|
||||
// This function takes a Markdown document and returns an HTML document.
|
||||
func MdToHTML(md []byte) ([]byte, error) {
|
||||
// create parser with extensions
|
||||
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
|
||||
p := parser.NewWithExtensions(extensions)
|
||||
doc := p.Parse(md)
|
||||
|
||||
// build HTML renderer
|
||||
htmlFlags := html.CommonFlags | html.HrefTargetBlank
|
||||
opts := html.RendererOptions{Flags: htmlFlags}
|
||||
renderer := html.NewRenderer(opts)
|
||||
|
||||
return markdown.Render(doc, renderer), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue