Merge pull request #18 from pineconellc/fix_title_tag_finder

Scope the title tag selector to the head element
This commit is contained in:
Jaehyun Shin 2016-11-22 13:49:18 +09:00 committed by GitHub
commit 203efa28d4
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