本文整理匯總了Golang中github.com/russross/blackfriday.Markdown函數的典型用法代碼示例。如果您正苦於以下問題:Golang Markdown函數的具體用法?Golang Markdown怎麽用?Golang Markdown使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Markdown函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: markdownRender
func markdownRender(ctx *RenderingContext) []byte {
if ctx.RenderTOC {
return blackfriday.Markdown(ctx.Content,
getHTMLRenderer(blackfriday.HTML_TOC, ctx),
getMarkdownExtensions(ctx))
}
return blackfriday.Markdown(ctx.Content, getHTMLRenderer(0, ctx),
getMarkdownExtensions(ctx))
}
示例2: main
func main() {
flag.Parse()
args := flag.Args()
renderer := &Console{}
extensions := 0 |
blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
blackfriday.EXTENSION_FENCED_CODE |
blackfriday.EXTENSION_AUTOLINK |
blackfriday.EXTENSION_STRIKETHROUGH |
blackfriday.EXTENSION_SPACE_HEADERS |
blackfriday.EXTENSION_HEADER_IDS |
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK |
blackfriday.EXTENSION_DEFINITION_LISTS
if len(args) > 0 {
for i := 0; i < len(args); i++ {
input, err := ioutil.ReadFile(args[i])
if err != nil {
os.Stderr.WriteString(fmt.Sprintf("mdcat: %s: unable to read from file\n", args[i]))
os.Exit(1)
}
output := blackfriday.Markdown(input, renderer, extensions)
os.Stdout.Write(output)
}
} else {
reader := bufio.NewReader(os.Stdin)
var input []byte
buffer := make([]byte, 2<<20)
for {
count, err := reader.Read(buffer)
if count == 0 {
break
}
if err != nil {
os.Stderr.WriteString("mdcat: unable to read from pipe\n")
os.Exit(1)
}
input = append(input, buffer...)
}
output := blackfriday.Markdown(input, renderer, extensions)
os.Stdout.Write(output)
}
}
示例3: RenderPost
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
}
示例4: markdownFile
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
}
}
示例5: RenderRaw
// 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
}
示例6: Markdown
// 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)
}
示例7: RenderPost
// 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)
}
示例8: RenderMarkdown
func RenderMarkdown(input []byte) []byte {
// 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_FOOTNOTE_RETURN_LINKS
renderer := &renderer{
Html: blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", blackfriday.HtmlRendererParameters{
FootnoteReturnLinkContents: "↩",
}).(*blackfriday.Html),
}
// 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_HEADER_IDS
extensions |= blackfriday.EXTENSION_FOOTNOTES
return blackfriday.Markdown(input, renderer, extensions)
}
示例9: MarkdownToTextNoMetadata
// MarkdownToTextNoMetadata is the same as MarkdownToText only skipping the
// detection and parsing of any leading metadata. If opts is nil the defaults
// will be used.
func MarkdownToTextNoMetadata(markdown []byte, opts *Options) []byte {
opts = resolveOpts(opts)
rend := &renderer{
width: opts.Width,
color: opts.Color,
tableAlignOptions: opts.TableAlignOptions,
headerPrefix: opts.HeaderPrefix,
headerSuffix: opts.HeaderSuffix,
}
markdown = bytes.Replace(markdown, []byte("\n///\n"), []byte(""), -1)
txt := blackfriday.Markdown(markdown, rend,
blackfriday.EXTENSION_NO_INTRA_EMPHASIS|
blackfriday.EXTENSION_TABLES|
blackfriday.EXTENSION_FENCED_CODE|
blackfriday.EXTENSION_AUTOLINK|
blackfriday.EXTENSION_STRIKETHROUGH|
blackfriday.EXTENSION_DEFINITION_LISTS)
for rend.level > 0 {
txt = append(txt, markIndentStop)
rend.level--
}
if len(txt) > 0 {
txt = bytes.Replace(txt, []byte(" \n"), []byte(" "), -1)
txt = bytes.Replace(txt, []byte("\n"), []byte(" "), -1)
txt = reflow(txt, opts.Indent1, opts.Indent2, rend.width)
txt = bytes.Replace(txt, []byte{markNBSP}, []byte(" "), -1)
txt = bytes.Replace(txt, []byte{markLineBreak}, []byte("\n"), -1)
}
return txt
}
示例10: renderItemBegin
//渲染評論HTML代碼
func (cl CommentNode) renderItemBegin(b *bytes.Buffer, sortType string) {
if cl.Status == 2 {
cl.Content = "[已刪除]"
}
b.WriteString(fmt.Sprintf(`<div id="cm-%d" class="cm" data-id="%v">
<div class="vt">
<a class="icon-thumbs-up up" href="javascript:"></a>
<a class="icon-thumbs-down down" href="javascript:"></a>
</div>
<div class="ct">
<div class="uif">
<a class="ep" href="javascript:">[–]</a>
<a href="/user/%v">%v</a>
<i class="v" title="↑%v ↓%v">%v分</i> <i class="t">%v</i>
</div>
<div class="tx">%s</div>
<div class="ed">
<a href="/link/permacoment/%v/%v/?cm_order=%s" class="cbtn">查看</a>
<a href="javascript:" class="cbtn rp">回複</a>
</div>`, cl.Id, cl.Id,
cl.UserId, cl.UserName,
cl.VoteUp, cl.VoteDown,
cl.VoteUp-cl.VoteDown,
cl.SinceTime(), blackfriday.Markdown([]byte(cl.Content), renderer, extensions), //strings.Replace(cl.Content, "\n", "<br/>", -1),
cl.LinkId, cl.Id, sortType))
}
示例11: Render
// 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
}
示例12: RenderMarkdown
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
}
示例13: markdown
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
}
示例14: RenderRawMarkdown
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
}
示例15: Markdown
// Markdown formats input using a plain-text renderer, and
// then returns up to the first `wordcount` words as a summary.
func Markdown(input []byte, wordcount int) []byte {
words := bytes.Fields(blackfriday.Markdown(input, renderer{}, 0))
if wordcount > len(words) {
wordcount = len(words)
}
return bytes.Join(words[0:wordcount], []byte{' '})
}