Scope the title tag selector to the head element

This commit is contained in:
Jeff Browning 2016-11-14 17:54:12 -05:00
parent 4936a3f625
commit 91dcb1e285
2 changed files with 14 additions and 1 deletions

View File

@ -33,7 +33,7 @@ defmodule Readability.TitleFinder do
@spec tag_title(html_tree) :: binary
def tag_title(html_tree) do
html_tree
|> Floki.find("title")
|> Floki.find("head title")
|> clean_title()
|> String.split(@title_suffix)
|> hd()

View File

@ -71,6 +71,19 @@ defmodule Readability.TitleFinderTest do
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title-tag-title"
html = """
<html>
<head>
<title>Tag title</title>
</head>
<body>
<svg><title>SVG title</title></svg>
</body>
</html>
"""
title = Readability.TitleFinder.tag_title(html)
assert title == "Tag title"
end
test "extract h1 tag title" do