Skip to content

fix: keep pseudo-element rules that can't be inlined - #665

Merged
cossssmin merged 1 commit into
masterfrom
fix/preserve-pseudo-elements
Sep 24, 2026
Merged

cossssmin merged 1 commit into
masterfrom
fix/preserve-pseudo-elements

Conversation

@cossssmin

Copy link
Copy Markdown
Collaborator

Closes #293

With the default removeStyleTags: true, rules using ::first-letter, ::first-line, ::marker, ::selection or ::placeholder were silently dropped: they can't be inlined, but they weren't kept in the <style> tag either. So a drop cap like this one disappeared completely, even in email clients that support ::first-letter:

<style>h3::first-letter { color: red; font-size: 32px; }</style>
<h3>abc</h3>

These now go in the default ignoredPseudos, next to hover, active and friends, which is exactly what that list is for: skip inlining, keep the rule in a <style> tag (controlled by preservePseudos). Both :: and the legacy : syntax work.

Output for the example above:

<style>
h3::first-letter {
  color: red;
  font-size: 32px;
}
</style><h3>abc</h3>

Note that this keeps ::first-letter rules in the <style> tag rather than inlining them as <span>s like inlinePseudoElements does for ::before / ::after. Wrapping the first letter correctly (leading punctuation, emoji, nested elements, interplay with ::before) is a lot more involved, and ::first-line can't be done statically at all.

Added tests for each pseudo-element, both syntaxes, preservePseudos: false, and regular rules still being inlined alongside. Also updated the ignoredPseudos default in the README.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cossssmin
cossssmin merged commit 43a143a into master Sep 24, 2026
3 checks passed
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.

It seems the :first-letter don't work

1 participant