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

Enable parse of IO data html #504

Merged
merged 1 commit into from
Dec 18, 2023
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
4 changes: 2 additions & 2 deletions lib/floki/html_parser/fast_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ defmodule Floki.HTMLParser.FastHtml do

@impl true
def parse_document(html, args) do
execute_with_module(fn module -> module.decode(html, args) end)
execute_with_module(fn module -> module.decode(IO.chardata_to_string(html), args) end)
end

@impl true
def parse_fragment(html, args) do
execute_with_module(fn module -> module.decode_fragment(html, args) end)
execute_with_module(fn module -> module.decode_fragment(IO.chardata_to_string(html), args) end)
end

@impl true
Expand Down
2 changes: 1 addition & 1 deletion lib/floki/html_parser/html5ever.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Floki.HTMLParser.Html5ever do
def parse_document(html, _args) do
case Code.ensure_loaded(Html5ever) do
{:module, module} ->
case apply(module, :parse, [html]) do
case apply(module, :parse, [IO.chardata_to_string(html)]) do
{:ok, result} ->
{:ok, result}

Expand Down
2 changes: 1 addition & 1 deletion lib/floki/html_parser/mochiweb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Floki.HTMLParser.Mochiweb do

@impl true
def parse_document(html, args) do
html = "<#{@root_node}>#{html}</#{@root_node}>"
html = ["<#{@root_node}>", html, "</#{@root_node}>"]
{@root_node, _, parsed} = :floki_mochi_html.parse(html, args)

{:ok, parsed}
Expand Down
8 changes: 4 additions & 4 deletions test/floki_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ defmodule FlokiTest do

raw_html = Floki.raw_html(document!(html))

assert raw_html == html
assert raw_html == IO.chardata_to_string(html)

html_with_doctype = [
{:doctype, "html", "", ""},
Expand All @@ -283,7 +283,7 @@ defmodule FlokiTest do

parsed = document!(span_with_entities)

assert Floki.raw_html(parsed) == span_with_entities
assert Floki.raw_html(parsed) == IO.chardata_to_string(span_with_entities)
end

test "raw_html/1 with plain text" do
Expand Down Expand Up @@ -1858,7 +1858,7 @@ defmodule FlokiTest do
end)
|> Floki.raw_html()

assert result == expects
assert result == IO.chardata_to_string(expects)
end

test "changing attribute don't change the order of nodes" do
Expand Down Expand Up @@ -1986,7 +1986,7 @@ defmodule FlokiTest do
end

defp html_body(body) do
"<html><head></head><body>#{body}</body></html>"
["<html><head></head><body>", body, "</body></html>"]
end

defp document!(html_string, opts \\ []) do
Expand Down
Loading