Backtestshugorun-20261024-162305#14044

Issue #14044 Merged fix PR #15353 Run 24 Oct 2026 · run-20261024-162305 gohugoio/hugo

Automatic summary may generate invalid HTML with blockquotes and lists

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches fix the reported automatic-summary cases (all seven independent tests pass on A and B), so the decision rests on how each extends the cutoff and on test quality. Patch A balances every element opened since the wrapper start, including generic containers like div. That means any raw-HTML div wrapper in Markdown, or the first section of a multi-section AsciiDoc document, will push the summary to the end of that container, potentially swallowing the whole content; it only falls back to the original cut when the container never closes. Patch B restricts extension to a whitelist of block elements (blockquote, lists, dl, table, figure, details) and documents why div/section are excluded, with explicit tests showing AsciiDoc sections, RST document wrappers and intro divs are not over-extended while AsciiDoc quote blocks still close correctly. B also reuses golang.org/x/net/html's tokenizer, which is already a Hugo dependency and handles comments, attributes, raw-text elements and case-folding, instead of A's hand-rolled scanner. B additionally handles the manual divider placed inside a blockquote or list, which is beyond the issue's literal ask but is low-risk and tested. B's tests are broader (nested blockquotes, lists in blockquotes, void elements, unclosed elements, several markup wrappers, divider cases). A's tests are adequate but it also rewrites the existing benchmark from b.Loop to b.N for no clear reason. Correctness risk of over-expansion in A plus B's stronger tests and more robust parsing make B the better fix.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

2h 15m

Wall-clock time in the container

Full test suite

No new failures

2,374 passed · 6 skipped · 2,425 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

387vs 226 merged

Changed lines, ours vs merged

<!--
Please do not use the issue queue for questions or troubleshooting. Unless you are certain that your issue is a software defect, use the forum:

https://discourse.gohugo.io
-->

<!-- Please answer these questions before submitting your issue. Thanks! -->

What version of Hugo are you using (hugo version)?

<pre>
$ hugo version
hugo v0.151.0+extended+withdeploy darwin/arm64 BuildDate=2025-10-02T13:30:36Z VendorInfo=brew
</pre>

Does this issue reproduce with the latest release?

Yes

Issue

Using a blockquote that extends past the .Summary cutoff causes the content below {{ .Summary }} to be treated as part of the blockquote until the end of the parent tag. Reproduction repo

<img width="848" height="652" alt="Image" src="https://github.com/user-attachments/assets/212f747c-af3c-4af5-89fe-78fe9dc04ebd" />

Hugo's .Summary may lead to blockquote end tag be below cutoff point

Explanation

In most modern browsers this html code will be parsed and rendered without errors

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
  <main>
    <blockquote>
      <p>1</p>
  </main>
</body>
</html>

Leading to shown in browser as a source

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
  <main>
    <blockquote>
      <p>1</p>
      <!-- This blockquote end tag was automatically inserted -->
    </blockquote>
  </main>
</body>
</html>

This is due to these parsing rules

An end tag whose tag name is one of: "address", "article", "aside", "blockquote", "button", "center", "details", "dialog", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "listing", "main", "menu", "nav", "ol", "pre", "search", "section", "select", "summary", "ul"

If the stack of open elements does not have an element in scope that is an HTML element with the same tag name as that of the token, then this is a parse error; ignore the token.

Otherwise, run these steps:

Generate implied end tags.

If the current node is not an HTML element with the same tag name as that of the token, then this is a parse error.

Pop elements from the stack of open elements until an HTML element with the same tag name as the token has been popped from the stack.

To Discuss

I think the best case scenario is for .Summary to handle generation of implied tags. But I am not sure how to do that myself.

For now I plan to provide a PR with fixes for a theme and docs, to avoid confusion and errors

The two patches

