You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type of Markup.parse_html is ?report:(location -> Error.t -> unit) -> ?encoding:Encoding.t -> ?context:[< `Document | `Fragment of string ] -> (char, 's) stream -> 's parser. That is quite handy in that you can call it without context and encoding arguments.
If you are writing a utility of a library that calls Markup.parse_html, that can become a source of annoynance. With encoding it's easy: the default is Markup.Encoding.utf_8, so you can easily do something like:
The option wrap-unwrap cycle is rather inelegant but at least there's no code duplication needed.
However, with the context argument, there is no way to achieve the same effect in one function call! The value that parse_html takes can be either `Document or `Fragment "tag" — two-state. There is no polymorphic variant constructor that would mean "guess the context", like Html_parser.parse None ... does.
So, the only way to pass the context from an external source is to use two different calls, one for "context not given, guess", the other for explicit context.
match settings.context with
| None -> ... |> Markup.parse_html ~encoding:settings.encoding |> ...
| Some c -> ... |> Markup.parse_html ~context:c ~encoding:settings.encoding |> ...
I'm not sure what's the best way out. I see three options:
Change the type of Markup.parse_html to ~context:(< Document | Fragment of string> option) — that would be a breaking change.
Add a new polymorphic variant constructor like `Any — non-breaking but makes the internal logic quite inelegant.
Add a new function with a different name — compatible but sacrifices the API elegance.
The text was updated successfully, but these errors were encountered:
The type of
Markup.parse_html
is?report:(location -> Error.t -> unit) -> ?encoding:Encoding.t -> ?context:[< `Document | `Fragment of string ] -> (char, 's) stream -> 's parser
. That is quite handy in that you can call it without context and encoding arguments.If you are writing a utility of a library that calls
Markup.parse_html
, that can become a source of annoynance. With encoding it's easy: the default isMarkup.Encoding.utf_8
, so you can easily do something like:The option wrap-unwrap cycle is rather inelegant but at least there's no code duplication needed.
However, with the
context
argument, there is no way to achieve the same effect in one function call! The value thatparse_html
takes can be either`Document
or`Fragment "tag"
— two-state. There is no polymorphic variant constructor that would mean "guess the context", likeHtml_parser.parse None ...
does.So, the only way to pass the context from an external source is to use two different calls, one for "context not given, guess", the other for explicit context.
I'm not sure what's the best way out. I see three options:
Markup.parse_html
to~context:(<
Document |Fragment of string> option)
— that would be a breaking change.`Any
— non-breaking but makes the internal logic quite inelegant.The text was updated successfully, but these errors were encountered: