Scope the title tag selector to the head element
This commit is contained in:
parent
4936a3f625
commit
91dcb1e285
|
@ -33,7 +33,7 @@ defmodule Readability.TitleFinder do
|
||||||
@spec tag_title(html_tree) :: binary
|
@spec tag_title(html_tree) :: binary
|
||||||
def tag_title(html_tree) do
|
def tag_title(html_tree) do
|
||||||
html_tree
|
html_tree
|
||||||
|> Floki.find("title")
|
|> Floki.find("head title")
|
||||||
|> clean_title()
|
|> clean_title()
|
||||||
|> String.split(@title_suffix)
|
|> String.split(@title_suffix)
|
||||||
|> hd()
|
|> hd()
|
||||||
|
|
|
@ -71,6 +71,19 @@ defmodule Readability.TitleFinderTest do
|
||||||
"""
|
"""
|
||||||
title = Readability.TitleFinder.tag_title(html)
|
title = Readability.TitleFinder.tag_title(html)
|
||||||
assert title == "Tag title-tag-title"
|
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
|
end
|
||||||
|
|
||||||
test "extract h1 tag title" do
|
test "extract h1 tag title" do
|
||||||
|
|
Loading…
Reference in New Issue