2

I'm begginer to Go. I'm trying to use blackfriday (a Go Markdown parser). This is the code:

package main

import (
    "fmt"
    "github.com/russross/blackfriday"
)

func main() {
    input := "this is a test"
    output := blackfriday.MarkdownCommon(input)

    fmt.Println(output)
}

I got an error, though:

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

So I tried turning the argument into []byte:

output := blackfriday.MarkdownCommon([]byte(input))

This output the bytes though:

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]

How can I print the generated HTML instead of the bytes?

1 Answer 1

4

Convert it back to a string.

fmt.Println(string(output))

Sign up to request clarification or add additional context in comments.

3 Comments

Oh, thanks. Is that something that's commonly done in Go (changing the input/output type)? Or I'm using them in a wrong way?
I'm not familiar with the blackfriday package so I can't comment on how that's supposed to work -- but in general it's not uncommon to have to convert types when manipulating data
Looking at their source, it looks like they take in and return []bytes everywhere, so yes -- I think you're on the right track. github.com/russross/blackfriday/blob/master/markdown.go#L250

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.