Skip to content

Read clip-path from style and CSS rules, and quoted url() references - #544

Merged
deeplook merged 2 commits into
deeplook:mainfrom
RavSinghChandan:clip-path-style
Nov 9, 2026
Merged

deeplook merged 2 commits into
deeplook:mainfrom
RavSinghChandan:clip-path-style

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

get_clippath() only reads the clip-path attribute, and only in the exact form url(#id). So the clip is silently dropped when it comes from:

  • a style attribute: style="clip-path: url(#clip)",
  • a CSS rule: .cls-2 { clip-path: url(#clip-path); }, as in Illustrator's CSS exports and in svgo-optimized matplotlib charts,
  • a quoted or spaced reference: url("#clip"), url('#clip'), url( #clip ), which is how browsers serialize the property.

Gradient fills already accept all of these (_GRADIENT_URL_RE). get_clippath() now applies the style rules to the node first, as the baseline-shift lookup does (clip-path is not inherited, so only the node itself is read), and parses the value with _GRADIENT_URL_RE. clip-path="none" still clips nothing.

Real files: PyMuPDF's docs/images/icons/icon-svg.svg (Illustrator) gets its 1 clip path, and the matplotlib charts in rapidfuzz's documentation (docs/Usage/img/*.svg) get their 18 each; on main they get none, so the plot lines are not clipped to the axes.

Added test_clipping_path_reference (attribute, both quotes, spaces, style, CSS class) and test_clipping_path_none; 5 of the 8 cases fail on main. Added a ### Fixed entry in CHANGELOG.md (I used #545, as I expect #544 for the <image> PR; I'll fix it if needed). pytest (without the network-dependent sample downloads), ruff format --check, ruff check and mypy src tests pass.

AI-assisted (Claude Code); I reviewed and tested the change

@deeplook
deeplook merged commit a348ea6 into deeplook:main Nov 9, 2026
16 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