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.
Ref #105
A bit of context is in #105 (comment) but ultimately this parser should not be transforming HTML entities for the user - that's up to the compiler or the user agent.
While I personally believe this functionality should be stripped from this package entirely and downstream consumers should be the ones to make that decision, I figured that'd be less palatable than keeping things backwards compatible.
Therefore, this PR introduces the option
transformEntities
which is enabled by default that will handle HTML entities and transform them automatically - the current functionality. Passingfalse
disables this and leaves HTML entities untouched.This is imperative for proper parsing for many non-React frameworks.
A note about the implementation: to keep things performant, I (ab)use an explicit
case
fallthrough as a makeshiftgoto
, avoiding duplicated code or more string fetches, etc. The branch is inevitable, but thankfully only occurs if&
is detected (which is much less often than if it were to be put intodefault
to avoid the fallthrough, for example). This was the best balance between code readability and performance in my opinion.