Our patch+385 −2
hugolib/page_test.goindex a50ff316b..ab2172bca 100644@@ -788,6 +788,77 @@ Content: {{ .Content }}| 		"Content: <p>This is <strong>summary</strong>.") } +// Issue 14044.+func TestSummaryAutoBlockquoteAndList(t *testing.T) {+	t.Parallel()+	b := Test(t, `+-- hugo.toml --+summaryLength = 2+[security]+allowContent = ['.*']+-- content/blockquote.md --+---+title: Blockquote+---+> One two+>+> Three four++Five six.+-- content/list.md --+---+title: List+---+- One two++- Three four++Five six.+-- content/manual.md --+---+title: Manual+---+> One two+>+> <!--more-->+>+> Three four++Five six.+-- content/manualhtml.html --+---+title: Manual HTML+---+<blockquote><p>One two</p><!--more--><p>Three four</p></blockquote><p>Five six.</p>+-- layouts/single.html --+Summary: {{ .Summary }}|Truncated: {{ .Truncated }}|+ContentWithoutSummary: {{ .ContentWithoutSummary }}|+`)++	b.AssertFileContent("public/manualhtml/index.html",+		"Summary: <blockquote><p>One two</p>\n\n\n\n<p>Three four</p></blockquote>|",+		"Truncated: true|",+		"ContentWithoutSummary: <p>Five six.</p>|",+	)++	b.AssertFileContent("public/blockquote/index.html",+		"Summary: <blockquote>\n<p>One two</p>\n<p>Three four</p>\n</blockquote>|",+		"Truncated: true|",+		"ContentWithoutSummary: <p>Five six.</p>|",+	)+	b.AssertFileContent("public/list/index.html",+		"Summary: <ul>\n<li>\n<p>One two</p>\n</li>\n<li>\n<p>Three four</p>\n</li>\n</ul>|",+		"Truncated: true|",+		"ContentWithoutSummary: <p>Five six.</p>|",+	)+	// The divider splits the blockquote in two, both halves balanced.+	b.AssertFileContent("public/manual/index.html",+		"Summary: <blockquote>\n<p>One two</p>\n</blockquote>|",+		"Truncated: true|",+		"ContentWithoutSummary: <blockquote>\n<p>Three four</p>\n</blockquote>\n<p>Five six.</p>|",+	)+}+ // #2973 func TestSummaryWithHTMLTagsOnNextLine(t *testing.T) { 	htesting.SkipSlowTestUnlessCI(t)resources/page/page_markup.goindex 8f58fc2ab..47193a9f3 100644@@ -25,6 +25,7 @@ import ( 	"github.com/gohugoio/hugo/markup/tableofcontents" 	"github.com/gohugoio/hugo/media" 	"github.com/gohugoio/hugo/tpl"+	"golang.org/x/net/html" )  type Content interface {@@ -234,9 +235,12 @@ func ExtractSummaryFromHTML(mt media.Type, input string, numWords int, isCJK boo 		}  		if count >= numWords {+			low := result.WrapperStart.High+			cut := j + closingIndex + len(ptag.tagName) + 3+			// Make sure we don't cut inside e.g. a blockquote or a list. 			result.SummaryLowHigh = types.LowHigh[string]{-				Low:  result.WrapperStart.High,-				High: j + closingIndex + len(ptag.tagName) + 3,+				Low:  low,+				High: low + closeOpenElements(input[low:high], cut-low), 			} 			return 		}@@ -276,9 +280,144 @@ func ExtractSummaryFromHTMLWithDivider(mt media.Type, input, divider string) (re 		High: result.Divider.Low, 	} +	// If the divider is placed inside e.g. a blockquote or a list,+	// extend the summary to the end of the outermost open element.+	end := result.Divider.High+	endMarkupLow := result.Divider.High+	if !result.SummaryEndTag.IsZero() {+		end = result.SummaryEndTag.High+		endMarkupLow = result.SummaryEndTag.Low+	}+	high := len(input)+	if result.WrapperEnd.Low > 0 {+		high = result.WrapperEnd.Low+	}+	low := result.SummaryLowHigh.Low+	if end <= high {+		if closed := low + closeOpenElements(input[low:high], end-low); closed > end {+			result.SummaryEndTag = types.LowHigh[string]{Low: endMarkupLow, High: closed}+		}+	}+ 	return } +// htmlVoidElements are elements that never have an end tag.+var htmlVoidElements = map[string]bool{+	"area":   true,+	"base":   true,+	"br":     true,+	"col":    true,+	"embed":  true,+	"hr":     true,+	"img":    true,+	"input":  true,+	"keygen": true,+	"link":   true,+	"meta":   true,+	"param":  true,+	"source": true,+	"track":  true,+	"wbr":    true,+}++// htmlSummaryBlockElements are the block elements that the summary will not+// be cut inside. Generic containers such as div and section are not included,+// as they often wrap the entire content (e.g. AsciiDoc and Org sections).+var htmlSummaryBlockElements = map[string]bool{+	"blockquote": true,+	"details":    true,+	"dl":         true,+	"figure":     true,+	"ol":         true,+	"table":      true,+	"ul":         true,+}++// closeOpenElements returns a position >= cut in s where the outermost+// element in htmlSummaryBlockElements open at cut is closed, e.g. the end of+// a blockquote or list that the cut would otherwise split in two.+// Any end tags directly following that position are also included,+// e.g. the end of an AsciiDoc quote block's wrapper div.+// If no such element is open at cut, or it is never closed, cut is returned.+func closeOpenElements(s string, cut int) int {+	var (+		stack  []string+		offset int+		depth  = -1 // The stack depth to return to, set when cut is reached.+		end    = -1 // The position where depth was reached.+	)++	z := html.NewTokenizer(strings.NewReader(s))+	for {+		tt := z.Next()+		if tt == html.ErrorToken {+			// io.EOF or malformed input.+			if end != -1 {+				return end+			}+			return cut+		}+		offset += len(z.Raw())++		if end != -1 {+			// Include trailing whitespace and end tags closing open elements.+			switch tt {+			case html.TextToken:+				if strings.TrimSpace(string(z.Raw())) == "" {+					continue+				}+			case html.EndTagToken:+				name, _ := z.TagName()+				if len(stack) > 0 && stack[len(stack)-1] == string(name) {+					stack = stack[:len(stack)-1]+					end = offset+					continue+				}+			}+			return end+		}++		switch tt {+		case html.StartTagToken:+			name, _ := z.TagName()+			if !htmlVoidElements[string(name)] {+				stack = append(stack, string(name))+			}+		case html.EndTagToken:+			name, _ := z.TagName()+			// Pop up to and including the matching start tag, which also+			// handles elements with optional end tags (e.g. li).+			for i := len(stack) - 1; i >= 0; i-- {+				if stack[i] == string(name) {+					stack = stack[:i]+					break+				}+			}+		}++		if offset < cut {+			continue+		}++		if depth == -1 {+			for i, name := range stack {+				if htmlSummaryBlockElements[name] {+					depth = i+					break+				}+			}+			if depth == -1 {+				return cut+			}+		}++		if len(stack) <= depth {+			end = offset+		}+	}+}+ var ( 	pOrDiv = regexp.MustCompile(`<p[^>]?>|<div[^>]?>$`) resources/page/page_markup_test.goindex fc1102434..6b9180c4b 100644@@ -127,6 +127,179 @@ func TestExtractSummaryFromHTMLWithDivider(t *testing.T) { 	} } +// Issue 14044.+func TestExtractSummaryFromHTMLNestedBlocks(t *testing.T) {+	c := qt.New(t)++	tests := []struct {+		name                        string+		mt                          media.Type+		input                       string+		numWords                    int+		expectSummary               string+		expectContentWithoutSummary string+	}{+		{+			"blockquote",+			media.Builtin.MarkdownType,+			"<blockquote>\n<p>One two</p>\n<p>Three four</p>\n</blockquote>\n<p>Five six</p>",+			2,+			"<blockquote>\n<p>One two</p>\n<p>Three four</p>\n</blockquote>",+			"<p>Five six</p>",+		},+		{+			"nested blockquote",+			media.Builtin.MarkdownType,+			"<blockquote>\n<blockquote>\n<p>One two</p>\n</blockquote>\n<p>Three four</p>\n</blockquote>\n<p>Five six</p>",+			2,+			"<blockquote>\n<blockquote>\n<p>One two</p>\n</blockquote>\n<p>Three four</p>\n</blockquote>",+			"<p>Five six</p>",+		},+		{+			"unordered list",+			media.Builtin.MarkdownType,+			"<p>Intro</p>\n<ul>\n<li>\n<p>One two</p>\n</li>\n<li>\n<p>Three four</p>\n</li>\n</ul>\n<p>Five six</p>",+			2,+			"<p>Intro</p>\n<ul>\n<li>\n<p>One two</p>\n</li>\n<li>\n<p>Three four</p>\n</li>\n</ul>",+			"<p>Five six</p>",+		},+		{+			"ordered list in blockquote",+			media.Builtin.MarkdownType,+			"<blockquote>\n<ol>\n<li>\n<p>One two</p>\n</li>\n<li>\n<p>Three four</p>\n</li>\n</ol>\n</blockquote>\n<p>Five six</p>",+			1,+			"<blockquote>\n<ol>\n<li>\n<p>One two</p>\n</li>\n<li>\n<p>Three four</p>\n</li>\n</ol>\n</blockquote>",+			"<p>Five six</p>",+		},+		{+			"blockquote closed before cut",+			media.Builtin.MarkdownType,+			"<blockquote>\n<p>One</p>\n</blockquote>\n<p>Two three</p>\n<p>Four five</p>",+			2,+			"<blockquote>\n<p>One</p>\n</blockquote>\n<p>Two three</p>",+			"<p>Four five</p>",+		},+		{+			"void elements",+			media.Builtin.MarkdownType,+			"<blockquote>\n<p>One<br>two <img src=\"a.jpg\"></p>\n<hr>\n<p>Three</p>\n</blockquote>\n<p>Four</p>",+			2,+			"<blockquote>\n<p>One<br>two <img src=\"a.jpg\"></p>\n<hr>\n<p>Three</p>\n</blockquote>",+			"<p>Four</p>",+		},+		{+			"unclosed element keeps original cut",+			media.Builtin.MarkdownType,+			"<div>\n<p>One two</p>\n<p>Three four</p>",+			2,+			"<div>\n<p>One two</p>",+			"<p>Three four</p>",+		},+		{+			"blockquote in wrapper div",+			media.Builtin.MarkdownType,+			"<div class=\"intro\">\n<blockquote>\n<p>One two</p>\n<p>Three</p>\n</blockquote>\n<p>Four</p>\n</div>",+			2,+			"<div class=\"intro\">\n<blockquote>\n<p>One two</p>\n<p>Three</p>\n</blockquote>",+			"<p>Four</p>\n</div>",+		},+		{+			"wrapper div is not extended",+			media.Builtin.MarkdownType,+			"<div class=\"intro\">\n<p>One two</p>\n<p>Three four</p>\n</div>",+			2,+			"<div class=\"intro\">\n<p>One two</p>",+			"<p>Three four</p>\n</div>",+		},+		{+			"asciidoc section is not extended",+			media.Builtin.AsciiDocType,+			"<div class=\"sect1\"><h2>S</h2><div class=\"sectionbody\"><div class=\"paragraph\"><p>One two</p></div><div class=\"paragraph\"><p>Three four</p></div><div class=\"paragraph\"><p>Five six</p></div></div></div>",+			2,+			"<div class=\"sect1\"><h2>S</h2><div class=\"sectionbody\"><div class=\"paragraph\"><p>One two</p></div><div class=\"paragraph\"><p>Three four</p></div>",+			"<div class=\"paragraph\"><p>Five six</p></div></div></div>",+		},+		{+			"asciidoc quote block",+			media.Builtin.AsciiDocType,+			"<div class=\"quoteblock\"><blockquote><div class=\"paragraph\"><p>One two</p></div><div class=\"paragraph\"><p>Three</p></div></blockquote></div><div class=\"paragraph\"><p>Four</p></div>",+			2,+			"<div class=\"quoteblock\"><blockquote><div class=\"paragraph\"><p>One two</p></div><div class=\"paragraph\"><p>Three</p></div></blockquote></div>",+			"<div class=\"paragraph\"><p>Four</p></div>",+		},+		{+			"rst blockquote",+			media.Builtin.ReStructuredTextType,+			"<div class=\"document\"><blockquote><p>One two</p><p>Three</p></blockquote><p>Four</p></div>",+			2,+			"<div class=\"document\"><blockquote><p>One two</p><p>Three</p></blockquote></div>",+			"<div class=\"document\"><p>Four</p></div>",+		},+	}++	for _, test := range tests {+		c.Run(test.name, func(c *qt.C) {+			summary := ExtractSummaryFromHTML(test.mt, test.input, test.numWords, false)+			c.Assert(summary.Summary(), qt.Equals, test.expectSummary)+			c.Assert(summary.ContentWithoutSummary(), qt.Equals, test.expectContentWithoutSummary)+			c.Assert(summary.Content(), qt.Equals, test.input)+		})+	}+}++// Issue 14044.+func TestExtractSummaryFromHTMLWithDividerNestedBlocks(t *testing.T) {+	c := qt.New(t)++	const divider = "FOOO"++	tests := []struct {+		name                        string+		input                       string+		expectSummary               string+		expectContentWithoutSummary string+		expectContent               string+	}{+		{+			"divider paragraph in blockquote",+			"<blockquote>\n<p>One</p>\n<p>FOOO</p>\n<p>Two</p>\n</blockquote>\n<p>Three</p>",+			"<blockquote>\n<p>One</p>\n<p>Two</p>\n</blockquote>",+			"<p>Three</p>",+			"<blockquote>\n<p>One</p>\n<p>Two</p>\n</blockquote>\n<p>Three</p>",+		},+		{+			"divider at end of paragraph in list",+			"<ul>\n<li>\n<p>One FOOO</p>\n</li>\n<li>\n<p>Two</p>\n</li>\n</ul>\n<p>Three</p>",+			"<ul>\n<li>\n<p>One </p>\n</li>\n<li>\n<p>Two</p>\n</li>\n</ul>",+			"<p>Three</p>",+			"<ul>\n<li>\n<p>One </p>\n</li>\n<li>\n<p>Two</p>\n</li>\n</ul>\n<p>Three</p>",+		},+		{+			"divider at end of paragraph in blockquote",+			"<blockquote>\n<p>One FOOO</p>\n<p>Two</p>\n</blockquote>\n<p>Three</p>",+			"<blockquote>\n<p>One </p>\n<p>Two</p>\n</blockquote>",+			"<p>Three</p>",+			"<blockquote>\n<p>One </p>\n<p>Two</p>\n</blockquote>\n<p>Three</p>",+		},+		{+			"divider in wrapper div",+			"<div class=\"wrap\">\n<p>One</p>\n<p>FOOO</p>\n<p>Two</p>\n</div>",+			"<div class=\"wrap\">\n<p>One</p>",+			"<p>Two</p>\n</div>",+			"<div class=\"wrap\">\n<p>One</p>\n<p>Two</p>\n</div>",+		},+	}++	for _, test := range tests {+		c.Run(test.name, func(c *qt.C) {+			summary := ExtractSummaryFromHTMLWithDivider(media.Builtin.MarkdownType, test.input, divider)+			c.Assert(summary.Summary(), qt.Equals, test.expectSummary)+			c.Assert(summary.ContentWithoutSummary(), qt.Equals, test.expectContentWithoutSummary)+			c.Assert(summary.Content(), qt.Equals, test.expectContent)+		})+	}+}+ func TestExpandDivider(t *testing.T) { 	c := qt.New(t)  
Merged fix · PR #15353+210 −16
hugolib/page_test.goindex a50ff316b..88a6b22f3 100644@@ -788,6 +788,36 @@ Content: {{ .Content }}| 		"Content: <p>This is <strong>summary</strong>.") } +// See issue 14044.+func TestSummaryAutoBalancesContainerTags(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ['home','rss','section','sitemap','taxonomy','term']+summaryLength = 1+-- content/p1.md --+---+title: p1+---+> foo+-- content/p2.md --+---+title: p2+---+- item 1 line 1++  item 1 line 2+-- layouts/page.html --+|{{ .Summary }}|+`++	b := Test(t, files)++	b.AssertFileContent("public/p1/index.html", "|<blockquote>\n<p>foo</p>\n</blockquote>|")+	b.AssertFileContent("public/p2/index.html", "|<ul>\n<li>\n<p>item 1 line 1</p>\n<p>item 1 line 2</p>\n</li>\n</ul>|")+}+ // #2973 func TestSummaryWithHTMLTagsOnNextLine(t *testing.T) { 	htesting.SkipSlowTestUnlessCI(t)resources/page/page_markup.goindex 8f58fc2ab..572822b0b 100644@@ -234,9 +234,11 @@ func ExtractSummaryFromHTML(mt media.Type, input string, numWords int, isCJK boo 		}  		if count >= numWords {+			summaryHigh := j + closingIndex + len(ptag.tagName) + 3+			summaryHigh = expandSummaryHighToBalancedHTML(input, result.WrapperStart.High, summaryHigh, high) 			result.SummaryLowHigh = types.LowHigh[string]{ 				Low:  result.WrapperStart.High,-				High: j + closingIndex + len(ptag.tagName) + 3,+				High: summaryHigh, 			} 			return 		}@@ -253,6 +255,167 @@ func ExtractSummaryFromHTML(mt media.Type, input string, numWords int, isCJK boo 	return } +// expandSummaryHighToBalancedHTML moves high forward until every element+// opened in input[low:high] is closed, so the summary does not end inside+// e.g. a blockquote or list item.+func expandSummaryHighToBalancedHTML(input string, low, high, maxHigh int) int {+	if low >= high || high >= maxHigh {+		return high+	}++	var buf [16]string+	stack := buf[:0]+	sc := htmlTagScanner{s: input, pos: low}++	for {+		name, end, ok := sc.next(high)+		if !ok {+			break+		}+		stack = pushOrPopHTMLStack(stack, name, end)+	}++	if len(stack) == 0 {+		return high+	}++	for {+		name, end, ok := sc.next(maxHigh)+		if !ok {+			return high+		}+		stack = pushOrPopHTMLStack(stack, name, end)+		if len(stack) == 0 {+			return sc.pos+		}+	}+}++func pushOrPopHTMLStack(stack []string, name string, end bool) []string {+	if end {+		for i := len(stack) - 1; i >= 0; i-- {+			if stack[i] == name {+				return stack[:i]+			}+		}+		return stack+	}+	if isVoidHTMLElement(name) {+		return stack+	}+	return append(stack, name)+}++// htmlTagScanner is a minimal, allocation-free scanner for start and end tags.+// It skips comments, quoted attribute values and raw text elements.+type htmlTagScanner struct {+	s   string+	pos int+}++// next returns the lowercased name of the next tag before limit and+// whether it is an end tag. ok is false when no more tags are found.+func (sc *htmlTagScanner) next(limit int) (name string, end, ok bool) {+	for {+		i := strings.IndexByte(sc.s[sc.pos:limit], '<')+		if i == -1 {+			sc.pos = limit+			return "", false, false+		}+		sc.pos += i + 1+		if sc.pos >= limit {+			return "", false, false+		}++		end = false+		switch c := sc.s[sc.pos]; c {+		case '!', '?':+			if strings.HasPrefix(sc.s[sc.pos:limit], "!--") {+				sc.skipPast(limit, "-->")+			} else {+				sc.skipPast(limit, ">")+			}+			continue+		case '/':+			end = true+			sc.pos+++		}++		start := sc.pos+		for sc.pos < limit && isHTMLTagNameByte(sc.s[sc.pos]) {+			sc.pos+++		}+		if sc.pos == start {+			continue+		}+		name = strings.ToLower(sc.s[start:sc.pos])++		selfClosing := false+		for sc.pos < limit {+			c := sc.s[sc.pos]+			sc.pos+++			switch c {+			case '"', '\'':+				sc.skipPast(limit, string(c))+			case '/':+				selfClosing = true+			case '>':+				if selfClosing {+					continue+				}+				if !end && isRawTextHTMLElement(name) {+					sc.skipPastEndTag(limit, name)+				}+				return name, end, true+			default:+				selfClosing = false+			}+		}+		return name, end, true+	}+}++func (sc *htmlTagScanner) skipPast(limit int, sep string) {+	if i := strings.Index(sc.s[sc.pos:limit], sep); i == -1 {+		sc.pos = limit+	} else {+		sc.pos += i + len(sep)+	}+}++func (sc *htmlTagScanner) skipPastEndTag(limit int, name string) {+	for {+		sc.skipPast(limit, "</")+		if sc.pos >= limit {+			return+		}+		if rest := sc.s[sc.pos:limit]; len(rest) > len(name) && strings.EqualFold(rest[:len(name)], name) && !isHTMLTagNameByte(rest[len(name)]) {+			sc.pos -= 2+			return+		}+	}+}++func isHTMLTagNameByte(c byte) bool {+	return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '-'+}++func isRawTextHTMLElement(name string) bool {+	switch name {+	case "script", "style", "textarea", "title", "iframe", "xmp", "noembed", "noframes":+		return true+	}+	return false+}++func isVoidHTMLElement(name string) bool {+	switch name {+	case "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr":+		return true+	}+	return false+}+ // ExtractSummaryFromHTMLWithDivider extracts a summary from the given HTML content with // a manual summary divider. func ExtractSummaryFromHTMLWithDivider(mt media.Type, input, divider string) (result HtmlSummary) {resources/page/page_markup_test.goindex fc1102434..ee9fb1bbe 100644@@ -38,6 +38,14 @@ func TestExtractSummaryFromHTML(t *testing.T) { 		{media.Builtin.MarkdownType, "<p>First paragraph</p>", false, 10, "<p>First paragraph</p>", ""}, 		{media.Builtin.MarkdownType, "<p>First paragraph</p><p>Second paragraph</p>", false, 2, "<p>First paragraph</p>", "<p>Second paragraph</p>"}, 		{media.Builtin.MarkdownType, "<p>First paragraph</p><p>Second paragraph</p><p>Third paragraph</p>", false, 3, "<p>First paragraph</p><p>Second paragraph</p>", "<p>Third paragraph</p>"},+		{media.Builtin.MarkdownType, "<blockquote>\n<p>foo</p>\n</blockquote>\n<p>bar</p>", false, 1, "<blockquote>\n<p>foo</p>\n</blockquote>", "<p>bar</p>"},+		{media.Builtin.MarkdownType, "<ul>\n<li>\n<p>item 1 line 1</p>\n<p>item 1 line 2</p>\n</li>\n</ul>\n<p>bar</p>", false, 1, "<ul>\n<li>\n<p>item 1 line 1</p>\n<p>item 1 line 2</p>\n</li>\n</ul>", "<p>bar</p>"},+		{media.Builtin.HTMLType, "<div><p>foo</p></div><p>bar</p>", false, 1, "<div><p>foo</p></div>", "<p>bar</p>"},+		{media.Builtin.HTMLType, "<DIV><p>foo</p></DIV><p>bar</p>", false, 1, "<DIV><p>foo</p></DIV>", "<p>bar</p>"},+		{media.Builtin.HTMLType, "<div><!-- <span> --><p>foo</p></div><p>bar</p>", false, 1, "<div><!-- <span> --><p>foo</p></div>", "<p>bar</p>"},+		{media.Builtin.HTMLType, `<div><p title="a>b"><img src="x"/>foo</p></div><p>bar</p>`, false, 1, `<div><p title="a>b"><img src="x"/>foo</p></div>`, "<p>bar</p>"},+		{media.Builtin.HTMLType, "<div><script>var a = '<div>';</script><p>foo</p></div><p>bar</p>", false, 1, "<div><script>var a = '<div>';</script><p>foo</p></div>", "<p>bar</p>"},+		{media.Builtin.HTMLType, "<div><p>foo</p><p>bar</p>", false, 1, "<div><p>foo</p>", "<p>bar</p>"}, 		{media.Builtin.AsciiDocType, "<div><p>First paragraph</p></div><div><p>Second paragraph</p></div>", false, 2, "<div><p>First paragraph</p></div>", "<div><p>Second paragraph</p></div>"}, 		{media.Builtin.MarkdownType, "<p>这是中文,全中文</p><p>a这是中文,全中文</p>", true, 5, "<p>这是中文,全中文</p>", "<p>a这是中文,全中文</p>"}, 	}@@ -172,25 +180,18 @@ func TestIsProbablyHTMLToken(t *testing.T) { }  func BenchmarkSummaryFromHTML(b *testing.B) {--	input := "<p>First paragraph</p><p>Second paragraph</p>"--	for b.Loop() {-		summary := ExtractSummaryFromHTML(media.Builtin.MarkdownType, input, 2, false)-		if s := summary.Content(); s != input {-			b.Fatalf("unexpected content: %q", s)-		}-		if s := summary.ContentWithoutSummary(); s != "<p>Second paragraph</p>" {-			b.Fatalf("unexpected content without summary: %q", s)-		}-		if s := summary.Summary(); s != "<p>First paragraph</p>" {-			b.Fatalf("unexpected summary: %q", s)-		}+	run := func(name, input string) {+		b.Run(name, func(b *testing.B) {+			for i := 0; i < b.N; i++ {+				_ = ExtractSummaryFromHTML(media.Builtin.MarkdownType, input, 2, false)+			}+		}) 	}+	run("basic", "<p>First paragraph</p><p>Second paragraph</p>")+	run("list", "<ul>\n<li>\n<p>item 1 line 1</p>\n<p>item 1 line 2</p>\n</li>\n</ul>\n<p>bar</p>") }  func BenchmarkSummaryFromHTMLWithDivider(b *testing.B) {- 	input := "<p>First paragraph</p><p>FOOO</p><p>Second paragraph</p>"  	for b.Loop() {