Current section

86 Versions

Jump to

Compare versions

9 files changed
+50 additions
-26 deletions
  @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7 7
8 8 ## [Unreleased][unreleased]
9 9
10 + ## [0.34.2] - 2023-02-24
11 +
12 + ### Added
13 +
14 + - Add option to pass down arguments to the parser in `Floki.parse_document/2` and
15 + `Floki.parse_fragment/2`. Thanks [@Kuret](https://github.com/Kuret).
16 +
17 + - Add support for returning more elements from the `Floki.traverse_and_update/2` function callback.
18 + This enables the creation of more elements in the tree, but should be used with care,
19 + since the tree can grow a lot if the change is not controlled. Thanks [@martosaur](https://github.com/martosaur).
20 +
10 21 ## [0.34.1] - 2023-02-11
11 22
12 23 ### Fixed
  @@ -643,7 +654,8 @@ of the parent element inside HTML.
643 654
644 655 - Elixir version requirement from "~> 1.0.0" to ">= 1.0.0".
645 656
646 - [unreleased]: https://github.com/philss/floki/compare/v0.34.1...HEAD
657 + [unreleased]: https://github.com/philss/floki/compare/v0.34.2...HEAD
658 + [0.34.2]: https://github.com/philss/floki/compare/v0.34.1...v0.34.2
647 659 [0.34.1]: https://github.com/philss/floki/compare/v0.34.0...v0.34.1
648 660 [0.34.0]: https://github.com/philss/floki/compare/v0.33.1...v0.34.0
649 661 [0.33.1]: https://github.com/philss/floki/compare/v0.33.0...v0.33.1
  @@ -7,8 +7,7 @@
7 7 [<<"lib/floki">>,<<"lib/floki/deep_text.ex">>,<<"lib/floki/filter_out.ex">>,
8 8 <<"lib/floki/finder.ex">>,<<"lib/floki/flat_text.ex">>,<<"lib/floki/html">>,
9 9 <<"lib/floki/html/numeric_charref.ex">>,<<"lib/floki/html/tokenizer.ex">>,
10 - <<"lib/floki/html_parser.ex">>,<<"lib/floki/html_parser">>,
11 - <<"lib/floki/html_parser/fast_html.ex">>,
10 + <<"lib/floki/html_parser">>,<<"lib/floki/html_parser/fast_html.ex">>,
12 11 <<"lib/floki/html_parser/html5ever.ex">>,
13 12 <<"lib/floki/html_parser/mochiweb.ex">>,<<"lib/floki/html_tree.ex">>,
14 13 <<"lib/floki/html_tree">>,<<"lib/floki/html_tree/comment.ex">>,
  @@ -20,9 +19,10 @@
20 19 <<"lib/floki/selector/attribute_selector.ex">>,
21 20 <<"lib/floki/selector/combinator.ex">>,
22 21 <<"lib/floki/selector/pseudo_class.ex">>,<<"lib/floki/selector/parser.ex">>,
23 - <<"lib/floki/traversal.ex">>,<<"lib/floki/entities">>,
24 - <<"lib/floki/entities/codepoints.ex">>,<<"lib/floki/raw_html.ex">>,
25 - <<"lib/floki/selector.ex">>,<<"lib/floki/entities.ex">>,<<"lib/floki.ex">>,
22 + <<"lib/floki/entities">>,<<"lib/floki/entities/codepoints.ex">>,
23 + <<"lib/floki/raw_html.ex">>,<<"lib/floki/selector.ex">>,
24 + <<"lib/floki/entities.ex">>,<<"lib/floki/html_parser.ex">>,
25 + <<"lib/floki/traversal.ex">>,<<"lib/floki.ex">>,
26 26 <<"src/floki_selector_lexer.xrl">>,<<"src/floki_mochi_html.erl">>,
27 27 <<"src/floki.gleam">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,
28 28 <<"CODE_OF_CONDUCT.md">>,<<"CONTRIBUTING.md">>,<<"CHANGELOG.md">>]}.
  @@ -33,4 +33,4 @@
33 33 {<<"Sponsor">>,<<"https://github.com/sponsors/philss">>}]}.
34 34 {<<"name">>,<<"floki">>}.
35 35 {<<"requirements">>,[]}.
36 - {<<"version">>,<<"0.34.1">>}.
36 + {<<"version">>,<<"0.34.2">>}.
  @@ -372,9 +372,9 @@ defmodule Floki do
