我乞求去。我正在尝试使用blackfriday(Go Markdown解析器)。这是代码:
package main import ( "fmt" "github.com/russross/blackfriday" ) func main() { input := "this is a test" output := blackfriday.MarkdownCommon(input) fmt.Println(output) }
我遇到了一个错误:
alex@alex-K43U:~/go/src/m2kgo$ go run m2kgo.go # command-line-arguments ./m2kgo.go:20: cannot use input (type string) as type []byte in argument to blackfriday.MarkdownCommon
所以我尝试将参数转换为[]byte:
[]byte
output := blackfriday.MarkdownCommon([]byte(input))
但这会输出字节:
alex@alex-K43U:~/go/src/m2kgo$ go run m2kgo.go [60 112 62 116 104 105 115 32 105 115 32 97 32 116 101 115 116 60 47 112 62 10]
如何打印生成的HTML而不是字节?
将其转换回字符串。
fmt.Println(string(output))