@@ -169,14 +169,16 @@ func (r *hugoContextRenderer) getPage(w util.BufWriter) any {
169
169
return p
170
170
}
171
171
172
+ func (r * hugoContextRenderer ) isHTMLComment (b []byte ) bool {
173
+ return len (b ) > 4 && b [0 ] == '<' && b [1 ] == '!' && b [2 ] == '-' && b [3 ] == '-'
174
+ }
175
+
172
176
// HTML rendering based on Goldmark implementation.
173
177
func (r * hugoContextRenderer ) renderHTMLBlock (
174
178
w util.BufWriter , source []byte , node ast.Node , entering bool ,
175
179
) (ast.WalkStatus , error ) {
176
180
n := node .(* ast.HTMLBlock )
177
- isHTMLComment := func (b []byte ) bool {
178
- return len (b ) > 4 && b [0 ] == '<' && b [1 ] == '!' && b [2 ] == '-' && b [3 ] == '-'
179
- }
181
+
180
182
if entering {
181
183
if r .Unsafe {
182
184
l := n .Lines ().Len ()
@@ -193,7 +195,7 @@ func (r *hugoContextRenderer) renderHTMLBlock(
193
195
} else {
194
196
l := n .Lines ().At (0 )
195
197
v := l .Value (source )
196
- if ! isHTMLComment (v ) {
198
+ if ! r . isHTMLComment (v ) {
197
199
r .logRawHTMLEmittedWarn (w )
198
200
_ , _ = w .WriteString ("<!-- raw HTML omitted -->\n " )
199
201
}
@@ -206,7 +208,7 @@ func (r *hugoContextRenderer) renderHTMLBlock(
206
208
} else {
207
209
l := n .Lines ().At (0 )
208
210
v := l .Value (source )
209
- if ! isHTMLComment (v ) {
211
+ if ! r . isHTMLComment (v ) {
210
212
_ , _ = w .WriteString ("<!-- raw HTML omitted -->\n " )
211
213
}
212
214
}
@@ -221,17 +223,21 @@ func (r *hugoContextRenderer) renderRawHTML(
221
223
if ! entering {
222
224
return ast .WalkSkipChildren , nil
223
225
}
226
+ n := node .(* ast.RawHTML )
227
+ l := n .Segments .Len ()
224
228
if r .Unsafe {
225
- n := node .(* ast.RawHTML )
226
- l := n .Segments .Len ()
227
229
for i := 0 ; i < l ; i ++ {
228
230
segment := n .Segments .At (i )
229
231
_ , _ = w .Write (segment .Value (source ))
230
232
}
231
233
return ast .WalkSkipChildren , nil
232
234
}
233
- r .logRawHTMLEmittedWarn (w )
234
- _ , _ = w .WriteString ("<!-- raw HTML omitted -->" )
235
+ segment := n .Segments .At (0 )
236
+ v := segment .Value (source )
237
+ if ! r .isHTMLComment (v ) {
238
+ r .logRawHTMLEmittedWarn (w )
239
+ _ , _ = w .WriteString ("<!-- raw HTML omitted -->" )
240
+ }
235
241
return ast .WalkSkipChildren , nil
236
242
}
237
243
0 commit comments