Current section

86 Versions

Jump to

Compare versions

5 files changed
+84 additions
-23 deletions
  @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7 7
8 8 ## [Unreleased][unreleased]
9 9
10 + ## [0.31.0] - 2021-06-11
11 +
12 + ### Changed
13 +
14 + - Treat `style` and `title` tags as plaintext in Mochiweb - thanks [@SweetMNM](https://github.com/SweetMNM)
15 +
10 16 ## [0.30.1] - 2021-03-29
11 17
12 18 ### Fixed
  @@ -575,7 +581,8 @@ of the parent element inside HTML.
575 581
576 582 - Elixir version requirement from "~> 1.0.0" to ">= 1.0.0".
577 583
578 - [unreleased]: https://github.com/philss/floki/compare/v0.30.1...HEAD
584 + [unreleased]: https://github.com/philss/floki/compare/v0.31.0...HEAD
585 + [0.31.0]: https://github.com/philss/floki/compare/v0.30.1...v0.31.0
579 586 [0.30.1]: https://github.com/philss/floki/compare/v0.30.0...v0.30.1
580 587 [0.30.0]: https://github.com/philss/floki/compare/v0.29.0...v0.30.0
581 588 [0.29.0]: https://github.com/philss/floki/compare/v0.28.0...v0.29.0
  @@ -62,7 +62,7 @@ Add Floki to your `mix.exs`:
62 62 ```elixir
63 63 defp deps do
64 64 [
65 - {:floki, "~> 0.30.0"}
65 + {:floki, "~> 0.31.0"}
66 66 ]
67 67 end
68 68 ```
  @@ -121,7 +121,7 @@ After Rust is set up, you need to add `html5ever` NIF to your dependency list:
121 121 ```elixir
122 122 defp deps do
123 123 [
124 - {:floki, "~> 0.30.0"},
124 + {:floki, "~> 0.31.0"},
125 125 {:html5ever, "~> 0.8.0"}
126 126 ]
127 127 end
  @@ -149,7 +149,7 @@ First, add `fast_html` to your dependencies:
149 149 ```elixir
150 150 defp deps do
151 151 [
152 - {:floki, "~> 0.30.0"},
152 + {:floki, "~> 0.31.0"},
153 153 {:fast_html, "~> 2.0"}
154 154 ]
155 155 end
  @@ -4,25 +4,25 @@
4 4 <<"Floki is a simple HTML parser that enables search for nodes using CSS selectors.">>}.
5 5 {<<"elixir">>,<<"~> 1.8">>}.
6 6 {<<"files">>,
7 - [<<"lib">>,<<"lib/floki">>,<<"lib/floki/html_parser.ex">>,
8 - <<"lib/floki/html_parser">>,<<"lib/floki/html_parser/fast_html.ex">>,
7 + [<<"lib">>,<<"lib/floki.ex">>,<<"lib/floki">>,<<"lib/floki/html_tree.ex">>,
8 + <<"lib/floki/html_parser">>,<<"lib/floki/html_parser/html5ever.ex">>,
9 9 <<"lib/floki/html_parser/mochiweb.ex">>,
10 - <<"lib/floki/html_parser/html5ever.ex">>,<<"lib/floki/selector">>,
11 - <<"lib/floki/selector/functional.ex">>,<<"lib/floki/selector/parser.ex">>,
12 - <<"lib/floki/selector/attribute_selector.ex">>,
10 + <<"lib/floki/html_parser/fast_html.ex">>,<<"lib/floki/traversal.ex">>,
11 + <<"lib/floki/html_tree">>,<<"lib/floki/html_tree/text.ex">>,
12 + <<"lib/floki/html_tree/html_node.ex">>,<<"lib/floki/html_tree/comment.ex">>,
13 + <<"lib/floki/html_tree/id_seeder.ex">>,<<"lib/floki/selector.ex">>,
14 + <<"lib/floki/deep_text.ex">>,<<"lib/floki/flat_text.ex">>,
15 + <<"lib/floki/finder.ex">>,<<"lib/floki/filter_out.ex">>,
16 + <<"lib/floki/html_parser.ex">>,<<"lib/floki/selector">>,
13 17 <<"lib/floki/selector/pseudo_class.ex">>,
14 - <<"lib/floki/selector/tokenizer.ex">>,
15 - <<"lib/floki/selector/combinator.ex">>,<<"lib/floki/deep_text.ex">>,
16 - <<"lib/floki/filter_out.ex">>,<<"lib/floki/flat_text.ex">>,
17 - <<"lib/floki/finder.ex">>,<<"lib/floki/traversal.ex">>,
18 - <<"lib/floki/raw_html.ex">>,<<"lib/floki/parse_error.ex">>,
19 - <<"lib/floki/html_tree">>,<<"lib/floki/html_tree/id_seeder.ex">>,
20 - <<"lib/floki/html_tree/comment.ex">>,<<"lib/floki/html_tree/text.ex">>,
21 - <<"lib/floki/html_tree/html_node.ex">>,<<"lib/floki/selector.ex">>,
22 - <<"lib/floki/html_tree.ex">>,<<"lib/floki.ex">>,
23 - <<"src/floki_selector_lexer.xrl">>,<<"src/floki_mochi_html.erl">>,
24 - <<"src/floki.gleam">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,
25 - <<"CODE_OF_CONDUCT.md">>,<<"CONTRIBUTING.md">>,<<"CHANGELOG.md">>]}.
18 + <<"lib/floki/selector/attribute_selector.ex">>,
19 + <<"lib/floki/selector/functional.ex">>,
20 + <<"lib/floki/selector/combinator.ex">>,<<"lib/floki/selector/parser.ex">>,
21 + <<"lib/floki/selector/tokenizer.ex">>,<<"lib/floki/raw_html.ex">>,
22 + <<"lib/floki/parse_error.ex">>,<<"src/floki_selector_lexer.xrl">>,
23 + <<"src/floki_mochi_html.erl">>,<<"src/floki.gleam">>,<<"mix.exs">>,
24 + <<"README.md">>,<<"LICENSE">>,<<"CODE_OF_CONDUCT.md">>,
25 + <<"CONTRIBUTING.md">>,<<"CHANGELOG.md">>]}.
26 26 {<<"licenses">>,[<<"MIT">>]}.
27 27 {<<"links">>,
28 28 [{<<"Changelog">>,<<"https://hexdocs.pm/floki/changelog.html">>},
  @@ -36,4 +36,4 @@
36 36 {<<"optional">>,false},
37 37 {<<"repository">>,<<"hexpm">>},
38 38 {<<"requirement">>,<<"~> 0.5.0">>}]]}.
39 - {<<"version">>,<<"0.30.1">>}.
39 + {<<"version">>,<<"0.31.0">>}.
  @@ -3,7 +3,7 @@ defmodule Floki.Mixfile do
