Open danny0838 opened 3 months ago
Thank you very much for the detailed report!
It looks like the proper way to fix this issue would be to always use a separate <style>
element for each @import
instead of inlining their content. I'll have to think about it... Out of curiosity, how do you handle this problem in webscrapbook?
WebScrapBook normally saves each @import
as a separate file, and thus doesn't natively has the issue.
When saving as single HTML, WebScrapBook recursively converts the <link>
and @import
content into a data URL (need some special care about circular importing). This is ugly and not volume efficient but such stupid fidelity can prevent many potential issues introduced by converting a <link>
or @import
into <style>
, for example:
@import
contains a media
, layer
, or support
query.@import
appears after another CSS rule (which makes it invalid by spec and ignored by most modern browsers).<link>
is an alternative stylesheet and may have been switched by the browser (e.g. Firefox supports switching alternative stylesheet).P.S.: As a developer I really hate all the CSS related things...
Sorry, I had forgotten that webscrapbook saves resources separately. In fact, I do more or less the same thing (I guess) in SingleFile when saving the page in self-extracting format. The only major difference is that I use Blob URIs.
I'm still studying on this problem and I can confirm that it's probably going to take me a while to fix it because of the refactoring. Anyway, I think it should be doable. For now, I'm just resting my brain to get back to it later.
I completely agree with you about CSS. For example, I'm not a fan of the fact that the URL passed to the FontFace
constructor is inaccessible via the DOM. More recently, I've (re-)discovered CSS Worklets (see also the paint
function). It seems that some sites are starting to use them (see https://github.com/gildas-lormeau/SingleFile/issues/1502). I'd also like to avoid having to use a third-party library to parse the CSS. And let's not even talk about constructed (and adopted) stylesheets... It was tense enough with the Shadow DOM, I hope Houdini APIs won't make our extensions obsolete.
It is unfortunate that there is no available standard-compliant CSS parser, making many things difficult to handle. Although browsers support CSSOM, it's not enough to retrieve details of a apecific cssText in a rule, such as referenced CSS variables.
The closest one so far is parse-css. Unfortunately it's still buggy and needs improvement, and the maitainer still haven't review my patch PRs.
Describe the bug Namespaced elements of XHTML and CSS are not correctly handled.
To Reproduce Steps to reproduce the behavior:
element.xhtml
element-import.css
Expected behavior
elem-6
is not correctly namespaced (should be underhttp://www.w3.org/1999/xhtml
instead ofhttp://example.com/myns
).Environment