Open dmbaturin opened 1 year ago
Ok, I completely missed the fact that you can set an implicit optional argument explicitly with ?context:settings.context
.
But I still believe there should be an explicit polymorphic variant for the default context.
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.