Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(console): handle nested style tags #726

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

innocenzi
Copy link
Member

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:

<style="dim">[<style="fg-cyan">cyan</style>]</style>

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 using 0m to reset all styles, it will use more specific reset codes depending on the opening tag.

For instance:

<style="dim"><style="fg-gray">dim-gray</style> just-dim</style>

Previously, after the first </style>, all colors and modifiers would be reset, so just-dim would use the default text style.

Now, </style> will reset the foreground color only, keeping the previous dim modifier intact, so just-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 missing TerminalStyle cases.

@innocenzi innocenzi marked this pull request as draft November 13, 2024 23:52
@brendt
Copy link
Member

brendt commented Nov 14, 2024

tempest/highlight is tagged :)

@innocenzi innocenzi marked this pull request as ready for review November 14, 2024 09:41
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11834579899

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 68 of 68 (100.0%) changed or added relevant lines in 3 files are covered.
  • 26 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.05%) to 82.65%

Files with Coverage Reduction New Missed Lines %
src/Tempest/Console/src/Highlight/DynamicTokenType.php 1 91.8%
src/Tempest/Reflection/src/ClassReflector.php 2 95.92%
src/Tempest/Generation/src/ClassManipulator.php 3 81.25%
src/Tempest/Http/src/IsRequest.php 8 84.91%
src/Tempest/Core/src/PublishesFiles.php 12 83.33%
Totals Coverage Status
Change from base Build 11828633715: 0.05%
Covered Lines: 7617
Relevant Lines: 9216

💛 - Coveralls

@innocenzi
Copy link
Member Author

Thanks—ready for review 👍

@brendt brendt merged commit 779973e into tempestphp:main Nov 14, 2024
57 checks passed
@brendt
Copy link
Member

brendt commented Nov 14, 2024

Merged!

@innocenzi innocenzi deleted the feat/console/nested-styles branch November 14, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants