-
-
Save jvns/9cc3024ff98433ced5e3a2304c5fc5e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/jvns/markdown-compare | |
go 1.23.1 | |
require ( | |
github.com/russross/blackfriday v1.6.0 // indirect | |
github.com/yuin/goldmark v1.7.4 // indirect | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"os" | |
"github.com/russross/blackfriday" | |
"github.com/yuin/goldmark" | |
"github.com/yuin/goldmark/extension" | |
"github.com/yuin/goldmark/parser" | |
"github.com/yuin/goldmark/renderer/html" | |
) | |
func main() { | |
// Read input from stdin | |
input, err := ioutil.ReadAll(os.Stdin) | |
if err != nil { | |
fmt.Println("Error reading input:", err) | |
return | |
} | |
// Convert markdown to HTML using blackfriday | |
blackfridayOutput := blackfriday.MarkdownBasic(input) | |
// Convert markdown to HTML using goldmark | |
var goldmarkOutput bytes.Buffer | |
// allow html unsafe | |
// do typography | |
md := goldmark.New( | |
goldmark.WithExtensions(extension.GFM), | |
goldmark.WithParserOptions( | |
parser.WithAutoHeadingID(), | |
), | |
goldmark.WithRendererOptions( | |
html.WithUnsafe(), | |
), | |
) | |
if err := md.Convert(input, &goldmarkOutput); err != nil { | |
fmt.Println("Error converting markdown using goldmark:", err) | |
return | |
} | |
// Print out both results | |
fmt.Println("Blackfriday HTML Output:") | |
fmt.Println(string(blackfridayOutput)) | |
fmt.Println("Goldmark HTML Output:") | |
fmt.Println(goldmarkOutput.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment