mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-10 21:17:54 +00:00
helpers: Support EXTENSION_BACKSLASH_LINE_BREAK for Blackfriday
Exposed as "backslashLineBreak" and enabled by default as upstream have done. Fixes #1935
This commit is contained in:
parent
4c4ce55217
commit
2c5e4f7640
2 changed files with 25 additions and 7 deletions
|
@ -55,7 +55,7 @@ type Blackfriday struct {
|
||||||
ExtensionsMask []string
|
ExtensionsMask []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults
|
// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults.
|
||||||
func NewBlackfriday() *Blackfriday {
|
func NewBlackfriday() *Blackfriday {
|
||||||
combinedParam := map[string]interface{}{
|
combinedParam := map[string]interface{}{
|
||||||
"smartypants": true,
|
"smartypants": true,
|
||||||
|
@ -100,6 +100,7 @@ var blackfridayExtensionMap = map[string]int{
|
||||||
"headerIds": blackfriday.EXTENSION_HEADER_IDS,
|
"headerIds": blackfriday.EXTENSION_HEADER_IDS,
|
||||||
"titleblock": blackfriday.EXTENSION_TITLEBLOCK,
|
"titleblock": blackfriday.EXTENSION_TITLEBLOCK,
|
||||||
"autoHeaderIds": blackfriday.EXTENSION_AUTO_HEADER_IDS,
|
"autoHeaderIds": blackfriday.EXTENSION_AUTO_HEADER_IDS,
|
||||||
|
"backslashLineBreak": blackfriday.EXTENSION_BACKSLASH_LINE_BREAK,
|
||||||
"definitionLists": blackfriday.EXTENSION_DEFINITION_LISTS,
|
"definitionLists": blackfriday.EXTENSION_DEFINITION_LISTS,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ func BytesToHTML(b []byte) template.HTML {
|
||||||
return template.HTML(string(b))
|
return template.HTML(string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
// getHTMLRenderer creates a new Renderer with the given configuration.
|
// getHTMLRenderer creates a new Blackfriday HTML Renderer with the given configuration.
|
||||||
func getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
func getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
|
||||||
renderParameters := blackfriday.HtmlRendererParameters{
|
renderParameters := blackfriday.HtmlRendererParameters{
|
||||||
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"),
|
||||||
|
@ -207,12 +208,23 @@ func getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Render
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMarkdownExtensions(ctx *RenderingContext) int {
|
func getMarkdownExtensions(ctx *RenderingContext) int {
|
||||||
flags := 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
// Default Blackfriday common extensions
|
||||||
blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE |
|
commonExtensions := 0 |
|
||||||
blackfriday.EXTENSION_AUTOLINK | blackfriday.EXTENSION_STRIKETHROUGH |
|
blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
||||||
blackfriday.EXTENSION_SPACE_HEADERS | blackfriday.EXTENSION_FOOTNOTES |
|
blackfriday.EXTENSION_TABLES |
|
||||||
blackfriday.EXTENSION_HEADER_IDS | blackfriday.EXTENSION_AUTO_HEADER_IDS |
|
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.EXTENSION_DEFINITION_LISTS
|
||||||
|
|
||||||
|
// Extra Blackfriday extensions that Hugo enables by default
|
||||||
|
flags := commonExtensions |
|
||||||
|
blackfriday.EXTENSION_AUTO_HEADER_IDS |
|
||||||
|
blackfriday.EXTENSION_FOOTNOTES
|
||||||
|
|
||||||
for _, extension := range ctx.getConfig().Extensions {
|
for _, extension := range ctx.getConfig().Extensions {
|
||||||
if flag, ok := blackfridayExtensionMap[extension]; ok {
|
if flag, ok := blackfridayExtensionMap[extension]; ok {
|
||||||
flags |= flag
|
flags |= flag
|
||||||
|
|
|
@ -244,10 +244,16 @@ func TestGetMarkdownExtensionsByDefaultAllExtensionsAreEnabled(t *testing.T) {
|
||||||
{blackfriday.EXTENSION_FENCED_CODE},
|
{blackfriday.EXTENSION_FENCED_CODE},
|
||||||
{blackfriday.EXTENSION_AUTOLINK},
|
{blackfriday.EXTENSION_AUTOLINK},
|
||||||
{blackfriday.EXTENSION_STRIKETHROUGH},
|
{blackfriday.EXTENSION_STRIKETHROUGH},
|
||||||
|
// {blackfriday.EXTENSION_LAX_HTML_BLOCKS},
|
||||||
{blackfriday.EXTENSION_SPACE_HEADERS},
|
{blackfriday.EXTENSION_SPACE_HEADERS},
|
||||||
|
// {blackfriday.EXTENSION_HARD_LINE_BREAK},
|
||||||
|
// {blackfriday.EXTENSION_TAB_SIZE_EIGHT},
|
||||||
{blackfriday.EXTENSION_FOOTNOTES},
|
{blackfriday.EXTENSION_FOOTNOTES},
|
||||||
|
// {blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK},
|
||||||
{blackfriday.EXTENSION_HEADER_IDS},
|
{blackfriday.EXTENSION_HEADER_IDS},
|
||||||
|
// {blackfriday.EXTENSION_TITLEBLOCK},
|
||||||
{blackfriday.EXTENSION_AUTO_HEADER_IDS},
|
{blackfriday.EXTENSION_AUTO_HEADER_IDS},
|
||||||
|
{blackfriday.EXTENSION_BACKSLASH_LINE_BREAK},
|
||||||
{blackfriday.EXTENSION_DEFINITION_LISTS},
|
{blackfriday.EXTENSION_DEFINITION_LISTS},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue