1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 21:14:48 +01:00

add support for blackfriday v2

This commit is contained in:
Maurits van der Schee 2021-06-04 12:13:49 +02:00 committed by Oliver Steele
parent 89922b8f0c
commit 0cd04545f8
2 changed files with 30 additions and 24 deletions

View File

@ -87,7 +87,7 @@ func AddJekyllFilters(e *liquid.Engine, c *config.Config) {
return c.BaseURL + s return c.BaseURL + s
}) })
e.RegisterFilter("jsonify", json.Marshal) e.RegisterFilter("jsonify", json.Marshal)
e.RegisterFilter("markdownify", blackfriday.MarkdownCommon) e.RegisterFilter("markdownify", blackfriday.Run)
e.RegisterFilter("normalize_whitespace", func(s string) string { e.RegisterFilter("normalize_whitespace", func(s string) string {
// s = strings.Replace(s, "n", "N", -1) // s = strings.Replace(s, "n", "N", -1)
wsPattern := regexp.MustCompile(`(?s:[\s\n]+)`) wsPattern := regexp.MustCompile(`(?s:[\s\n]+)`)

View File

@ -11,31 +11,34 @@ import (
) )
const blackfridayFlags = 0 | const blackfridayFlags = 0 |
blackfriday.HTML_USE_XHTML | blackfriday.UseXHTML |
blackfriday.HTML_USE_SMARTYPANTS | blackfriday.Smartypants |
blackfriday.HTML_SMARTYPANTS_FRACTIONS | blackfriday.SmartypantsFractions |
blackfriday.HTML_SMARTYPANTS_DASHES | blackfriday.SmartypantsDashes |
blackfriday.HTML_SMARTYPANTS_LATEX_DASHES blackfriday.SmartypantsLatexDashes
const blackfridayExtensions = 0 | const blackfridayExtensions = 0 |
blackfriday.EXTENSION_NO_INTRA_EMPHASIS | blackfriday.NoIntraEmphasis |
blackfriday.EXTENSION_TABLES | blackfriday.Tables |
blackfriday.EXTENSION_FENCED_CODE | blackfriday.FencedCode |
blackfriday.EXTENSION_AUTOLINK | blackfriday.Autolink |
blackfriday.EXTENSION_STRIKETHROUGH | blackfriday.Strikethrough |
blackfriday.EXTENSION_SPACE_HEADERS | blackfriday.SpaceHeadings |
blackfriday.EXTENSION_HEADER_IDS | blackfriday.HeadingIDs |
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK | blackfriday.BackslashLineBreak |
blackfriday.EXTENSION_DEFINITION_LISTS | blackfriday.DefinitionLists |
// added relative to commonExtensions // added relative to commonExtensions
blackfriday.EXTENSION_AUTO_HEADER_IDS blackfriday.AutoHeadingIDs
func renderMarkdown(md []byte) ([]byte, error) { func renderMarkdown(md []byte) ([]byte, error) {
renderer := blackfriday.HtmlRenderer(blackfridayFlags, "", "") params := blackfriday.HTMLRendererParameters{
html := blackfriday.MarkdownOptions( Flags: blackfridayFlags,
}
renderer := blackfriday.NewHTMLRenderer(params)
html := blackfriday.Run(
md, md,
renderer, blackfriday.WithRenderer(renderer),
blackfriday.Options{Extensions: blackfridayExtensions}, blackfriday.WithExtensions(blackfridayExtensions),
) )
html, err := renderInnerMarkdown(html) html, err := renderInnerMarkdown(html)
if err != nil { if err != nil {
@ -45,11 +48,14 @@ func renderMarkdown(md []byte) ([]byte, error) {
} }
func _renderMarkdown(md []byte) ([]byte, error) { func _renderMarkdown(md []byte) ([]byte, error) {
renderer := blackfriday.HtmlRenderer(blackfridayFlags, "", "") params := blackfriday.HTMLRendererParameters{
html := blackfriday.MarkdownOptions( Flags: blackfridayFlags,
}
renderer := blackfriday.NewHTMLRenderer(params)
html := blackfriday.Run(
md, md,
renderer, blackfriday.WithRenderer(renderer),
blackfriday.Options{Extensions: blackfridayExtensions}, blackfriday.WithExtensions(blackfridayExtensions),
) )
return html, nil return html, nil
} }