diff --git a/lib/floki.ex b/lib/floki.ex index 5a6def7f..f203681f 100644 --- a/lib/floki.ex +++ b/lib/floki.ex @@ -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 <> "") defp raw_html([{elem, attrs, value}|tail], html) do raw_html(tail, html <> tag_for(elem, attrs |> tag_attrs, value)) end diff --git a/test/floki_test.exs b/test/floki_test.exs index 29f5fd04..8885fae1 100644 --- a/test/floki_test.exs +++ b/test/floki_test.exs @@ -47,7 +47,7 @@ defmodule FlokiTest do """ - + @html_without_html_tag """

One

Two

@@ -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(UOL)