Skip to content

Commit 9147828

Browse files
committed
fix processor node range
1 parent 4a11446 commit 9147828

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

modules/markup/html.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path"
1111
"path/filepath"
1212
"regexp"
13+
"slices"
1314
"strings"
1415
"sync"
1516

@@ -1006,7 +1007,12 @@ func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) {
10061007
if ctx.Metas == nil {
10071008
return
10081009
}
1009-
for node != nil {
1010+
nodeStop := node.NextSibling
1011+
for node != nodeStop {
1012+
if node.Type != html.TextNode {
1013+
node = node.NextSibling
1014+
continue
1015+
}
10101016
ret, ok := anyHashPatternExtract(node.Data)
10111017
if !ok {
10121018
node = node.NextSibling
@@ -1028,19 +1034,16 @@ func comparePatternProcessor(ctx *RenderContext, node *html.Node) {
10281034
if ctx.Metas == nil {
10291035
return
10301036
}
1031-
1032-
next := node.NextSibling
1033-
for node != nil && node != next {
1034-
m := comparePattern.FindStringSubmatchIndex(node.Data)
1035-
if m == nil {
1036-
return
1037+
nodeStop := node.NextSibling
1038+
for node != nodeStop {
1039+
if node.Type != html.TextNode {
1040+
node = node.NextSibling
1041+
continue
10371042
}
1038-
1039-
// Ensure that every group (m[0]...m[7]) has a match
1040-
for i := 0; i < 8; i++ {
1041-
if m[i] == -1 {
1042-
return
1043-
}
1043+
m := comparePattern.FindStringSubmatchIndex(node.Data)
1044+
if m == nil || slices.Contains(m, -1) {
1045+
node = node.NextSibling
1046+
continue
10441047
}
10451048

10461049
urlFull := node.Data[m[0]:m[1]]

modules/markup/html_codepreview.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ func renderCodeBlock(ctx *RenderContext, node *html.Node) (urlPosStart, urlPosSt
6060
}
6161

6262
func codePreviewPatternProcessor(ctx *RenderContext, node *html.Node) {
63-
for node != nil {
63+
nodeStop := node.NextSibling
64+
for node != nodeStop {
6465
if node.Type != html.TextNode {
6566
node = node.NextSibling
6667
continue

0 commit comments

Comments
 (0)