publicly expose tokenizer callbacks#64
Merged
MohamedRejeb merged 1 commit intoMohamedRejeb:mainfrom Jun 8, 2025
Merged
Conversation
… forwarded to public consumer specified callback
MohamedRejeb
approved these changes
Jun 8, 2025
Owner
MohamedRejeb
left a comment
There was a problem hiding this comment.
LGTM, Thanks for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Use Case
Been using Ksoup for a while as an alternative to fromHtml on KMP iOS, but I now came across a need to for certain unsupported tags output their entire raw unformatted representation (rather than just emitting their content).
In this case it is importent they are represented exactly "as is", so I can't just recreate them based on e.g. the attributes parameter.
Unfortunately for me to be able to handle this case with Ksoup I need to expose some internal state, hence this fork/PR.
There could be many ways Ksoup could allow for this (and similar) use-cases, e.g.:
KsoupHtmlHandlercallbacks to include either the "raw" representation of a tag, or correspondingstartIndexandendIndex. Though I suspect this would be seen as out of scope for this library.KsoupHtmlParserand callback methodsopenrather thanfinal(perhaps with some internal state asprotectedto allow subclassers to change the behavior.KsoupHtmlParserwhich gets called (in addition to its own internal one).Changes made:
KsoupTokenizerCallbacks) and makes them publicKsoupHtmlParserin addition to existingKsoupHtmlHandlerKsoupHtmlParserto inner (anonymous) object as I don't see why they should be publicly exposed? (could invite calling methods that could mess up internal state?)