Packages
floki
0.30.0
0.38.4
0.38.3
0.38.2
0.38.1
0.38.0
0.37.1
0.37.0
0.36.3
0.36.2
0.36.1
0.36.0
0.35.4
0.35.3
0.35.2
0.35.1
0.35.0
0.34.3
0.34.2
0.34.1
0.34.0
0.33.1
0.33.0
0.32.1
0.32.0
0.31.0
0.30.1
0.30.0
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.0
0.23.1
0.23.0
0.22.0
0.21.0
0.20.4
0.20.3
0.20.2
0.20.1
0.20.0
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.0
0.15.0
0.14.0
0.13.2
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.0
0.4.1
0.4.0
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.1
0.1.0
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Floki is a simple HTML parser that enables search for nodes using CSS selectors.
Current section
86 Versions
Jump to
Current section
86 Versions
Compare versions
13
files changed
+876
additions
-112
deletions
| @@ -0,0 +1,628 @@ | |
| 1 | + # Changelog |
| 2 | + |
| 3 | + All notable changes to this project will be documented in this file. |
| 4 | + |
| 5 | + The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) |
| 6 | + and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). |
| 7 | + |
| 8 | + ## [Unreleased][unreleased] |
| 9 | + |
| 10 | + ## [0.30.0] - 2021-02-06 |
| 11 | + |
| 12 | + ### Added |
| 13 | + |
| 14 | + - Add ":disabled" pseudo selector - thanks [@vnegrisolo](https://github.com/vnegrisolo) |
| 15 | + - Add [Gleam](https://github.com/gleam-lang/gleam) adapter - thanks [@CrowdHailer](https://github.com/CrowdHailer) |
| 16 | + - Add pretty option to `Floki.raw_html/2` - thanks [@evaldobratti](https://github.com/evaldobratti) |
| 17 | + - Add `html_parser` option to `parse_` functions. This enables a more dynamic and functional |
| 18 | + configuration of the HTML parser in use. |
| 19 | + |
| 20 | + ### Changed |
| 21 | + |
| 22 | + - Remove support for Elixir 1.7 - thanks [@carlosfrodrigues](https://github.com/carlosfrodrigues) |
| 23 | + - Replace `IO.warn` by `Logger.info` for deprecation warnings - thanks [@juulSme](https://github.com/juulSme) |
| 24 | + |
| 25 | + ### Fixed |
| 26 | + |
| 27 | + - Fix typespecs for `find`, `attr` and `attribute` functions - thanks [@mtarnovan](https://github.com/mtarnovan) |
| 28 | + - Documentation Improvements - thanks [@kianmeng](https://github.com/kianmeng) |
| 29 | + |
| 30 | + ## [0.29.0] - 2020-10-02 |
| 31 | + |
| 32 | + ### Added |
| 33 | + |
| 34 | + - Add `Floki.find_and_update/3` that updates nodes inside a tree, like traverse and update |
| 35 | + but without allowing changes in the children nodes. There for the tree cannot grow in size, |
| 36 | + but can have nodes removed. |
| 37 | + |
| 38 | + ### Changed |
| 39 | + |
| 40 | + - Deprecate `Floki.map/2` because we have now `Floki.find_and_update/3` and `Floki.traverse_and_update/2` that |
| 41 | + are powerful APIs. `Floki.map/2` can be replaced by `Enum.map/2` as well - thanks [@josevalim](https://github.com/josevalim) for the idea! |
| 42 | + - Update optional dependency `fast_html` to `v2.0.4` |
| 43 | + |
| 44 | + ### Fixed |
| 45 | + |
| 46 | + - Fix a bug when parsing a HTML with a XML inside using Mochiweb's parser |
| 47 | + |
| 48 | + ### Improvements |
| 49 | + |
| 50 | + - Add more typespecs |
| 51 | + |
| 52 | + ## [0.28.0] - 2020-08-26 |
| 53 | + |
| 54 | + ### Added |
| 55 | + |
| 56 | + - Add support for `:checked` pseudo-class selector - thanks [@wojtekmach](https://github.com/wojtekmach) |
| 57 | + |
| 58 | + ### Changed |
| 59 | + |
| 60 | + - Drop support for Elixir 1.6 |
| 61 | + - Update version of `fast_html` to 2.0 in docs and CI - thanks [@rinpatch](https://github.com/rinpatch) |
| 62 | + |
| 63 | + ### Fixed |
| 64 | + |
| 65 | + - Fix docs by mentioning HTML nodes supported for `traverse_and_update` - thanks [@hubertlepicki](https://github.com/hubertlepicki) |
| 66 | + |
| 67 | + ## [0.27.0] - 2020-07-07 |
| 68 | + |
| 69 | + ### Added |
| 70 | + |
| 71 | + - `Floki.filter_out/2` now can filter text nodes - thanks [@ckruse](https://github.com/ckruse) |
| 72 | + - Support more encoding entities in `Floki.raw_html/1` - thanks [@ntenczar](https://github.com/ntenczar) |
| 73 | + |
| 74 | + ### Fixed |
| 75 | + |
| 76 | + - Fix `Floki.attribute/2` when there is only text nodes in the document - thanks [@ckruse](https://github.com/ckruse) |
| 77 | + |
| 78 | + ### Improvements |
| 79 | + |
| 80 | + - Performance improvements of `Floki.raw_html/1` function - thanks [@josevalim](https://github.com/josevalim) |
| 81 | + - Improvements in the docs and specs of `Floki.traverse_and_update/2` and `Floki.children/1` - thanks [@josevalim](https://github.com/josevalim) |
| 82 | + - Improvements in the spec of `Floki.traverse_and_update/2` - thanks [@Dalgona](https://github.com/Dalgona) |
| 83 | + - Improve the CI setup to run the formatter correctly - thanks [@Cleidiano](https://github.com/Cleidiano) |
| 84 | + |
| 85 | + ## [0.26.0] - 2020-02-17 |
| 86 | + |
| 87 | + ### Added |
| 88 | + |
| 89 | + - Add support for the pseudo-class selectors `:nth-last-child` and `:nth-last-of-type` |
| 90 | + |
| 91 | + ### Fixed |
| 92 | + |
| 93 | + - Fix the typespecs of `Floki.traverse_and_update/3` - thanks [@RichMorin](https://github.com/RichMorin) |
| 94 | + |
| 95 | + ### Changed |
| 96 | + |
| 97 | + - Update optional dependency `fast_html` to `v1.0.3` |
| 98 | + |
| 99 | + ## [0.25.0] - 2020-01-26 |
| 100 | + |
| 101 | + ### Added |
| 102 | + |
| 103 | + - Add `Floki.parse_fragment!/1` and `Floki.parse_document!/1` that has the same functionality of |
| 104 | + the functions without the bang, but they return the document or fragment without the either tuple |
| 105 | + and will raise exception in case of errors - thanks [@schneiderderek](https://github.com/schneiderderek) |
| 106 | + - Add `Floki.traverse_and_update/3` which accepts an accumulator which is useful to keep |
| 107 | + the state while traversing the HTML tree - thanks [@Dalgona](https://github.com/Dalgona) |
| 108 | + |
| 109 | + ### Changed |
| 110 | + |
| 111 | + - Update the `html_entities` dependency from `v0.5.0` to `v0.5.1` |
| 112 | + |
| 113 | + ## [0.24.0] - 2020-01-01 |
| 114 | + |
| 115 | + ### Added |
| 116 | + |
| 117 | + - Add support for [`fast_html`](https://hexdocs.pm/fast_html), which is a "C Node" wrapping |
| 118 | + Lexborisov's [myhtml](https://github.com/lexborisov/myhtml) - thanks [@rinpatch](https://github.com/rinpatch) |
| 119 | + - Add setup to run our test suite against all parsers on CI - thanks [@rinpatch](https://github.com/rinpatch) |
| 120 | + - Add `Floki.parse_document/1` and `Floki.parse_fragment/1` in order to correct parse documents |
| 121 | + and fragments of documents - it also prevents the confusion and inconsistency of `parse/1`. |
| 122 | + - Configure `dialyxir` in order to run Dialyzer easily. |
| 123 | + |
| 124 | + ### Changed |
| 125 | + |
| 126 | + - Deprecate `Floki.parse/1` and all the functions that uses it underneath. This means that all |
| 127 | + the functions that accepted HTML as binary are deprecated as well. This includes `find/2`, `attr/4`, |
| 128 | + `filter_out/2`, `text/2` and `attribute/2`. The recommendation is to use those functions with an |
| 129 | + already parsed document or fragment. |
| 130 | + - Remove support for `Elixir 1.5`. |
| 131 | + |
| 132 | + ## [0.23.1] - 2019-12-01 |
| 133 | + |
| 134 | + ### Fixed |
| 135 | + |
| 136 | + - It fixes the Mochiweb parser when there is an invalid charref. |
| 137 | + |
| 138 | + ## [0.23.0] - 2019-09-11 |
| 139 | + |
| 140 | + ### Changed |
| 141 | + |
| 142 | + - Remove Mochiweb as a hex dependency. It brings the code from the original project |
| 143 | + to Floki's codebase - thanks [@josevalim](https://github.com/josevalim) |
| 144 | + |
| 145 | + ## [0.22.0] - 2019-08-21 |
| 146 | + |
| 147 | + ### Added |
| 148 | + |
| 149 | + - Add `Floki.traverse_and_update/2` that works in similar way to `Floki.map/2` but |
| 150 | + traverse the tree and update the children elements. The difference from "map" is that |
| 151 | + this function can create a tree with more or less nodes. - thanks [@ericlathrop](https://github.com/ericlathrop) |
| 152 | + |
| 153 | + ### Changed |
| 154 | + |
| 155 | + - Remove support for Elixir 1.4. |
| 156 | + |
| 157 | + ## [0.21.0] - 2019-04-17 |
| 158 | + |
| 159 | + ### Added |
| 160 | + |
| 161 | + - Add a possibility to filter `style` tags on `Floki.text/2` - thanks [@Vict0rynox](https://github.com/Vict0rynox) |
| 162 | + |
| 163 | + ### Fixed |
| 164 | + |
| 165 | + - Fix `Floki.text/2` to consider the previous filter of `js` when filtering `style` - thanks [@Vict0rynox](https://github.com/Vict0rynox) |
| 166 | + - Fix typespecs for `Floki.filter_out/2` - thanks [@myfreeweb](https://github.com/myfreeweb) |
| 167 | + |
| 168 | + ### Changed |
| 169 | + |
| 170 | + - Drop support for Elixir 1.3 and below - thanks [@herbstrith](https://github.com/herbstrith) |
| 171 | + |
| 172 | + ## [0.20.4] - 2018-09-24 |
| 173 | + |
| 174 | + ### Fixed |
| 175 | + |
| 176 | + - Fix `Floki.raw_html` to accept lists as attribute values - thanks [@katehedgpeth](https://github.com/katehedgpeth) |
| 177 | + |
| 178 | + ## [0.20.3] - 2018-06-22 |
| 179 | + |
| 180 | + ### Fixed |
| 181 | + |
| 182 | + - Fix style and script tags with comments - thanks [@francois2metz](https://github.com/francois2metz) |
| 183 | + |
| 184 | + ## [0.20.2] - 2018-05-09 |
| 185 | + |
| 186 | + ### Fixed |
| 187 | + |
| 188 | + - Fix `Floki.raw_html/1` to correct handle quotes and double quotes on attributes - thanks [@grych](https://github.com/grych) |
| 189 | + |
| 190 | + ## [0.20.1] - 2018-04-05 |
| 191 | + |
| 192 | + ### Fixed |
| 193 | + |
| 194 | + - Remove `Enumerable.slice/1` compile warning for `Floki.HTMLTree` - thanks [@thecodeboss](https://github.com/thecodeboss) |
| 195 | + - Fix `Floki.find/2` that was failing on HTML that consists entirely of a comment - thanks [@ShaneWilton](https://github.com/ShaneWilton) |
| 196 | + |
| 197 | + ## [0.20.0] - 2018-02-06 |
| 198 | + |
| 199 | + ### Added |
| 200 | + |
| 201 | + - Configurable raw_html/2 to allow optional encode of HTML entities - thanks [@davydog187](https://github.com/davydog187) |
| 202 | + |
| 203 | + ### Fixed |
| 204 | + |
| 205 | + - Fix serialization of the tree after updating attribute - thanks [@francois2metz](https://github.com/francois2metz) |
| 206 | + |
| 207 | + ## [0.19.3] - 2018-01-25 |
| 208 | + |
| 209 | + ### Fixed |
| 210 | + |
| 211 | + - Skip HTML entities encode for `Floki.raw_html/1` for `script` or `style` tags |
| 212 | + - Add `:html_entities` app to the list of OTP applications. It fixes production releases. |
| 213 | + |
| 214 | + ## [0.19.2] - 2017-12-22 |
| 215 | + |
| 216 | + ### Fixed |
| 217 | + |
| 218 | + - **(BREAKING CHANGE)** Re-encode HTML entities on `Floki.raw_html/1`. |
| 219 | + |
| 220 | + ## [0.19.1] - 2017-12-04 |
| 221 | + |
| 222 | + ### Fixed |
| 223 | + |
| 224 | + - Fixed doctype serialization for `Floki.raw_html/1` - thanks [@jhchen][https://github.com/jhchen] |
| 225 | + |
| 226 | + ## [0.19.0] - 2017-11-11 |
| 227 | + |
| 228 | + ### Added |
| 229 | + |
| 230 | + - Added support for `nth-of-type`, `first-of-type`, `last-of-type` and `last-child` pseudo-classes - thanks [@saleem1337](https://github.com/saleem1337). |
| 231 | + - Added support for `nth-child` pseudo-class functional notation - thanks [@nirev](https://github.com/nirev). |
| 232 | + - Added functional notation support for `nth-of-type` pseudo-class. |
| 233 | + - Added a [Contributing guide](https://github.com/philss/floki/blob/master/CONTRIBUTING.md). |
| 234 | + |
| 235 | + ### Fixed |
| 236 | + |
| 237 | + - Format all files according to the Elixir 1.6 formatter - thanks [@fcevado](https://github.com/fcevado). |
| 238 | + - Fix `Floki.raw_html` to support raw text - thanks [@craig-day](https://github.com/craig-day). |
| 239 | + |
| 240 | + ## [0.18.1] - 2017-10-13 |
| 241 | + |
| 242 | + ### Added |
| 243 | + |
| 244 | + - Added a [Code of Conduct](https://github.com/philss/floki/blob/master/CODE_OF_CONDUCT.md). |
| 245 | + |
| 246 | + ### Fixed |
| 247 | + |
| 248 | + - Fix XML tag when building HTML tree. |
| 249 | + - Return empty list when `Floki.filter_out/2` result is empty. |
| 250 | + |
| 251 | + ## [0.18.0] - 2017-08-05 |
| 252 | + |
| 253 | + ### Added |
| 254 | + |
| 255 | + - Added `Floki.attr/4` that receives a function enabling manipulation of attribute values - thanks [@erikdsi](https://github.com/erikdsi). |
| 256 | + - Implement the String.Chars protocol for Floki.Selector. |
| 257 | + - Implement the Enumerable protocol for Floki.HTMLTree. |
| 258 | + |
| 259 | + ### Changed |
| 260 | + |
| 261 | + - Changed `Floki.transform/2` to `Floki.map/2` and `Floki.Finder.apply_transform/2` to `Floki.Finder.map/2` - thanks [@aphillipo](https://github.com/aphillipo). |
| 262 | + |
| 263 | + ### Fixed |
| 264 | + |
| 265 | + - Fix `Floki.raw_html/1` to consider XML prefixes - thanks [@sergey-kintsel](https://github.com/sergey-kintsel). |
| 266 | + - Fix `raw_html` for self closing tags with content - thanks [@navinpeiris](https://github.com/navinpeiris). |
| 267 | + |
| 268 | + ### Removed |
| 269 | + |
| 270 | + - Removed support for Elixir 1.2. |
| 271 | + |
| 272 | + ## [0.17.2] - 2017-05-25 |
| 273 | + |
| 274 | + ### Fixed |
| 275 | + |
| 276 | + - Fix attribute selectors in :not() - thanks [@jjcarstens](https://github.com/jjcarstens) and [@Eiji7](https://github.com/Eiji7) |
| 277 | + - Fix selector parser to consider combinators across selectors separated by commas. |
| 278 | + For further details, please check the [pull request](https://github.com/philss/floki/pull/115) - thanks [@jjcarstens](https://github.com/jjcarstens) and [@mischov](https://github.com/mischov) |
| 279 | + |
| 280 | + ## [0.17.1] - 2017-05-22 |
| 281 | + |
| 282 | + ### Fixed |
| 283 | + |
| 284 | + - Fix search when body has unencoded angles (`<` and `>`) - thanks [@sergey-kintsel](https://github.com/sergey-kintsel) |
| 285 | + - Fix crash caused by XML declaration inside body - thanks [@erikdsi](https://github.com/erikdsi) |
| 286 | + - Fix issue when finding fails if HTML begins with XML tag - thanks [@sergey-kintsel](https://github.com/sergey-kintsel) |
| 287 | + |
| 288 | + ## [0.17.0] - 2017-04-12 |
| 289 | + |
| 290 | + ### Added |
| 291 | + |
| 292 | + - Add support for multiple pseudo-selectors, line :not() and :nth-child() - thanks [@jjcarstens](https://github.com/jjcarstens) |
| 293 | + - Add support for multiple selectors inside the :not() pseudo-class selector - thanks [@jjcarstens](https://github.com/jjcarstens) |
| 294 | + |
| 295 | + ## [0.16.0] - 2017-04-05 |
| 296 | + |
| 297 | + ### Added |
| 298 | + |
| 299 | + - Add support for selectors that only include a pseudo-class selector - thanks [@buhman](https://github.com/buhman) |
| 300 | + - Add support for a new selector: `fl-contains`, which returns elements that contains a given text - thanks [@buhman](https://github.com/buhman) |
| 301 | + |
| 302 | + ### Fixed |
| 303 | + |
| 304 | + - Fix `:not()` pseudo-class selector to accept simple pseudo-class selectors as well - thanks [@mischov](https://github.com/mischov) |
| 305 | + |
| 306 | + ## [0.15.0] - 2017-03-14 |
| 307 | + |
| 308 | + ### Added |
| 309 | + |
| 310 | + - Added support for the `:not()` pseudo-class selector. |
| 311 | + |
| 312 | + ### Fixed |
| 313 | + |
| 314 | + - Fixed pseudo-class selectors that are used in conjunction with combinators - thanks [@Eiji7](https://github.com/Eiji7) |
| 315 | + - Fixed order of elements after search using descendant combinator - thanks [@Eiji7](https://github.com/Eiji7) |
| 316 | + |
| 317 | + ## [0.14.0] - 2017-02-07 |
| 318 | + |
| 319 | + ### Added |
| 320 | + |
| 321 | + - Added support for configuring `html5ever` as the HTML parser. Issue #83 - thanks [@hansihe](https://github.com/hansihe) |
| 322 | + and [@aphillipo](https://github.com/aphillipo)! |
| 323 | + |
| 324 | + ## [0.13.2] - 2017-02-07 |
| 325 | + |
| 326 | + ### Fixed |
| 327 | + |
| 328 | + - Fixed bug that was causing Floki.text/1 and Floki.filter_out/2 |
| 329 | + to ignore "trees" with only text nodes. Issue #91 - thanks [@boydm](https://github.com/boydm). |
| 330 | + |
| 331 | + ## [0.13.1] - 2017-01-22 |
| 332 | + |
| 333 | + ### Fixed |
| 334 | + |
| 335 | + - Fix ordering of duplicated descendant matches - thanks [@mmmries](https://github.com/mmmries) |
| 336 | + - Fix ordering of `Floki.text/1` when there are only root nodes - thanks [@mmmries](https://github.com/mmmries) |
| 337 | + |
| 338 | + ## [0.13.0] - 2017-01-22 |
| 339 | + |
| 340 | + ### Added |
| 341 | + |
| 342 | + - Floki.filter_out/2 is now able to understand complex selectors to filter out from the tree. |
| 343 | + |
| 344 | + ## [0.12.1] - 2017-01-20 |
| 345 | + |
| 346 | + ### Fixed |
| 347 | + |
| 348 | + - Fix search for elements using descendant combinator - issue #84 - thanks [@mmmries](https://github.com/mmmries) |
| 349 | + |
| 350 | + ## [0.12.0] - 2016-12-28 |
| 351 | + |
| 352 | + ### Added |
| 353 | + |
| 354 | + - Add basic support for nth-child pseudo-class selector. |
| 355 | + Closes [issue #64](https://github.com/philss/floki/issues/64). |
| 356 | + |
| 357 | + ### Changed |
| 358 | + |
| 359 | + - Remove support for Elixir 1.1 and below. |
| 360 | + - Remove public documentation for internal code. |
| 361 | + |
| 362 | + ## [0.11.0] - 2016-10-12 |
| 363 | + |
| 364 | + ### Added |
| 365 | + |
| 366 | + - First attempt to transform nodes with `Floki.transform/2`. It is not able to update |
| 367 | + the tree yet, but works good with results from `Floki.find/2` - thanks [@bobjflong](https://github.com/bobjflong) |
| 368 | + |
| 369 | + ### Changed |
| 370 | + |
| 371 | + - Using Logger to notify unknown tokens in selector parser - thanks [@teamon](https://github.com/teamon) and [@geonnave](https://github.com/geonnave) |
| 372 | + - Replace `mochiweb_html` with `mochiweb` package. This is needed to fix conflict with other |
| 373 | + packages that are using `mochiweb`. - thanks [@aphillipo](https://github.com/aphillipo) |
| 374 | + |
| 375 | + ## [0.10.1] - 2016-08-28 |
| 376 | + |
| 377 | + ### Fixed |
| 378 | + |
| 379 | + - Fix sibling search after immediate children - thanks [@gmile](https://github.com/gmile). |
| 380 | + |
| 381 | + ## [0.10.0] - 2016-08-05 |
| 382 | + |
| 383 | + ### Changed |
| 384 | + |
| 385 | + - Change the search for namespaced elements using the correct CSS3 syntax. |
| 386 | + |
| 387 | + ### Fixed |
| 388 | + |
| 389 | + - Fix the search for child elements when is more than two elements deep - thanks [@gmile](https://github.com/gmile) |
| 390 | + |
| 391 | + ## [0.9.0] - 2016-06-16 |
| 392 | + |
| 393 | + ### Added |
| 394 | + |
| 395 | + - A separator between text when getting text from nodes - thanks [@rochdi](https://github.com/rochdi). |
| 396 | + |
| 397 | + ## [0.8.1] - 2016-05-20 |
| 398 | + |
| 399 | + ### Added |
| 400 | + |
| 401 | + - Support rendering boolean attributes on `Floki.raw_html/1` - thanks [@iamvery](https://github.com/iamvery). |
| 402 | + |
| 403 | + ### Changed |
| 404 | + |
| 405 | + - Update Mochiweb HTML parser dependency to version 2.15.0. |
| 406 | + |
| 407 | + ## [0.8.0] - 2016-03-06 |
| 408 | + |
| 409 | + ### Added |
| 410 | + |
| 411 | + - Add possibility to search tags with namespaces. |
| 412 | + - Accept `Floki.Selector` as parameter of `Floki.find/2` instead of only strings - thanks [@hansihe](https://github.com/hansihe). |
| 413 | + |
| 414 | + ### Changed |
| 415 | + |
| 416 | + - Using a smaller package with only the Mochiweb HTML parser. |
| 417 | + |
| 418 | + ## [0.7.2] - 2016-02-23 |
| 419 | + |
| 420 | + ### Fixed |
| 421 | + |
| 422 | + - Replace `<br>` nodes by newline (`\n`) in `DeepText` - thanks [@maxneuvians](https://github.com/maxneuvians). |
| 423 | + - Allow `FilterOut` to filter special nodes, like `comment`. |
| 424 | + |
| 425 | + ## [0.7.1] - 2015-11-14 |
| 426 | + |
| 427 | + ### Fixed |
| 428 | + |
| 429 | + - Ignore PHP scripts when finding nodes. |
| 430 | + |
| 431 | + ## [0.7.0] - 2015-11-03 |
| 432 | + |
| 433 | + ### Added |
| 434 | + |
| 435 | + - Add support for excluding script notes in `Floki.text`. |
| 436 | + By default, it will exclude those nodes, but it can be enabled with |
| 437 | + the flag `js: true` - thanks [@vikeri](https://github.com/vikeri)! |
| 438 | + |
| 439 | + ### Fixed |
| 440 | + |
| 441 | + - Fix find for sibling nodes when the precedent selector match an element |
| 442 | + at the end of sibling list - fix [issue #39](https://github.com/philss/floki/issues/39) |
| 443 | + |
| 444 | + ## [0.6.1] - 2015-10-11 |
| 445 | + |
| 446 | + ### Fixed |
| 447 | + |
| 448 | + - Fix the `Floki.raw_html/1` to build HTML comments properly. |
| 449 | + |
| 450 | + ## [0.6.0] - 2015-10-07 |
| 451 | + |
| 452 | + ### Added |
| 453 | + |
| 454 | + - Add `Floki.raw_html/2`. |
| 455 | + |
| 456 | + ## [0.5.0] - 2015-09-27 |
| 457 | + |
| 458 | + ### Added |
| 459 | + |
| 460 | + - Add the child combinator to `Floki.find/2`. |
| 461 | + - Add the adjacent sibling combinator to `Floki.find/2`. |
| 462 | + - Add the general adjacent sibling combinator to `Floki.find/2`. |
| 463 | + |
| 464 | + ## [0.4.1] - 2015-09-18 |
| 465 | + |
| 466 | + ### Fixed |
| 467 | + |
| 468 | + - Ignoring other files that are not lexer files (".xrl") under `src/` directory |
| 469 | + in Hex package. This fixes a crash when compiling using OTP 17.5 on Mac OS X. |
| 470 | + Huge thanks to [@henrik](https://github.com/henrik) and [@licyeus](https://github.com/licyeus) that pointed the |
| 471 | + [issue](https://github.com/philss/floki/issues/24)! |
| 472 | + |
| 473 | + ## [0.4.0] - 2015-09-17 |
| 474 | + |
| 475 | + ### Added |
| 476 | + |
| 477 | + - A robust representation of selectors in order to enable queries using a mix of selector types, |
| 478 | + such as classes with attributes, attributes with types, classes with classes and so on. |
| 479 | + Here is a list with examples of what is possible now: |
| 480 | + - `Floki.find(html, "a.foo")` |
| 481 | + - `Floki.find(html, "a.foo[data-action=post]")` |
| 482 | + - `Floki.find(html, ".foo.bar")` |
| 483 | + - `Floki.find(html, "a.foo[href$='.org']")` |
| 484 | + Thanks to [@licyeus](https://github.com/licyeus) to point out the [issue](https://github.com/philss/floki/issues/18)! |
| 485 | + - Include `mochiweb` in the applications list at mix.exs - thanks [@EricDykstra](https://github.com/EricDykstra) |
| 486 | + |
| 487 | + ### Changed |
| 488 | + |
| 489 | + - `Floki.find/2` will now return a list instead of tuple when searching only by IDs. |
| 490 | + For now on, Floki should always return the results inside a list, even if it's an ID match. |
| 491 | + |
| 492 | + ### Removed |
| 493 | + |
| 494 | + - `Floki.find/2` does not accept tuples as selectors anymore. |
| 495 | + This is because with the robust selectors representation, it won't be necessary to query directly using |
| 496 | + tuples or another data structures rather than string. |
| 497 | + |
| 498 | + ## [0.3.3] - 2015-08-23 |
| 499 | + |
| 500 | + ### Fixed |
| 501 | + |
| 502 | + - Fix `Floki.find/2` when there is a non-HTML input. |
| 503 | + It closes the [issue #17](https://github.com/philss/floki/issues/17) |
| 504 | + |
| 505 | + ## [0.3.2] - 2015-06-27 |
| 506 | + |
| 507 | + ### Fixed |
| 508 | + |
| 509 | + - Fix `Floki.DeepText` when there is a comment inside nodes. |
| 510 | + |
| 511 | + ## [0.3.1] - 2015-06-21 |
| 512 | + |
| 513 | + ### Fixed |
| 514 | + |
| 515 | + - Fix `Floki.find/2` to consider XML trees. |
| 516 | + |
| 517 | + ## [0.3.0] - 2015-06-07 |
| 518 | + |
| 519 | + ### Added |
| 520 | + |
| 521 | + - Add attribute equals selector. This feature enables the user to search using |
| 522 | + HTML attributes other than "class" or "id". |
| 523 | + E.g: `Floki.find(html, "[data-model=user]")` - [@nelsonr](https://github.com/nelsonr) |
| 524 | + |
| 525 | + ## [0.2.1] - 2015-06-04 |
| 526 | + |
| 527 | + ### Fixed |
| 528 | + |
| 529 | + - Fix `parse/1` when parsing a part of HTML without a root node - [@antonmi](https://github.com/antonmi) |
| 530 | + |
| 531 | + ## [0.2.0] - 2015-05-03 |
| 532 | + |
| 533 | + ### Added |
| 534 | + |
| 535 | + - Support HTML string when searching for attributes with `Floki.attribute/2`. |
| 536 | + - Option for `Floki.text/2` to disable deep search and use flat search instead. |
| 537 | + |
| 538 | + ### Changed |
| 539 | + |
| 540 | + - Change `Floki.text/1` to perform a deep search of text nodes. |
| 541 | + - Consider doctests in the test suite. |
| 542 | + |
| 543 | + ## [0.1.1] - 2015-03-25 |
| 544 | + |
| 545 | + ### Added |
| 546 | + |
| 547 | + - Add CHANGELOG.md following the [Keep a changelog](http://keepachangelog.com/). |
| 548 | + |
| 549 | + ### Changed |
| 550 | + |
| 551 | + - Using MochiWeb as a hex dependency instead of embedded code. |
| 552 | + It closes the [issue #5](https://github.com/philss/floki/issues/5) |
| 553 | + |
| 554 | + ## [0.1.0] - 2015-02-15 |
| 555 | + |
| 556 | + ### Added |
| 557 | + |
| 558 | + - Descendant selectors, like ".class tag" to Floki.find/2. |
| 559 | + - Multiple selection, like ".class1, .class2" to Floki.find/2. |
| 560 | + |
| 561 | + ## [0.0.5] - 2014-12-21 |
| 562 | + |
| 563 | + ### Added |
| 564 | + |
| 565 | + - `Floki.text/1`, which returns all text in the same level |
| 566 | + of the parent element inside HTML. |
| 567 | + |
| 568 | + ### Changed |
| 569 | + |
| 570 | + - Elixir version requirement from "~> 1.0.0" to ">= 1.0.0". |
| 571 | + |
| 572 | + [unreleased]: https://github.com/philss/floki/compare/v0.30.0...HEAD |
| 573 | + [0.30.0]: https://github.com/philss/floki/compare/v0.29.0...v0.30.0 |
| 574 | + [0.29.0]: https://github.com/philss/floki/compare/v0.28.0...v0.29.0 |
| 575 | + [0.28.0]: https://github.com/philss/floki/compare/v0.27.0...v0.28.0 |
| 576 | + [0.27.0]: https://github.com/philss/floki/compare/v0.26.0...v0.27.0 |
| 577 | + [0.26.0]: https://github.com/philss/floki/compare/v0.25.0...v0.26.0 |
| 578 | + [0.25.0]: https://github.com/philss/floki/compare/v0.24.0...v0.25.0 |
| 579 | + [0.24.0]: https://github.com/philss/floki/compare/v0.23.1...v0.24.0 |
| 580 | + [0.23.1]: https://github.com/philss/floki/compare/v0.23.0...v0.23.1 |
| 581 | + [0.23.0]: https://github.com/philss/floki/compare/v0.22.0...v0.23.0 |
| 582 | + [0.22.0]: https://github.com/philss/floki/compare/v0.21.0...v0.22.0 |
| 583 | + [0.21.0]: https://github.com/philss/floki/compare/v0.20.4...v0.21.0 |
| 584 | + [0.20.4]: https://github.com/philss/floki/compare/v0.20.3...v0.20.4 |
| 585 | + [0.20.3]: https://github.com/philss/floki/compare/v0.20.2...v0.20.3 |
| 586 | + [0.20.2]: https://github.com/philss/floki/compare/v0.20.1...v0.20.2 |
| 587 | + [0.20.1]: https://github.com/philss/floki/compare/v0.20.0...v0.20.1 |
| 588 | + [0.20.0]: https://github.com/philss/floki/compare/v0.19.3...v0.20.0 |
| 589 | + [0.19.3]: https://github.com/philss/floki/compare/v0.19.2...v0.19.3 |
| 590 | + [0.19.2]: https://github.com/philss/floki/compare/v0.19.1...v0.19.2 |
| 591 | + [0.19.1]: https://github.com/philss/floki/compare/v0.19.0...v0.19.1 |
| 592 | + [0.19.0]: https://github.com/philss/floki/compare/v0.18.1...v0.19.0 |
| 593 | + [0.18.1]: https://github.com/philss/floki/compare/v0.18.0...v0.18.1 |
| 594 | + [0.18.0]: https://github.com/philss/floki/compare/v0.17.2...v0.18.0 |
| 595 | + [0.17.2]: https://github.com/philss/floki/compare/v0.17.1...v0.17.2 |
| 596 | + [0.17.1]: https://github.com/philss/floki/compare/v0.17.0...v0.17.1 |
| 597 | + [0.17.0]: https://github.com/philss/floki/compare/v0.16.0...v0.17.0 |
| 598 | + [0.16.0]: https://github.com/philss/floki/compare/v0.15.0...v0.16.0 |
| 599 | + [0.15.0]: https://github.com/philss/floki/compare/v0.14.0...v0.15.0 |
| 600 | + [0.14.0]: https://github.com/philss/floki/compare/v0.13.2...v0.14.0 |
| 601 | + [0.13.2]: https://github.com/philss/floki/compare/v0.13.1...v0.13.2 |
| 602 | + [0.13.1]: https://github.com/philss/floki/compare/v0.13.0...v0.13.1 |
| 603 | + [0.13.0]: https://github.com/philss/floki/compare/v0.12.1...v0.13.0 |
| 604 | + [0.12.1]: https://github.com/philss/floki/compare/v0.12.0...v0.12.1 |
| 605 | + [0.12.0]: https://github.com/philss/floki/compare/v0.11.0...v0.12.0 |
| 606 | + [0.11.0]: https://github.com/philss/floki/compare/v0.10.1...v0.11.0 |
| 607 | + [0.10.1]: https://github.com/philss/floki/compare/v0.10.0...v0.10.1 |
| 608 | + [0.10.0]: https://github.com/philss/floki/compare/v0.9.0...v0.10.0 |
| 609 | + [0.9.0]: https://github.com/philss/floki/compare/v0.8.1...v0.9.0 |
| 610 | + [0.8.1]: https://github.com/philss/floki/compare/v0.8.0...v0.8.1 |
| 611 | + [0.8.0]: https://github.com/philss/floki/compare/v0.7.2...v0.8.0 |
| 612 | + [0.7.2]: https://github.com/philss/floki/compare/v0.7.1...v0.7.2 |
| 613 | + [0.7.1]: https://github.com/philss/floki/compare/v0.7.0...v0.7.1 |
| 614 | + [0.7.0]: https://github.com/philss/floki/compare/v0.6.1...v0.7.0 |
| 615 | + [0.6.1]: https://github.com/philss/floki/compare/v0.6.0...v0.6.1 |
| 616 | + [0.6.0]: https://github.com/philss/floki/compare/v0.5.0...v0.6.0 |
| 617 | + [0.5.0]: https://github.com/philss/floki/compare/v0.4.1...v0.5.0 |
| 618 | + [0.4.1]: https://github.com/philss/floki/compare/v0.4.0...v0.4.1 |
| 619 | + [0.4.0]: https://github.com/philss/floki/compare/v0.3.3...v0.4.0 |
| 620 | + [0.3.3]: https://github.com/philss/floki/compare/v0.3.2...v0.3.3 |
| 621 | + [0.3.2]: https://github.com/philss/floki/compare/v0.3.1...v0.3.2 |
| 622 | + [0.3.1]: https://github.com/philss/floki/compare/v0.3.0...v0.3.1 |
| 623 | + [0.3.0]: https://github.com/philss/floki/compare/v0.2.1...v0.3.0 |
| 624 | + [0.2.1]: https://github.com/philss/floki/compare/v0.2.0...v0.2.1 |
| 625 | + [0.2.0]: https://github.com/philss/floki/compare/v0.1.1...v0.2.0 |
| 626 | + [0.1.1]: https://github.com/philss/floki/compare/v0.1.0...v0.1.1 |
| 627 | + [0.1.0]: https://github.com/philss/floki/compare/v0.0.5...v0.1.0 |
| 628 | + [0.0.5]: https://github.com/philss/floki/compare/v0.0.3...v0.0.5 |
| @@ -1,6 +1,6 @@ | |
| 1 1 | ## Contributing |
| 2 2 | |
| 3 | - We want to encorage you to contribute to Floki with documentation, code and ideas. |
| 3 | + We want to encourage you to contribute to Floki with documentation, code and ideas. |
| 4 4 | To do so, you can read the existing docs and take a look at our source code through [closed pull requests](https://github.com/philss/floki/pulls?q=is%3Apr+is%3Aclosed). |
| 5 5 | |
| 6 6 | Before starting, please read our [Code of Conduct](https://github.com/philss/floki/blob/master/CODE_OF_CONDUCT.md) and our [License](https://github.com/philss/floki/blob/master/LICENSE) files. |
| @@ -21,20 +21,20 @@ This can make the project very rich, even if your proposal is not accepted. It w | |
| 21 21 | |
| 22 22 | ### Code |
| 23 23 | |
| 24 | - Contributing with code (and documentation) is easy if you already know how to work with pull requests on Github. |
| 24 | + Contributing with code (and documentation) is easy if you already know how to work with Pull Request (PR) on GitHub. |
| 25 25 | If you don't know yet, it's basically: |
| 26 26 | |
| 27 | - 1. Fork the project |
| 28 | - 2. Clone your fork using the project URL (git or https) |
| 27 | + 1. Fork the project. |
| 28 | + 2. Clone your fork using the project URL (git or https). |
| 29 29 | 3. Create a new branch to implement your functionality or code. This can be done with the command: |
| 30 30 | `git checkout -b your-branch-name-here` |
| 31 | - 4. Make your changes and add a new commit with a clear message saying **why** this change is being made |
| 32 | - 5. Push your code with the command: `git push -u origin your-branch-name-here` |
| 33 | - 6. Go to your fork page at Github |
| 34 | - 7. Open a new Pull request. |
| 31 | + 4. Make your changes and add a new commit with a clear message saying **why** this change is being made. |
| 32 | + 5. Push your code with the command: `git push -u origin your-branch-name-here`. |
| 33 | + 6. Go to your fork page at GitHub. |
| 34 | + 7. Open a new PR. |
| 35 35 | |
| 36 | - Today we only need a one :shipit: (it's the sign of approval) in order to merge a pull request. Unfortunally we can't garantee that all pull requests will be merged. |
| 37 | - But we can garantee that all PRs that are not accepted will have an explanation for that. |
| 36 | + Today we only need a one :shipit: (it's the sign of approval) in order to merge a PR. Unfortunately we can't guarantee that all PRs will be merged. |
| 37 | + But we can guarantee that all PRs that are not accepted will have an explanation for that. |
| 38 38 | |
| 39 39 | If you have questions, security issues or suggestions about the project and prefer to talk privately, please send me an email at: philip.sampaio+flokicontributing@gmail.com. |
| @@ -1,8 +1,10 @@ | |
| 1 1 | [](https://github.com/philss/floki/actions) |
| 2 2 | [](https://hex.pm/packages/floki) |
| 3 | - [](https://hex.pm/packages/floki) |
| 3 | + [](https://hexdocs.pm/floki/) |
| 4 4 | [](https://inch-ci.org/github/philss/floki) |
| 5 | - [](https://app.sourcelevel.io/github/philss/floki) |
| 5 | + [](https://hex.pm/packages/floki) |
| 6 | + [](https://github.com/philss/floki/blob/master/LICENSE) |
| 7 | + [](https://github.com/philss/floki/commits/master) |
| 6 8 | |
| 7 9 | <img src="assets/images/floki-logo-with-type.svg" width="500" alt="Floki logo"> |
| 8 10 | |
| @@ -60,23 +62,21 @@ Add Floki to your `mix.exs`: | |
| 60 62 | ```elixir |
| 61 63 | defp deps do |
| 62 64 | [ |
| 63 | - {:floki, "~> 0.29.0"} |
| 65 | + {:floki, "~> 0.30.0"} |
| 64 66 | ] |
| 65 67 | end |
| 66 68 | ``` |
| 67 69 | |
| 68 70 | After that, run `mix deps.get`. |
| 69 71 | |
| 70 | - You can check the [change log](https://github.com/philss/floki/blob/master/CHANGELOG.md) for changes. |
| 72 | + You can check the [changelog](CHANGELOG.md) for changes. |
| 71 73 | |
| 72 74 | ## Dependencies |
| 73 75 | |
| 74 | - Floki needs the `leex` module in order to compile. |
| 76 | + Floki needs the `:leex` module in order to compile. |
| 75 77 | Normally this module is installed with Erlang in a complete installation. |
| 76 78 | |
| 77 | - If you get this [kind of error](https://github.com/philss/floki/issues/35), |
| 78 | - you need to install the `erlang-dev` and `erlang-parsetools` packages in order get the `leex` module. |
| 79 | - The packages names may be different depending on your OS. |
| 79 | + If you get this ["module :leex is not available"](https://github.com/philss/floki/issues/35) error message, you need to install the `erlang-dev` and `erlang-parsetools` packages in order get the `:leex` module. The packages names may be different depending on your OS. |
| 80 80 | |
| 81 81 | ### Alternative HTML parsers |
| 82 82 | |
| @@ -104,6 +104,13 @@ Floki supports the following alternative parsers: | |
| 104 104 | [benchmarks](https://hexdocs.pm/fast_html/readme.html#benchmarks) conducted by |
| 105 105 | its developers. |
| 106 106 | |
| 107 | + You can perform a benchmark by running the following: |
| 108 | + |
| 109 | + $ sh benchs/extract.sh |
| 110 | + $ mix run benchs/parse_document.exs |
| 111 | + |
| 112 | + Extracting the files is needed only once. |
| 113 | + |
| 107 114 | #### Using `html5ever` as the HTML parser |
| 108 115 | |
| 109 116 | Rust needs to be installed on the system in order to compile html5ever. To do that, please |
| @@ -114,7 +121,7 @@ After Rust is set up, you need to add `html5ever` NIF to your dependency list: | |
| 114 121 | ```elixir |
| 115 122 | defp deps do |
| 116 123 | [ |
| 117 | - {:floki, "~> 0.29.0"}, |
| 124 | + {:floki, "~> 0.30.0"}, |
| 118 125 | {:html5ever, "~> 0.8.0"} |
| 119 126 | ] |
| 120 127 | end |
| @@ -142,7 +149,7 @@ First, add `fast_html` to your dependencies: | |
| 142 149 | ```elixir |
| 143 150 | defp deps do |
| 144 151 | [ |
| 145 | - {:floki, "~> 0.29.0"}, |
| 152 | + {:floki, "~> 0.30.0"}, |
| 146 153 | {:fast_html, "~> 2.0"} |
| 147 154 | ] |
| 148 155 | end |
| @@ -241,6 +248,7 @@ Here you find all the [CSS selectors](https://www.w3.org/TR/selectors/#selectors | |
| 241 248 | | E:first-of-type | an E element, first child of its type among its siblings | |
| 242 249 | | E:last-of-type | an E element, last child of its type among its siblings | |
| 243 250 | | E:checked | An E element (checkbox, radio, or option) that is checked | |
| 251 | + | E:disabled | An E element (button, input, select, textarea, or option) that is disabled | |
| 244 252 | | E.warning | an E element whose class is "warning" | |
| 245 253 | | E#myid | an E element with ID equal to "myid" | |
| 246 254 | | E:not(s) | an E element that does not match simple selector s | |
| @@ -261,4 +269,6 @@ There are also some selectors based on non-standard specifications. They are: | |
| 261 269 | |
| 262 270 | ## License |
| 263 271 | |
| 264 | - Floki is under MIT license. Check the `LICENSE` file for more details. |
| 272 | + Copyright (c) 2014 Philip Sampaio Silva |
| 273 | + |
| 274 | + Floki is under MIT license. Check the [LICENSE](https://github.com/philss/floki/blob/master/LICENSE) file for more details. |
| @@ -2,29 +2,31 @@ | |
| 2 2 | {<<"build_tools">>,[<<"mix">>]}. |
| 3 3 | {<<"description">>, |
| 4 4 | <<"Floki is a simple HTML parser that enables search for nodes using CSS selectors.">>}. |
| 5 | - {<<"elixir">>,<<"~> 1.7">>}. |
| 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 | - <<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,<<"CODE_OF_CONDUCT.md">>, |
| 25 | - <<"CONTRIBUTING.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 | - {<<"links">>,[{<<"GitHub">>,<<"https://github.com/philss/floki">>}]}. |
| 27 | + {<<"links">>, |
| 28 | + [{<<"Changelog">>,<<"https://hexdocs.pm/floki/changelog.html">>}, |
| 29 | + {<<"GitHub">>,<<"https://github.com/philss/floki">>}]}. |
| 28 30 | {<<"name">>,<<"floki">>}. |
| 29 31 | {<<"requirements">>, |
| 30 32 | [[{<<"app">>,<<"html_entities">>}, |
| @@ -32,4 +34,4 @@ | |
| 32 34 | {<<"optional">>,false}, |
| 33 35 | {<<"repository">>,<<"hexpm">>}, |
| 34 36 | {<<"requirement">>,<<"~> 0.5.0">>}]]}. |
| 35 | - {<<"version">>,<<"0.29.0">>}. |
| 37 | + {<<"version">>,<<"0.30.0">>}. |
| @@ -1,6 +1,8 @@ | |
| 1 1 | defmodule Floki do |
| 2 2 | alias Floki.{Finder, FilterOut, HTMLTree} |
| 3 3 | |
| 4 | + require Logger |
| 5 | + |
| 4 6 | @moduledoc """ |
| 5 7 | Floki is a simple HTML parser that enables search for nodes using CSS selectors. |
| 6 8 | |
| @@ -80,7 +82,7 @@ defmodule Floki do | |
| 80 82 | |
| 81 83 | @spec parse(binary()) :: html_tag() | html_tree() | String.t() |
| 82 84 | |
| 83 | - @deprecated "Please use parse_document/1 or parse_fragment/1" |
| 85 | + @deprecated "Use `parse_document/1` or `parse_fragment/1` instead." |
| 84 86 | def parse(html) do |
| 85 87 | with {:ok, document} <- Floki.HTMLParser.parse_document(html) do |
| 86 88 | if length(document) == 1 do |
| @@ -94,19 +96,23 @@ defmodule Floki do | |
| 94 96 | @doc """ |
| 95 97 | Parses a HTML Document from a string. |
| 96 98 | |
| 97 | - It will use the available parser. |
| 99 | + It will use the available parser from application env or the one from the |
| 100 | + `:html_parser` option. |
| 98 101 | Check https://github.com/philss/floki#alternative-html-parsers for more details. |
| 99 102 | |
| 100 | - ## Example |
| 103 | + ## Examples |
| 101 104 | |
| 102 105 | iex> Floki.parse_document("<html><head></head><body>hello</body></html>") |
| 103 106 | {:ok, [{"html", [], [{"head", [], []}, {"body", [], ["hello"]}]}]} |
| 104 107 | |
| 108 | + iex> Floki.parse_document("<html><head></head><body>hello</body></html>", html_parser: Floki.HTMLParser.Mochiweb) |
| 109 | + {:ok, [{"html", [], [{"head", [], []}, {"body", [], ["hello"]}]}]} |
| 110 | + |
| 105 111 | """ |
| 106 112 | |
| 107 | - @spec parse_document(binary()) :: {:ok, html_tree()} | {:error, String.t()} |
| 113 | + @spec parse_document(binary(), Keyword.t()) :: {:ok, html_tree()} | {:error, String.t()} |
| 108 114 | |
| 109 | - defdelegate parse_document(document), to: Floki.HTMLParser |
| 115 | + defdelegate parse_document(document, opts \\ []), to: Floki.HTMLParser |
| 110 116 | |
| 111 117 | @doc """ |
| 112 118 | Parses a HTML Document from a string. |
| @@ -121,10 +127,10 @@ defmodule Floki do | |
| 121 127 | |
| 122 128 | """ |
| 123 129 | |
| 124 | - @spec parse_document!(binary()) :: html_tree() |
| 130 | + @spec parse_document!(binary(), Keyword.t()) :: html_tree() |
| 125 131 | |
| 126 | - def parse_document!(document) do |
| 127 | - case parse_document(document) do |
| 132 | + def parse_document!(document, opts \\ []) do |
| 133 | + case parse_document(document, opts) do |
| 128 134 | {:ok, parsed_document} -> parsed_document |
| 129 135 | {:error, message} -> raise Floki.ParseError, message: message |
| 130 136 | end |
| @@ -133,13 +139,15 @@ defmodule Floki do | |
| 133 139 | @doc """ |
| 134 140 | Parses a HTML fragment from a string. |
| 135 141 | |
| 136 | - It will use the available parser. |
| 142 | + It will use the available parser from application env or the one from the |
| 143 | + `:html_parser` option. |
| 144 | + |
| 137 145 | Check https://github.com/philss/floki#alternative-html-parsers for more details. |
| 138 146 | """ |
| 139 147 | |
| 140 | - @spec parse_fragment(binary()) :: {:ok, html_tree()} | {:error, String.t()} |
| 148 | + @spec parse_fragment(binary(), Keyword.t()) :: {:ok, html_tree()} | {:error, String.t()} |
| 141 149 | |
| 142 | - defdelegate parse_fragment(fragment), to: Floki.HTMLParser |
| 150 | + defdelegate parse_fragment(fragment, opts \\ []), to: Floki.HTMLParser |
| 143 151 | |
| 144 152 | @doc """ |
| 145 153 | Parses a HTML fragment from a string. |
| @@ -148,10 +156,10 @@ defmodule Floki do | |
| 148 156 | error parsing the fragment. |
| 149 157 | """ |
| 150 158 | |
| 151 | - @spec parse_fragment!(binary()) :: html_tree() |
| 159 | + @spec parse_fragment!(binary(), Keyword.t()) :: html_tree() |
| 152 160 | |
| 153 | - def parse_fragment!(fragment) do |
| 154 | - case parse_fragment(fragment) do |
| 161 | + def parse_fragment!(fragment, opts \\ []) do |
| 162 | + case parse_fragment(fragment, opts) do |
| 155 163 | {:ok, parsed_fragment} -> parsed_fragment |
| 156 164 | {:error, message} -> raise Floki.ParseError, message: message |
| 157 165 | end |
| @@ -162,12 +170,17 @@ defmodule Floki do | |
| 162 170 | Note that the resultant HTML may be different from the original one. |
| 163 171 | Spaces after tags and doctypes are ignored. |
| 164 172 | |
| 165 | - Floki.raw_html/2 accepts a keyword list of options. Currently, the |
| 166 | - only supported option is `:encode`, which can be set to `true` or `false`. |
| 173 | + ## Options |
| 167 174 | |
| 175 | + - `:encode`: accepts `true` or `false`. Will encode html special characters |
| 176 | + to html entities. |
| 168 177 | You can also control the encoding behaviour at the application level via |
| 169 178 | `config :floki, :encode_raw_html, true | false` |
| 170 179 | |
| 180 | + - `:pretty`: accepts `true` or `false`. Will format the output, ignoring |
| 181 | + breaklines and spaces from the input and putting new ones in order to pretty format |
| 182 | + the html. |
| 183 | + |
| 171 184 | ## Examples |
| 172 185 | |
| 173 186 | iex> Floki.raw_html({"div", [{"class", "wrapper"}], ["my content"]}) |
| @@ -178,6 +191,15 @@ defmodule Floki do | |
| 178 191 | |
| 179 192 | iex> Floki.raw_html({"div", [{"class", "wrapper"}], ["10 > 5"]}, encode: false) |
| 180 193 | ~s(<div class="wrapper">10 > 5</div>) |
| 194 | + |
| 195 | + iex> Floki.raw_html({"div", [], ["\\n ", {"span", [], "Fully indented"}, " \\n"]}, pretty: true) |
| 196 | + \"\"\" |
| 197 | + <div> |
| 198 | + <span> |
| 199 | + Fully indented |
| 200 | + </span> |
| 201 | + </div> |
| 202 | + \"\"\" |
| 181 203 | """ |
| 182 204 | |
| 183 205 | @spec raw_html(html_tree | binary, keyword) :: binary |
| @@ -206,10 +228,10 @@ defmodule Floki do | |
| 206 228 | |
| 207 229 | """ |
| 208 230 | |
| 209 | - @spec find(binary() | html_tree(), css_selector()) :: html_tree |
| 231 | + @spec find(binary() | html_tree() | html_node(), css_selector()) :: html_tree |
| 210 232 | |
| 211 233 | def find(html, selector) when is_binary(html) do |
| 212 | - IO.warn( |
| 234 | + Logger.info( |
| 213 235 | "deprecation: parse the HTML with parse_document or parse_fragment before using find/2" |
| 214 236 | ) |
| 215 237 | |
| @@ -239,14 +261,15 @@ defmodule Floki do | |
| 239 261 | [{"div", [{"id", "b"}, {"class", "name"}], []}] |
| 240 262 | |
| 241 263 | """ |
| 242 | - @spec attr(binary | html_tree, css_selector(), binary, (binary -> binary)) :: html_tree |
| 264 | + @spec attr(binary | html_tree | html_node, css_selector(), binary, (binary -> binary)) :: |
| 265 | + html_tree |
| 243 266 | |
| 244 267 | def attr(html_elem_tuple, selector, attribute_name, mutation) when is_tuple(html_elem_tuple) do |
| 245 268 | attr([html_elem_tuple], selector, attribute_name, mutation) |
| 246 269 | end |
| 247 270 | |
| 248 271 | def attr(html, selector, attribute_name, mutation) when is_binary(html) do |
| 249 | - IO.warn( |
| 272 | + Logger.info( |
| 250 273 | "deprecation: parse the HTML with parse_document or parse_fragment before using attr/4" |
| 251 274 | ) |
| 252 275 | |
| @@ -291,7 +314,7 @@ defmodule Floki do | |
| 291 314 | def map(html_tree, fun), do: Finder.map(html_tree, fun) |
| 292 315 | |
| 293 316 | @doc """ |
| 294 | - Searchs for elements inside the HTML tree and update those that matches the selector. |
| 317 | + Searches for elements inside the HTML tree and update those that matches the selector. |
| 295 318 | |
| 296 319 | It will return the updated HTML tree. |
| 297 320 | |
| @@ -536,7 +559,7 @@ defmodule Floki do | |
| 536 559 | |
| 537 560 | """ |
| 538 561 | |
| 539 | - @spec attribute(binary | html_tree, binary, binary) :: list |
| 562 | + @spec attribute(binary | html_tree | html_node, binary, binary) :: list |
| 540 563 | |
| 541 564 | def attribute(html, selector, attribute_name) do |
| 542 565 | html |
| @@ -554,9 +577,9 @@ defmodule Floki do | |
| 554 577 | |
| 555 578 | """ |
| 556 579 | |
| 557 | - @spec attribute(binary | html_tree, binary) :: list |
| 580 | + @spec attribute(binary | html_tree | html_node, binary) :: list |
| 558 581 | def attribute(html, attribute_name) when is_binary(html) do |
| 559 | - IO.warn( |
| 582 | + Logger.info( |
| 560 583 | "deprecation: parse the HTML with parse_document or parse_fragment before using attribute/2" |
| 561 584 | ) |
| 562 585 | |
| @@ -606,7 +629,7 @@ defmodule Floki do | |
| 606 629 | end |
| 607 630 | |
| 608 631 | defp parse_it(html) when is_binary(html) do |
| 609 | - IO.warn( |
| 632 | + Logger.info( |
| 610 633 | "deprecation: parse the HTML with parse_document or parse_fragment before using text/2" |
| 611 634 | ) |
| 612 635 | |
| @@ -645,7 +668,7 @@ defmodule Floki do | |
| 645 668 | html_node() | html_tree() |
| 646 669 | |
| 647 670 | def filter_out(html, selector) when is_binary(html) do |
| 648 | - IO.warn( |
| 671 | + Logger.info( |
| 649 672 | "deprecation: parse the HTML with parse_document or parse_fragment before using filter_out/2" |
| 650 673 | ) |
Loading more files…