fix(console): handle nested style
tags
#726
Merged
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.
This pull request is a follow-up of #703. It improves support for nested
<style>
tags and better handles ending tags (</style>
).Nesting <style>
The first change is the support for nested
<style>
tags. I changed the regular expression to use a negative lookahead ((?!\<style)
) that prevents matching nested<style>
tags. Without this, the following would be matched as one block:The replacement would then miss styles. Now, it properly matches two distinct blocks.
Handling resets
The second change is an update to how
</style>
resets the current style. Instead of using0m
to reset all styles, it will use more specific reset codes depending on the opening tag.For instance:
Previously, after the first
</style>
, all colors and modifiers would be reset, sojust-dim
would use the default text style.Now,
</style>
will reset the foreground color only, keeping the previousdim
modifier intact, sojust-dim
will still be dimmed.Note
This pull request depends on tempestphp/highlight#163 for the new reset cases on
TerminalStyle
.Once
tempest/highlight
is tagged a new version, I'll update this PR with the new version and refactor the part of the code where I used strings instead of the missingTerminalStyle
cases.