all repos — grayfriday @ 3ee2b137f8d5ffbd8675296a3001be5ba830fb58

blackfriday fork with a few changes

return result instead of taking buffer as input
Russ Ross russ@russross.com
Sat, 28 May 2011 22:37:12 -0600
commit

3ee2b137f8d5ffbd8675296a3001be5ba830fb58

parent

6c6efa13b561c6b7541bce781b5472a8e1c59492

2 files changed, 8 insertions(+), 7 deletions(-)

jump to
M example/main.goexample/main.go

@@ -13,7 +13,6 @@

package main import ( - "bytes" "fmt" "io/ioutil" "github.com/russross/blackfriday"

@@ -41,7 +40,6 @@ os.Exit(-1)

} // set up options - output := bytes.NewBuffer(nil) var extensions uint32 extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS extensions |= blackfriday.EXTENSION_TABLES

@@ -57,16 +55,16 @@ html_flags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS

html_flags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES // render the data - blackfriday.Markdown(output, input, blackfriday.HtmlRenderer(html_flags), extensions) + output := blackfriday.Markdown(input, blackfriday.HtmlRenderer(html_flags), extensions) // output the result if len(os.Args) == 3 { - if err = ioutil.WriteFile(os.Args[2], output.Bytes(), 0644); err != nil { + if err = ioutil.WriteFile(os.Args[2], output, 0644); err != nil { fmt.Fprintln(os.Stderr, "Error writing to", os.Args[2], ":", err) os.Exit(-1) } } else { - if _, err = os.Stdout.Write(output.Bytes()); err != nil { + if _, err = os.Stdout.Write(output); err != nil { fmt.Fprintln(os.Stderr, "Error writing to Stdout:", err) os.Exit(-1) }
M markdown.gomarkdown.go

@@ -166,10 +166,10 @@

// Parse and render a block of markdown-encoded text. // The renderer is used to format the output, and extensions dictates which // non-standard extensions are enabled. -func Markdown(output *bytes.Buffer, input []byte, renderer *Renderer, extensions uint32) { +func Markdown(input []byte, renderer *Renderer, extensions uint32) []byte { // no point in parsing if we can't render if renderer == nil { - return + return nil } // fill in the character-level parsers

@@ -255,6 +255,7 @@ sort.Sort(rndr.refs)

} // second pass: actual rendering + output := bytes.NewBuffer(nil) if rndr.mk.doc_header != nil { rndr.mk.doc_header(output, rndr.mk.opaque) }

@@ -275,6 +276,8 @@

if rndr.nesting != 0 { panic("Nesting level did not end at zero") } + + return output.Bytes() }