372 372 The tree is traversed in a post-walk fashion, where the children are traversed
373 373 before the parent.
374 374
375 - When the function `fun` encounters HTML tag, it receives a tuple with
376 - `{name, attributes, children}`, and should either return a similar tuple or
377 - `nil` to delete the current node.
375 + When the function `fun` encounters HTML tag, it receives a tuple with `{name,
376 + attributes, children}`, and should either return a similar tuple, a list of
377 + tuples to split current node or `nil` to delete it.
378 378
379 379 The function `fun` can also encounter HTML doctype, comment or declaration and
380 380 will receive, and should return, different tuple for these types. See the
  @@ -404,7 +404,7 @@ defmodule Floki do
404 404
405 405 @spec traverse_and_update(
406 406 html_node() | html_tree(),
407 - (html_node() -> html_node() | nil)
407 + (html_node() -> html_node() | [html_node()] | nil)
408 408 ) :: html_node() | html_tree()
409 409
410 410 defdelegate traverse_and_update(html_tree, fun), to: Floki.Traversal
  @@ -458,7 +458,7 @@ defmodule Floki do
458 458 html_node() | html_tree(),
459 459 traverse_acc,
460 460 (html_node(), traverse_acc ->
461 - {html_node() | nil, traverse_acc})
461 + {html_node() | [html_node()] | nil, traverse_acc})
462 462 ) :: {html_node() | html_tree(), traverse_acc}
463 463 when traverse_acc: any()
464 464 defdelegate traverse_and_update(html_tree, acc, fun), to: Floki.Traversal
  @@ -21,15 +21,19 @@ defmodule Floki.HTMLParser do
21 21
22 22 @default_parser Floki.HTMLParser.Mochiweb
23 23
24 - @callback parse_document(binary()) :: {:ok, Floki.html_tree()} | {:error, String.t()}
25 - @callback parse_fragment(binary()) :: {:ok, Floki.html_tree()} | {:error, String.t()}
24 + @callback parse_document(binary(), list()) :: {:ok, Floki.html_tree()} | {:error, String.t()}
25 + @callback parse_fragment(binary(), list()) :: {:ok, Floki.html_tree()} | {:error, String.t()}
26 26
27 27 def parse_document(html, opts \\ []) do
28 - parser(opts).parse_document(html)
28 + parser_args = opts[:parser_args] || []
29 +
30 + parser(opts).parse_document(html, parser_args)
29 31 end
30 32
31 33 def parse_fragment(html, opts \\ []) do
32 - parser(opts).parse_fragment(html)
34 + parser_args = opts[:parser_args] || []
35 +
36 + parser(opts).parse_fragment(html, parser_args)
33 37 end
34 38
35 39 defp parser(opts) do
  @@ -3,13 +3,13 @@ defmodule Floki.HTMLParser.FastHtml do
3 3 @moduledoc false
4 4
5 5 @impl true
6 - def parse_document(html) do
7 - execute_with_module(fn module -> module.decode(html) end)
6 + def parse_document(html, args) do
7 + execute_with_module(fn module -> module.decode(html, args) end)
8 8 end
9 9
10 10 @impl true
11 - def parse_fragment(html) do
12 - execute_with_module(fn module -> module.decode_fragment(html) end)
11 + def parse_fragment(html, args) do
12 + execute_with_module(fn module -> module.decode_fragment(html, args) end)
13 13 end
14 14
15 15 defp execute_with_module(fun) do
Loading more files…