Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HTML comment in raw_html #34

Merged
merged 2 commits into from
Oct 9, 2015
Merged
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
1 change: 1 addition & 0 deletions lib/floki.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ defmodule Floki do
defp raw_html([], html), do: html
defp raw_html(tuple, html) when is_tuple(tuple), do: raw_html([tuple], html)
defp raw_html([value|tail], html) when is_binary(value), do: raw_html(tail, html <> value)
defp raw_html([{:comment, value}|tail], html), do: raw_html(tail, html <> "<!--#{value}-->")
defp raw_html([{elem, attrs, value}|tail], html) do
raw_html(tail, html <> tag_for(elem, attrs |> tag_attrs, value))
end
Expand Down
7 changes: 6 additions & 1 deletion test/floki_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule FlokiTest do
</body>
</html>
"""

@html_without_html_tag """
<h2 class="js-cool">One</h2>
<p>Two</p>
Expand Down Expand Up @@ -144,6 +144,11 @@ defmodule FlokiTest do
assert raw_html == String.split(raw_html, "\n") |> Enum.map(&(String.strip(&1))) |> Enum.join("")
end

test "raw_html (with comment)" do
raw_html = Floki.parse(@html_with_img) |> Floki.raw_html
assert raw_html == String.split(raw_html, "\n") |> Enum.map(&(String.strip(&1))) |> Enum.join("")
end

test "raw_html (after find)" do
raw_html = Floki.parse(@basic_html) |> Floki.find("a") |> Floki.raw_html
assert raw_html == ~s(<a href="uol.com.br" class="bar"><span>UOL</span><img src="foo.png"/></a>)
Expand Down