1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-26 19:24:45 +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
})
e.RegisterFilter("jsonify", json.Marshal)
e.RegisterFilter("markdownify", blackfriday.MarkdownCommon)
e.RegisterFilter("markdownify", blackfriday.Run)
e.RegisterFilter("normalize_whitespace", func(s string) string {
// s = strings.Replace(s, "n", "N", -1)
wsPattern := regexp.MustCompile(`(?s:[\s\n]+)`)

View File

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