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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,16 @@ func (ps *Parser) grabArticle() *html.Node {
// the scoring algorithm with DIVs with are, in
// practice, paragraphs.
if ps.hasSingleTagInsideElement(node, "p") && ps.getLinkDensity(node) < 0.25 {
divID := dom.ID(node)
divClassName := dom.ClassName(node)
newNode := dom.Children(node)[0]
node, _ = dom.ReplaceChild(node.Parent, newNode, node)
if divID != "" && dom.ID(node) == "" {
dom.SetAttribute(node, "id", divID)
}
if divClassName != "" && dom.ClassName(node) == "" {
dom.SetAttribute(node, "class", divClassName)
}
elementsToScore = append(elementsToScore, node)
} else if !ps.hasChildBlockElement(node) {
ps.setNodeTag(node, "p")
Expand Down
2 changes: 1 addition & 1 deletion test-pages/gmw/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<a href="http://www.gmw.cn" target="_blank"><img src="https://img.gmw.cn/pic/content_logo.png" title="返回光明网首页"/></a>
</p>

<p>[责任编辑:肖春芳]</p>
<p id="contentLiability">[责任编辑:肖春芳]</p>


</div></div>
4 changes: 2 additions & 2 deletions test-pages/lazy-image-1/expected.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2 id="292e">
(for more details about V8 and its garbage collector you can read my previous article <a target="_blank" rel="noopener" href="http://fakehost/voodoo-engineering/nodejs-internals-v8-garbage-collector-a6eca82540ec">here</a>)
</p>
<blockquote>
<p>
<p id="6f9a">
Stay focused on the CPU!
</p>
</blockquote>
Expand All @@ -61,7 +61,7 @@ <h2 id="8d00">
CPU profiling: what’s the difference with CPU monitoring?
</h2>
<blockquote>
<p>
<p id="19fb">
“Most commonly, profiling information serves to aid program optimization. Profiling is achieved by instrumenting either the program source code or its binary executable form using a tool called a profiler”
</p>
</blockquote>
Expand Down