René's URL Explorer Experiment


Title: Bonsai: parse sheet CSS with a comment and string aware scanner by petruconduraru · Pull Request #8979 · IfcOpenShell/IfcOpenShell · GitHub

Open Graph Title: Bonsai: parse sheet CSS with a comment and string aware scanner by petruconduraru · Pull Request #8979 · IfcOpenShell/IfcOpenShell

X Title: Bonsai: parse sheet CSS with a comment and string aware scanner by petruconduraru · Pull Request #8979 · IfcOpenShell/IfcOpenShell

Description: Fixes #7312. @sl-x75 reported that generating a sheet with third party pattern CSS (his example: a hatch pattern library) produced broken output, and proposed a fix to ensure_drawing_unique_styles. @Moult's reply was the actual ask: We need something along these lines, but is there a safer way to do it than assumptions in parsing CSS this way? He is right to be suspicious. ensure_drawing_unique_styles scopes every CSS rule to its drawing by counting {/} characters one at a time over the raw CSS text. That breaks on: A brace inside a comment or a quoted string, e.g. content: "{". The counter desyncs and every rule after it silently loses its scoping prefix, so it leaks unscoped across the whole sheet. Concretely, before this PR: IN : '.foo::before { content: "{"; }\n.bar { fill: blue; }' OUT: '.foo::before.d42 { content: "{"; }\n.bar { fill: blue; }' Note .bar never gets .d42. An @media (...) prelude gets a bogus .prefix suffix appended to it: IN : '@media (min-width: 600px) { .foo { fill: red; } }' OUT: '@media (min-width: 600px).d42 { .foo { fill: red; } }' A comma inside a functional pseudo-class splits the selector in the wrong place: IN : ':is(.a, .b) { fill: red; }' OUT: ':is(.a.d42, .b).d42 { fill: red; }' This replaces the character-by-character brace counter with a small state machine (src/bonsai/bonsai/bim/module/drawing/css_scope.py) that treats /* ... */ comments and quoted strings as opaque so braces inside them do not desync anything, leaves at-rule preludes alone instead of corrupting them, and only splits selector lists on commas that are outside of ()/[]/quotes. After this change the three cases above become: '.foo::before.d42 { content: "{"; }.bar.d42 { fill: blue; }' '@media (min-width: 600px) { .foo { fill: red; } }' ':is(.a, .b).d42 { fill: red; }' (Nested rules inside an @media block are still not individually scoped, matching the previous behaviour; this is not a new regression.) For every currently working input I checked (multi-selector rules, multi-line rules, nth-of-type/attribute selectors, url() rewriting, and sl-x75's own sample CSS from the issue), the new output is byte for byte identical to the old output. On the dependency question: I looked at using tinycss2 (a real, small, pure-Python CSS parser, BSD-3-Clause, already a transitive dependency of cssselect2/CairoSVG elsewhere in the Python ecosystem but not currently something Bonsai bundles). It would fully close the remaining gap (scoping rules nested inside @media/@supports, full spec-correct tokenizing). I did not add it, since adding a dependency to Bonsai's bundled wheels (src/bonsai/Makefile) is a maintainer call. The comment/string/at-rule/paren-aware scanner above gets full correctness for the concrete cases reported and checked, without a new dependency, which seemed like the better default. @Moult, if you would rather depend on tinycss2 for full spec coverage (including the @media-nesting gap), say so and I will swap this out for it. The CSS-scoping logic is kept out of sheeter.py on purpose so it has no bpy/bonsai imports and can be exercised directly with plain python3 without a Blender environment, which is how I verified the before/after outputs above. Credit to @sl-x75 for identifying the real problem (styling from custom pattern SVGs colliding across a sheet) and proposing the first fix. Generated with the assistance of an AI coding tool. The whole diff (src/bonsai/bonsai/bim/module/drawing/css_scope.py and the corresponding change to sheeter.py) is AI-generated.

Open Graph Description: Fixes #7312. @sl-x75 reported that generating a sheet with third party pattern CSS (his example: a hatch pattern library) produced broken output, and proposed a fix to ensure_drawing_unique_styles....

