Skip to content

Commit

Permalink
markup/goldmark: Only log Raw HTML omitted WARN on block entering
Browse files Browse the repository at this point in the history
Updates #12997
  • Loading branch information
bep committed Nov 4, 2024
1 parent 62a96ce commit 6cf23bf
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions markup/goldmark/hugocontext/hugocontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,12 @@ func (r *hugoContextRenderer) renderHTMLBlock(
w util.BufWriter, source []byte, node ast.Node, entering bool,
) (ast.WalkStatus, error) {
n := node.(*ast.HTMLBlock)
var p any
ctx, ok := w.(*render.Context)
if ok {
p, _ = render.GetPageAndPageInner(ctx)
}
if !r.Unsafe {
r.logger.Warnidf(constants.WarnGoldmarkRawHTML, "Raw HTML omitted from %q; see https://gohugo.io/getting-started/configuration-markup/#rendererunsafe", p)
}
if entering {
var p any
ctx, ok := w.(*render.Context)
if ok {
p, _ = render.GetPageAndPageInner(ctx)
}
if r.Unsafe {
l := n.Lines().Len()
for i := 0; i < l; i++ {
Expand All @@ -178,10 +175,10 @@ func (r *hugoContextRenderer) renderHTMLBlock(
if stripped {
r.logger.Warnidf(constants.WarnRenderShortcodesInHTML, ".RenderShortcodes detected inside HTML block in %q; this may not be what you intended, see https://gohugo.io/methods/page/rendershortcodes/#limitations", p)
}

r.Writer.SecureWrite(w, linev)
}
} else {
r.logger.Warnidf(constants.WarnGoldmarkRawHTML, "Raw HTML omitted from %q; see https://gohugo.io/getting-started/configuration-markup/#rendererunsafe", p)
_, _ = w.WriteString("<!-- raw HTML omitted -->\n")
}
} else {
Expand Down

0 comments on commit 6cf23bf

Please sign in to comment.