philss / floki

Floki is a simple HTML parser that enables search for nodes using CSS selectors.
https://hex.pm/packages/floki
MIT License
2.05k stars 155 forks source link

Add unsafe versions of `Floki.parse_document` and `Floki.parse_fragment` to ease the migration #247

Closed rinpatch closed 4 years ago

rinpatch commented 4 years ago

Feature goal

Floki 0.2.4 deprecated Floki.parse and functions that accepted html as binary. However it's not easy to migrate the code to new parse functions since they return an {:ok | :error, result} tuple, which becomes a problem when you have used these functions in the middle of pipelines with a big number of steps. It also feels kinda useless with mochiweb_html, which is probably what most people use, since it can't return an error when parsing the document.

Hence, I think it would make sense to add unsafe versions of Floki.parse_document and Floki.parse_fragment, which raise an exception on parse failure.

Dependencies

I would use Unsafe, though it can be done manually just fine as well.

philss commented 4 years ago

@rinpatch thank you for the suggestion. We had a contribution from @schneiderderek which added the two functions parse_document! and parse_fragment! which has the same behaviour you mentioned. It is available in version 0.25.0.