X Description: Fixes #7312. @sl-x75 reported that generating a sheet with third party pattern CSS (his example: a hatch pattern library) produced broken output, and proposed a fix to ensure_drawing_unique_styles....

Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/pull/8979

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.3

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:031b19f6-868e-7998-75c6-98505a164eb3
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idEA50:C4ED3:26F95F:340BA2:6B04B635
html-safe-nonce18b1bc14948e107d2b69ea93fb8cacecfd2bb78b7647aa3ab77b39611493edd9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQTUwOkM0RUQzOjI2Rjk1RjozNDBCQTI6NkIwNEI2MzUiLCJ2aXNpdG9yX2lkIjoiNzc1Njk4MzIwMDY0MzMzMTYzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacfb2ba1d3d0f9be3f77efcb22ca2c726f8ca8f852bdbbaa9c329ec575e6d6330c
hovercard-subject-tagpull_request:4132369384
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
twitter:imagehttps://avatars.githubusercontent.com/u/139251053?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/139251053?s=400&v=4
og:image:altFixes #7312. @sl-x75 reported that generating a sheet with third party pattern CSS (his example: a hatch pattern library) produced broken output, and proposed a fix to ensure_drawing_unique_styles....
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None378bd702ac792b3550e484ad39d9a898fcd25bb52ba6962b0c9cc457c1ea71c7
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git
octolytics-dimension-user_id13692563
octolytics-dimension-user_loginIfcOpenShell
octolytics-dimension-repository_id40473201
octolytics-dimension-repository_nwoIfcOpenShell/IfcOpenShell
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id40473201
octolytics-dimension-repository_network_root_nwoIfcOpenShell/IfcOpenShell
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb032e77f1ea437ede6c115446a0a467709b468e7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FIfcOpenShell%2FIfcOpenShell%2Fpull%2F8979%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FIfcOpenShell%2FIfcOpenShell%2Fpull%2F8979%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=IfcOpenShell%2FIfcOpenShell
Reloadhttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
Reloadhttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
Reloadhttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
IfcOpenShellhttps://github.com/IfcOpenShell
IfcOpenShellhttps://github.com/IfcOpenShell/IfcOpenShell
Codehttps://github.com/IfcOpenShell/IfcOpenShell
Issues1.2k (1.2k)https://github.com/IfcOpenShell/IfcOpenShell/issues
Pull requests940 (940)https://github.com/IfcOpenShell/IfcOpenShell/pulls
Discussionshttps://github.com/IfcOpenShell/IfcOpenShell/discussions
Actionshttps://github.com/IfcOpenShell/IfcOpenShell/actions
Projectshttps://github.com/IfcOpenShell/IfcOpenShell/projects
Wikihttps://github.com/IfcOpenShell/IfcOpenShell/wiki
Security and qualityhttps://github.com/IfcOpenShell/IfcOpenShell/security
Insightshttps://github.com/IfcOpenShell/IfcOpenShell/insights
Sign up for GitHub https://github.com/signup?return_to=%2FIfcOpenShell%2FIfcOpenShell%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FIfcOpenShell%2FIfcOpenShell%2Fissues%2Fnew%2Fchoose
petruconduraruhttps://github.com/petruconduraru
IfcOpenShell:v0.8.0https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.8.0
BIMvoice:7312-safer-css-scopinghttps://github.com/BIMvoice/IfcOpenShell/tree/7312-safer-css-scoping
Conversation 2 https://github.com/IfcOpenShell/IfcOpenShell/pull/8979
Commits 1 https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/commits
Checks 3 https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/checks
Files changed https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
Please reload this pagehttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
Bonsai: parse sheet CSS with a comment and string aware scanner https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#top
Show all changes 1 commit https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
45569b0 Bonsai: parse sheet CSS with a comment and string aware scanner, not … petruconduraru Jul 25, 2026 https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/commits/45569b003898ec44456dc8242d398f2254a29964
Clear filters https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
Please reload this pagehttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
Please reload this pagehttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files
css_scope.py https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-0ec826b89020fc00b7b9ef40642bd183767a827ccd898c6af337fd4eedda8d0c
sheeter.py https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
src/bonsai/bonsai/bim/module/drawing/css_scope.pyhttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-0ec826b89020fc00b7b9ef40642bd183767a827ccd898c6af337fd4eedda8d0c
View file https://github.com/BIMvoice/IfcOpenShell/blob/45569b003898ec44456dc8242d398f2254a29964/src/bonsai/bonsai/bim/module/drawing/css_scope.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/{{ revealButtonHref }}
src/bonsai/bonsai/bim/module/drawing/sheeter.pyhttps://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
View file https://github.com/BIMvoice/IfcOpenShell/blob/45569b003898ec44456dc8242d398f2254a29964/src/bonsai/bonsai/bim/module/drawing/sheeter.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/{{ revealButtonHref }}
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
https://github.com/IfcOpenShell/IfcOpenShell/pull/8979/files#diff-d27dfc3dcc1fa0962d879f832023b473d688d86237df4ed6ed9365c1aca0540e
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.