Skip to content

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

Open
bysiber wants to merge 1 commit intojaraco:mainfrom
bysiber:fix-fontface-in-media-rule
Open

Allow @font-face rules nested inside @media rules#68
bysiber wants to merge 1 commit intojaraco:mainfrom
bysiber:fix-fontface-in-media-rule

Conversation

@bysiber
Copy link

@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.

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
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.

1 participant