Example #1
0
// RenderRaw renders Markdown to HTML without handling special links.
func RenderRaw(body []byte, urlPrefix string) []byte {
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_SKIP_STYLE
	htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
	renderer := &Renderer{
		Renderer:  blackfriday.HtmlRenderer(htmlFlags, "", ""),
		urlPrefix: urlPrefix,
	}

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	extensions |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK

	if setting.Markdown.EnableHardLineBreak {
		extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK
	}

	body = blackfriday.Markdown(body, renderer, extensions)
	return body
}
Example #2
0
func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte {
	// slow!
	//body := RenderSpecialLink(rawBytes, urlPrefix)
	body := rawBytes
	htmlFlags := 0
	// htmlFlags |= gfm.HTML_USE_XHTML
	// htmlFlags |= gfm.HTML_USE_SMARTYPANTS
	// htmlFlags |= gfm.HTML_SMARTYPANTS_FRACTIONS
	// htmlFlags |= gfm.HTML_SMARTYPANTS_LATEX_DASHES
	// htmlFlags |= gfm.HTML_SKIP_HTML
	htmlFlags |= gfm.HTML_SKIP_STYLE
	//htmlFlags |= gfm.HTML_SKIP_SCRIPT
	htmlFlags |= gfm.HTML_GITHUB_BLOCKCODE
	htmlFlags |= gfm.HTML_OMIT_CONTENTS
	// htmlFlags |= gfm.HTML_COMPLETE_PAGE
	renderer := &CustomRender{
		Renderer:  gfm.HtmlRenderer(htmlFlags, "", ""),
		urlPrefix: urlPrefix,
	}

	// set up the parser
	extensions := 0
	extensions |= gfm.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= gfm.EXTENSION_TABLES
	extensions |= gfm.EXTENSION_FENCED_CODE
	extensions |= gfm.EXTENSION_AUTOLINK
	extensions |= gfm.EXTENSION_STRIKETHROUGH
	extensions |= gfm.EXTENSION_HARD_LINE_BREAK
	extensions |= gfm.EXTENSION_SPACE_HEADERS
	extensions |= gfm.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK

	body = gfm.Markdown(body, renderer, extensions)
	return body
}
Example #3
0
func RenderMarkdown(mdStr string) string {
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_XHTML
	// htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	// htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	// htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	htmlFlags |= blackfriday.HTML_SKIP_HTML
	htmlFlags |= blackfriday.HTML_SKIP_STYLE
	htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
	htmlFlags |= blackfriday.HTML_GITHUB_BLOCKCODE
	htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
	htmlFlags |= blackfriday.HTML_COMPLETE_PAGE
	renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	extensions |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK

	body := blackfriday.Markdown([]byte(mdStr), renderer, extensions)

	return string(body)
}
Example #4
0
func RenderMarkdownSafe(input []byte) []byte {
	// set up the HTML renderer
	flags := 0
	flags |= blackfriday.HTML_USE_XHTML
	flags |= blackfriday.HTML_USE_SMARTYPANTS
	flags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	flags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	flags |= blackfriday.HTML_SKIP_HTML
	flags |= blackfriday.HTML_SKIP_SCRIPT
	flags |= blackfriday.HTML_SKIP_STYLE
	// flags |= blackfriday.HTML_TOC
	// flags |= blackfriday.HTML_GITHUB_BLOCKCODE
	renderer := blackfriday.HtmlRenderer(flags, "", "")

	// set up the parser
	ext := 0
	ext |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	ext |= blackfriday.EXTENSION_TABLES
	ext |= blackfriday.EXTENSION_FENCED_CODE
	ext |= blackfriday.EXTENSION_AUTOLINK
	ext |= blackfriday.EXTENSION_STRIKETHROUGH
	ext |= blackfriday.EXTENSION_SPACE_HEADERS
	ext |= blackfriday.EXTENSION_HARD_LINE_BREAK
	ext |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK

	return blackfriday.Markdown(input, renderer, ext)
}
Example #5
0
// Renders markdown in submitted messages.
func Render(raw []byte) []byte {
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_XHTML
	htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS

	escaped := new(bytes.Buffer)
	template.HTMLEscape(escaped, raw)
	rendered := blackfriday.Markdown(escaped.Bytes(), renderer, extensions)
	enabled := true
	fmt.Println("Raw message:")
	fmt.Println(string(raw))
	if enabled {
		fmt.Println("Rendered message:")
		fmt.Println(string(rendered))
		return rendered
	}
	return raw
}
Example #6
0
func markdown(raw []byte) []byte {
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_XHTML
	htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
	htmlFlags |= blackfriday.HTML_COMPLETE_PAGE

	renderer := &CustomRender{
		Renderer: blackfriday.HtmlRenderer(htmlFlags, "", ""),
	}

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	extensions |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK

	body := blackfriday.Markdown(raw, renderer, extensions)
	return body
}
Example #7
0
func RenderRawMarkdown(body []byte, urlPrefix string) []byte {
	htmlFlags := 0
	// htmlFlags |= blackfriday.HTML_USE_XHTML
	// htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	// htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	// htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	// htmlFlags |= blackfriday.HTML_SKIP_HTML
	htmlFlags |= blackfriday.HTML_SKIP_STYLE
	// htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
	// htmlFlags |= blackfriday.HTML_GITHUB_BLOCKCODE
	htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
	// htmlFlags |= blackfriday.HTML_COMPLETE_PAGE
	renderer := &CustomRender{
		Renderer:  blackfriday.HtmlRenderer(htmlFlags, "", ""),
		urlPrefix: urlPrefix,
	}

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	extensions |= blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK

	if setting.Markdown.EnableHardLineBreak {
		extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK
	}

	body = blackfriday.Markdown(body, renderer, extensions)
	return body
}
Example #8
0
// RenderPost runs the input source through the blackfriday library.
func RenderPost(post *Post, input []byte, page PageParams) ([]byte, error) {
	tpl, err := page.getTemplate("post")
	if err != nil {
		return nil, err
	}

	content := blackfriday.Markdown(
		input,
		blackfriday.HtmlRenderer(page.Blog.GetMarkdownHTMLOptions(), "", ""),
		page.Blog.GetMarkdownExtensions())

	page.Title = post.Title
	params := PostPageParams{
		Post:       post,
		Content:    string(content),
		PageParams: page,
	}

	buf := new(bytes.Buffer)
	if err := tpl.Execute(buf, params); err != nil {
		return nil, err
	}

	return wrapPage(buf.Bytes(), params.PageParams)
}
Example #9
0
// Markdown renders GitHub Flavored Markdown text.
func Markdown(text []byte) []byte {
	htmlFlags := 0
	renderer := &renderer{Html: blackfriday.HtmlRenderer(htmlFlags, "", "").(*blackfriday.Html)}

	// Parser extensions for GitHub Flavored Markdown.
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	//extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK

	unsanitized := blackfriday.Markdown(text, renderer, extensions)

	// GitHub Flavored Markdown-like sanitization policy.
	p := bluemonday.UGCPolicy()
	p.AllowAttrs("class").Matching(bluemonday.SpaceSeparatedTokens).OnElements("div", "span")
	p.AllowAttrs("class", "name").Matching(bluemonday.SpaceSeparatedTokens).OnElements("a")
	p.AllowAttrs("rel").Matching(regexp.MustCompile(`^nofollow$`)).OnElements("a")
	p.AllowAttrs("aria-hidden").Matching(regexp.MustCompile(`^true$`)).OnElements("a")
	p.AllowDataURIImages()

	return p.SanitizeBytes(unsanitized)
}
Example #10
0
// serveFile serves a file from disk, converting any markdown to HTML.
func serveFile(w http.ResponseWriter, r *http.Request, relPath, absPath string) {
	if !strings.HasSuffix(absPath, ".html") && !strings.HasSuffix(absPath, ".md") {
		http.ServeFile(w, r, absPath)
		return
	}

	data, err := ioutil.ReadFile(absPath)
	if err != nil {
		serveError(w, r, absPath, err)
		return
	}

	var markdownRenderer = blackfriday.HtmlRenderer(markdownHTMLFlags, "", "")
	data = blackfriday.MarkdownOptions(data, markdownRenderer, blackfriday.Options{Extensions: markdownExtensions})

	title := ""
	if m := h1TitlePattern.FindSubmatch(data); len(m) > 1 {
		title = string(m[1])
	}

	servePage(w, pageParams{
		title:   title,
		content: data,
	})
}
Example #11
0
func markdownParse(c *Controller) ([]*markdown.Config, error) {
	var mdconfigs []*markdown.Config

	for c.Next() {
		md := &markdown.Config{
			Renderer:    blackfriday.HtmlRenderer(0, "", ""),
			Templates:   make(map[string]string),
			StaticFiles: make(map[string]string),
		}

		// Get the path scope
		if !c.NextArg() || c.Val() == "{" {
			return mdconfigs, c.ArgErr()
		}
		md.PathScope = c.Val()

		// Load any other configuration parameters
		for c.NextBlock() {
			if err := loadParams(c, md); err != nil {
				return mdconfigs, err
			}
		}

		// If no extensions were specified, assume .md
		if len(md.Extensions) == 0 {
			md.Extensions = []string{".md"}
		}

		mdconfigs = append(mdconfigs, md)
	}

	return mdconfigs, nil
}
Example #12
0
func markdownFile(path string) (string, error) {
	if input, err := ioutil.ReadFile(path); err == nil {
		htmlFlags := 0
		htmlFlags |= blackfriday.HTML_USE_XHTML
		htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
		htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
		htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
		renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")

		// set up the parser
		extensions := 0
		extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
		extensions |= blackfriday.EXTENSION_TABLES
		extensions |= blackfriday.EXTENSION_FENCED_CODE
		extensions |= blackfriday.EXTENSION_AUTOLINK
		extensions |= blackfriday.EXTENSION_STRIKETHROUGH
		extensions |= blackfriday.EXTENSION_SPACE_HEADERS
		extensions |= blackfriday.EXTENSION_FOOTNOTES

		data := blackfriday.Markdown(input, renderer, extensions)
		return string(data), nil
	} else {
		return "", err
	}
}
Example #13
0
func pageRenderMarkdown(content string) (res string) {
	renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
	unsafe := blackfriday.MarkdownOptions([]byte(content), renderer, blackfriday.Options{
		Extensions: markdownExtensions})
	res = string(unsafe)
	return
}
func NewCustomHtml(c *config.Config) MarkdownTransformer {
	// set up the HTML renderer
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_XHTML
	htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	htmlFlags |= blackfriday.HTML_SKIP_SCRIPT

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_PLUGIN
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS

	// Plugins
	plugins := make(map[string]Plugin)

	// Wrap up everything
	htmlRenderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
	customRenderer := &CustomHtml{html: htmlRenderer,
		config:  c,
		plugins: plugins}
	transformer := &CustomMarkdownTransformer{renderer: customRenderer,
		extensions: extensions,
		plugins:    plugins}
	return transformer
}
Example #15
0
func init() {

	// render the data into HTML
	var htmlFlags = 0
	htmlFlags |= blackfriday.HTML_SKIP_HTML
	htmlFlags |= blackfriday.HTML_SKIP_STYLE
	htmlFlags |= blackfriday.HTML_GITHUB_BLOCKCODE
	// htmlFlags |= blackfriday.HTML_USE_XHTML
	// htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	// htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	// htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	// htmlFlags |= blackfriday.HTML_COMPLETE_PAGE
	// htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
	// htmlFlags |= blackfriday.HTML_TOC

	title := ""
	css := ""
	renderer = blackfriday.HtmlRenderer(htmlFlags, title, css)

	// set up options
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	extensions |= blackfriday.EXTENSION_HARD_LINE_BREAK // 强制换行

	// var output []byte
	// output = blackfriday.Markdown(input, renderer, extensions)
}
Example #16
0
File: run.go Project: fblecha/fuel
func configureBlackFriday(path string) (blackfriday.Renderer, int) {
	htmlFlags := 0
	css := ""
	extensions := 0
	title := getFilenameMinusExtension(path)
	renderer := blackfriday.HtmlRenderer(htmlFlags, title, css)
	return renderer, extensions
}
Example #17
0
func (p *Post) html() (T.HTML, error) {
	body, err := p.withImages()
	if err != nil {
		return "", err
	}
	extensions := md.EXTENSION_SPACE_HEADERS | md.EXTENSION_TABLES | md.EXTENSION_NO_INTRA_EMPHASIS | md.EXTENSION_STRIKETHROUGH | md.EXTENSION_FOOTNOTES
	renderer := md.HtmlRenderer(0, "", "")
	return T.HTML(md.Markdown([]byte(body), renderer, extensions)), nil
}
Example #18
0
func ToHtml(content string) template.HTML {
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS

	renderer := blackfriday.HtmlRenderer(htmlFlags, "", "")

	html := blackfriday.Markdown([]byte(content), renderer, enabled_md_extensions)
	return template.HTML(bluemonday.UGCPolicy().SanitizeBytes(html))
}
Example #19
0
func main() {
	// read the input
	var input []byte
	var err os.Error
	switch len(os.Args) {
	case 1:
		if input, err = ioutil.ReadAll(os.Stdin); err != nil {
			fmt.Fprintln(os.Stderr, "Error reading from Stdin:", err)
			os.Exit(-1)
		}
	case 2, 3:
		if input, err = ioutil.ReadFile(os.Args[1]); err != nil {
			fmt.Fprintln(os.Stderr, "Error reading from", os.Args[1], ":", err)
			os.Exit(-1)
		}
	default:
		fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "[inputfile [outputfile]]")
		os.Exit(-1)
	}

	// set up options
	var extensions uint32
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS

	html_flags := 0
	html_flags |= blackfriday.HTML_USE_XHTML
	// note: uncomment the following line to enable smartypants
	// it is commented out by default so that markdown
	// compatibility tests pass
	//html_flags |= blackfriday.HTML_USE_SMARTYPANTS
	html_flags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	html_flags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES

	// render the data
	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, 0644); err != nil {
			fmt.Fprintln(os.Stderr, "Error writing to", os.Args[2], ":", err)
			os.Exit(-1)
		}
	} else {
		if _, err = os.Stdout.Write(output); err != nil {
			fmt.Fprintln(os.Stderr, "Error writing to Stdout:", err)
			os.Exit(-1)
		}
	}
}
Example #20
0
// Markdown returns the HTML contents of the markdown contained in filename
// (relative to the site root).
func (c Context) Markdown(filename string) (string, error) {
	body, err := c.Include(filename)
	if err != nil {
		return "", err
	}
	renderer := blackfriday.HtmlRenderer(0, "", "")
	extns := blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE | blackfriday.EXTENSION_STRIKETHROUGH | blackfriday.EXTENSION_DEFINITION_LISTS
	markdown := blackfriday.Markdown([]byte(body), renderer, extns)

	return string(markdown), nil
}
Example #21
0
func getHtmlPageData(title string, md string) *PageData {
	mdData := MarkdownData{}
	pageData := PageData{Title: "Walking Noticeboard"}
	mdData.Title = title
	mdData.MdContent = md

	htmlRenderer := blackfriday.HtmlRenderer(htmlFlags, "", "")
	mdData.HtmlContent = template.HTML(blackfriday.Markdown([]byte(md), htmlRenderer, htmlExt))
	pageData.MarkDown = mdData

	return &pageData
}
Example #22
0
func (g *Generator) markdown(name string, argsv ...string) string {
	// find template with correct name
	t := g.Master.Lookup(name)
	if t == nil {
		abort("cannot find template '%s' (used as markdown function argument)", name)
	}

	// create new scope and execute the template
	args := g.ParseArgs(argsv)
	g.PushScope(args)
	defer g.PopScope()

	buf := bytes.NewBuffer(nil)
	err := t.Execute(buf, nil)
	if err != nil {
		abort("ff%s", err)
	}

	// set up the HTML renderer
	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_XHTML
	htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
	htmlFlags |= blackfriday.HTML_SKIP_SCRIPT
	htmlFlags |= blackfriday.HTML_GITHUB_BLOCKCODE

	// set up the parser
	extensions := 0
	extensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	extensions |= blackfriday.EXTENSION_TABLES
	extensions |= blackfriday.EXTENSION_FENCED_CODE
	extensions |= blackfriday.EXTENSION_AUTOLINK
	extensions |= blackfriday.EXTENSION_STRIKETHROUGH
	extensions |= blackfriday.EXTENSION_SPACE_HEADERS
	extensions |= blackfriday.EXTENSION_FOOTNOTES

	if str2bool(args["toc"]) {
		htmlFlags |= blackfriday.HTML_TOC
	}

	// convert markdown to html
	basename := path.Base(name)
	extension := path.Ext(basename)
	mdname := basename[0 : len(basename)-len(extension)]

	renderer := blackfriday.HtmlRenderer(htmlFlags, mdname, "")

	html := blackfriday.Markdown(buf.Bytes(), renderer, extensions)

	return string(html)
}
Example #23
0
func (post *PostModel) RenderPost(postId string) *Post {
	result := post.Get(postId)
	renderer := blackfriday.HtmlRenderer(post.html_flags, "", "")
	if result.Type == 1 {
		result.Content = string(blackfriday.Markdown([]byte(result.Content), renderer, post.extensions))
	}

	// Also render all blog comments as markdown
	for i, v := range result.Comments {
		result.Comments[i].Content = string(blackfriday.Markdown([]byte(v.Content), renderer, post.extensions))
	}
	return result
}
Example #24
0
func templateBlackfriday(mkd string) template.HTML {
	//Set up the HTML renderer
	renderer := blackfriday.HtmlRenderer(flags, "", "").(*blackfriday.Html)
	wrappedRenderer := &MarkdownRenderer{
		Html: renderer,
	}

	res := blackfriday.MarkdownOptions([]byte(mkd), wrappedRenderer, blackfriday.Options{
		Extensions: extensions,
	})

	return template.HTML(res)
}
Example #25
0
func renderMarkdown(title string, input []byte) []byte {
	var renderer md.Renderer
	htmlFlags := 0
	extensions := 0
	css := "../stylesheets/styles.css"
	htmlFlags |= md.HTML_USE_XHTML
	htmlFlags |= md.HTML_USE_SMARTYPANTS
	htmlFlags |= md.HTML_SMARTYPANTS_FRACTIONS
	htmlFlags |= md.HTML_COMPLETE_PAGE
	renderer = md.HtmlRenderer(htmlFlags, title, css)
	return md.Markdown(input, renderer, extensions)

}
Example #26
0
// pass custom flags to the blackfriday md->html renderer
func markdown(input []byte) []byte {
	flags := 0
	flags |= blackfriday.HTML_USE_XHTML
	r := blackfriday.HtmlRenderer(flags, "", "")

	ext := 0
	ext |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	ext |= blackfriday.EXTENSION_TABLES
	ext |= blackfriday.EXTENSION_SPACE_HEADERS
	ext |= blackfriday.EXTENSION_FOOTNOTES
	ext |= blackfriday.EXTENSION_FENCED_CODE

	return blackfriday.Markdown(input, r, ext)
}
Example #27
0
// toHTML reads a markdown file and returns a HTML string.
func toHTML(filename string) (string, error) {
	buf, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", err
	}
	// Use standard HTML rendering.
	renderer := blackfriday.HtmlRenderer(blackfriday.HTML_USE_XHTML, "", "")
	// Parse markdown where all id's are created from the values inside
	// the element tag.
	buf = blackfriday.MarkdownOptions(buf, renderer, blackfriday.Options{
		Extensions: blackfriday.EXTENSION_AUTO_HEADER_IDS | blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE,
	})
	return string(buf), nil
}
Example #28
0
// Initialize a custom HTML render
func initBF() {
	bfExtensions |= blackfriday.EXTENSION_NO_INTRA_EMPHASIS
	bfExtensions |= blackfriday.EXTENSION_TABLES
	bfExtensions |= blackfriday.EXTENSION_FENCED_CODE
	bfExtensions |= blackfriday.EXTENSION_AUTOLINK
	bfExtensions |= blackfriday.EXTENSION_STRIKETHROUGH
	bfExtensions |= blackfriday.EXTENSION_SPACE_HEADERS

	htmlFlags := 0
	htmlFlags |= blackfriday.HTML_USE_XHTML
	htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
	htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
	bfRender = blackfriday.HtmlRenderer(htmlFlags, "", "")
}
Example #29
0
func Render(text string) string {
	flags := 0 |
		blackfriday.HTML_USE_XHTML |
		blackfriday.HTML_USE_SMARTYPANTS

	renderer := blackfriday.HtmlRenderer(flags, "", "")

	extensions := 0 |
		blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
		blackfriday.EXTENSION_FENCED_CODE |
		blackfriday.EXTENSION_SPACE_HEADERS

	return string(blackfriday.Markdown([]byte(text), renderer, extensions))
}
Example #30
0
func renderMarkdown(input []byte) (out []byte, err error) {
	defer func() {
		if e := recover(); e != nil {
			if e, ok := e.(error); ok {
				log.Info("hilite error: restarting, due to: %s", e)
				setupPygments()
				err = e
			}
		}
	}()
	r := &Html{blackfriday.HtmlRenderer(DefaultHtmlFlags, "", "")}
	out = blackfriday.Markdown(input, r, DefaultExtensions)
	return
}