Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions helpers/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ var SummaryLength = 70
var SummaryDivider = []byte("<!--more-->")

type ContentSpec struct {
blackfriday map[string]interface{}
footnoteAnchorPrefix string
footnoteReturnLinkContents string

cfg config.Provider
}

func NewContentSpec(cfg config.Provider) *ContentSpec {
return &ContentSpec{cfg}
return &ContentSpec{
blackfriday: cfg.GetStringMap("blackfriday"),
footnoteAnchorPrefix: cfg.GetString("footnoteAnchorPrefix"),
footnoteReturnLinkContents: cfg.GetString("footnoteReturnLinkContents"),

cfg: cfg,
}
}

// Blackfriday holds configuration values for Blackfriday rendering.
Expand Down Expand Up @@ -84,16 +94,14 @@ func (c ContentSpec) NewBlackfriday() *Blackfriday {

ToLowerMap(defaultParam)

siteParam := c.cfg.GetStringMap("blackfriday")

siteConfig := make(map[string]interface{})

for k, v := range defaultParam {
siteConfig[k] = v
}

if siteParam != nil {
for k, v := range siteParam {
if c.blackfriday != nil {
for k, v := range c.blackfriday {
siteConfig[k] = v
}
}
Expand Down Expand Up @@ -198,13 +206,15 @@ func BytesToHTML(b []byte) template.HTML {
// getHTMLRenderer creates a new Blackfriday HTML Renderer with the given configuration.
func (c ContentSpec) getHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Renderer {
renderParameters := blackfriday.HtmlRendererParameters{
FootnoteAnchorPrefix: c.cfg.GetString("footnoteAnchorPrefix"),
FootnoteReturnLinkContents: c.cfg.GetString("footnoteReturnLinkContents"),
FootnoteAnchorPrefix: c.footnoteAnchorPrefix,
FootnoteReturnLinkContents: c.footnoteReturnLinkContents,
}

b := len(ctx.DocumentID) != 0

if b && !ctx.getConfig().PlainIDAnchors {
config := ctx.getConfig()

if b && !config.PlainIDAnchors {
renderParameters.FootnoteAnchorPrefix = ctx.DocumentID + ":" + renderParameters.FootnoteAnchorPrefix
renderParameters.HeaderIDSuffix = ":" + ctx.DocumentID
}
Expand All @@ -213,27 +223,27 @@ func (c ContentSpec) getHTMLRenderer(defaultFlags int, ctx *RenderingContext) bl
htmlFlags |= blackfriday.HTML_USE_XHTML
htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS

if ctx.getConfig().Smartypants {
if config.Smartypants {
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
}

if ctx.getConfig().AngledQuotes {
if config.AngledQuotes {
htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES
}

if ctx.getConfig().Fractions {
if config.Fractions {
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
}

if ctx.getConfig().HrefTargetBlank {
if config.HrefTargetBlank {
htmlFlags |= blackfriday.HTML_HREF_TARGET_BLANK
}

if ctx.getConfig().SmartDashes {
if config.SmartDashes {
htmlFlags |= blackfriday.HTML_SMARTYPANTS_DASHES
}

if ctx.getConfig().LatexDashes {
if config.LatexDashes {
htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
}

Expand Down Expand Up @@ -287,8 +297,8 @@ func (c ContentSpec) markdownRender(ctx *RenderingContext) []byte {
// getMmarkHTMLRenderer creates a new mmark HTML Renderer with the given configuration.
func (c ContentSpec) getMmarkHTMLRenderer(defaultFlags int, ctx *RenderingContext) mmark.Renderer {
renderParameters := mmark.HtmlRendererParameters{
FootnoteAnchorPrefix: c.cfg.GetString("footnoteAnchorPrefix"),
FootnoteReturnLinkContents: c.cfg.GetString("footnoteReturnLinkContents"),
FootnoteAnchorPrefix: c.footnoteAnchorPrefix,
FootnoteReturnLinkContents: c.footnoteReturnLinkContents,
}

b := len(ctx.DocumentID) != 0
Expand Down
3 changes: 2 additions & 1 deletion tpl/tplimpl/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,8 @@ func (t *templateFuncster) markdownify(in interface{}) (template.HTML, error) {

m := t.ContentSpec.RenderBytes(&helpers.RenderingContext{
Cfg: t.Cfg,
Content: []byte(text), PageFmt: "markdown"})
Content: []byte(text), PageFmt: "markdown",
Config: t.ContentSpec.NewBlackfriday()})
m = bytes.TrimPrefix(m, markdownTrimPrefix)
m = bytes.TrimSuffix(m, markdownTrimSuffix)
return template.HTML(m), nil
Expand Down