3 3
4 4 @description "Floki is a simple HTML parser that enables search for nodes using CSS selectors."
5 5 @source_url "https://github.com/philss/floki"
6 - @version "0.30.1"
6 + @version "0.31.0"
7 7
8 8 def project do
9 9 [
  @@ -308,6 +308,12 @@ tokens(B, S=#decoder{offset=O}, Acc) ->
308 308 script ->
309 309 {Tag2, S2} = tokenize_script(B, S1),
310 310 tokens(B, S2, [Tag2, Tag | Acc]);
311 + style ->
312 + {Tag2, S2} = tokenize_style(B, S1),
313 + tokens(B, S2, [Tag2, Tag | Acc]);
314 + title ->
315 + {Tag2, S2} = tokenize_title(B, S1),
316 + tokens(B, S2, [Tag2, Tag | Acc]);
311 317 textarea ->
312 318 {Tag2, S2} = tokenize_textarea(B, S1),
313 319 tokens(B, S2, [Tag2, Tag | Acc]);
  @@ -320,6 +326,10 @@ parse_flag({start_tag, B, _, false}) ->
320 326 case string:to_lower(binary_to_list(B)) of
321 327 "script" ->
322 328 script;
329 + "style" ->
330 + style;
331 + "title" ->
332 + title;
323 333 "textarea" ->
324 334 textarea;
325 335 _ ->
  @@ -802,6 +812,50 @@ tokenize_script(Bin, S=#decoder{offset=O}, Start) ->
802 812 {{data, Raw, false}, S}
803 813 end.
804 814
815 + tokenize_style(Bin, S=#decoder{offset=O}) ->
816 + tokenize_style(Bin, S, O).
817 +
818 + tokenize_style(Bin, S=#decoder{offset=O}, Start) ->
819 + case Bin of
820 + %% Just a look-ahead, we want the end_tag separately
821 + <<_:O/binary, $<, $/, SS, TT, YY, LL, EE, ZZ, _/binary>>
822 + when (SS =:= $s orelse SS =:= $S) andalso
823 + (TT=:= $t orelse TT =:= $T) andalso
824 + (YY=:= $y orelse YY =:= $Y) andalso
825 + (LL=:= $l orelse LL =:= $L) andalso
826 + (EE=:= $e orelse EE =:= $E) andalso
827 + ?PROBABLE_CLOSE(ZZ) ->
828 + Len = O - Start,
829 + <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
830 + {{data, Raw, false}, S};
831 + <<_:O/binary, C, _/binary>> ->
832 + tokenize_style(Bin, ?INC_CHAR(S, C), Start);
833 + <<_:Start/binary, Raw/binary>> ->
834 + {{data, Raw, false}, S}
835 + end.
836 +
837 + tokenize_title(Bin, S=#decoder{offset=O}) ->
838 + tokenize_title(Bin, S, O).
839 +
840 + tokenize_title(Bin, S=#decoder{offset=O}, Start) ->
841 + case Bin of
842 + %% Just a look-ahead, we want the end_tag separately
843 + <<_:O/binary, $<, $/, TT, II, TT2, LL, EE, ZZ, _/binary>>
844 + when (TT=:= $t orelse TT =:= $T) andalso
845 + (II=:= $i orelse II =:= $I) andalso
846 + (TT2=:= $t orelse TT2 =:= $T) andalso
847 + (LL=:= $l orelse LL =:= $L) andalso
848 + (EE=:= $e orelse EE =:= $E) andalso
849 + ?PROBABLE_CLOSE(ZZ) ->
850 + Len = O - Start,
851 + <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
852 + {{data, Raw, false}, S};
853 + <<_:O/binary, C, _/binary>> ->
854 + tokenize_title(Bin, ?INC_CHAR(S, C), Start);
855 + <<_:Start/binary, Raw/binary>> ->
856 + {{data, Raw, false}, S}
857 + end.
858 +
805 859 tokenize_textarea(Bin, S=#decoder{offset=O}) ->
806 860 tokenize_textarea(Bin, S, O).