mirror of
https://github.com/danog/blackfriday.git
synced 2024-11-30 04:29:13 +01:00
return result instead of taking buffer as input
This commit is contained in:
parent
6c6efa13b5
commit
3ee2b137f8
@ -13,7 +13,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"github.com/russross/blackfriday"
|
||||
@ -41,7 +40,6 @@ func main() {
|
||||
}
|
||||
|
||||
// set up options
|
||||
output := bytes.NewBuffer(nil)
|
||||
var extensions uint32
|
||||
extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
|
||||
extensions |= blackfriday.EXTENSION_TABLES
|
||||
@ -57,16 +55,16 @@ func main() {
|
||||
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)
|
||||
}
|
||||
|
@ -166,10 +166,10 @@ const (
|
||||
// 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 @@ func Markdown(output *bytes.Buffer, input []byte, renderer *Renderer, extensions
|
||||
}
|
||||
|
||||
// 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 @@ func Markdown(output *bytes.Buffer, input []byte, renderer *Renderer, extensions
|
||||
if rndr.nesting != 0 {
|
||||
panic("Nesting level did not end at zero")
|
||||
}
|
||||
|
||||
return output.Bytes()
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user