Skip to content

Allow @font-face rules nested inside @media rules#68

Merged
jaraco merged 3 commits intojaraco:mainfrom
bysiber:fix-fontface-in-media-rule
Apr 14, 2026
Merged

Allow @font-face rules nested inside @media rules#68
jaraco merged 3 commits intojaraco:mainfrom
bysiber:fix-fontface-in-media-rule

Conversation

@bysiber
Copy link
Copy Markdown
Contributor

@bysiber bysiber commented Feb 21, 2026

As reported in #30, @font-face rules nested inside @media blocks are incorrectly rejected with:

CSSMediaRule: This rule is not allowed in CSSMediaRule

Per MDN's At-Rules documentation, @font-face is valid inside conditional at-rules like @media. This is also common in real-world CSS, e.g. Google Fonts serves @font-face wrapped in @media screen.

The issue was in two places in cssmediarule.py:

  1. The CSS text parser's atrule handler had @font-face in the disallowed list instead of the factories dict. Moved it to factories so it gets parsed as a CSSFontFaceRule.

  2. insertRule() was rejecting CSSFontFaceRule instances. Removed that check so font-face rules can be inserted programmatically too.

Added a test covering both the parsing path and the insertRule() path. All existing tests continue to pass.

bysiber and others added 2 commits April 14, 2026 05:11
Per MDN's At-Rules Nesting documentation, @font-face is allowed
inside conditional at-rules like @media. However, cssutils was
rejecting them with "This rule is not allowed in CSSMediaRule".

This moves @font-face from the disallowed rules list to the
factories dict in the CSS text parser, and removes CSSFontFaceRule
from the rejected types in insertRule().

Fixes jaraco#30
@jaraco jaraco force-pushed the fix-fontface-in-media-rule branch from 28bd921 to af67c92 Compare April 14, 2026 09:12
@jaraco
Copy link
Copy Markdown
Owner

jaraco commented Apr 14, 2026

I force pushed the amended commit after removing the .pyc and commit_msg.txt files.

@jaraco jaraco merged commit 9b02fe7 into jaraco:main Apr 14, 2026
13 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.

2 participants