I have a use case where I provede html example code with somme specific css code which is bounded to each example only.
I can’t use <style> within a tiddler as it is not where it may appear. I dn’t want to use the style attribute because my code rely on css class. So the only way is to write a custom stylesheet in its own tiddler and to tag it accordingly.
But this makes the stylesheet available to every tiddler, which is a recipe for future problems and headache. To mitigate this, I have to complexify the whole things, like putting al my code fragements in a weird-named <div> and prefix all my css rules accordingly (like div#weirdName span.active { stuff... } which is polluting my solutions.
Would it not be fine to have a <$stylesheet> widget instead, to be used like that
<$stylesheet stylesheet="customStyle42">
(all my nice coding here)
</stylesheet>
where “customStyle42” would be a tiddler off css stylesheet type but NOT tagged as such. It would not apply everywhere but only within <$stylesheet> widget . This is the same idea than the <$include>` widget
for macro defined in tiddler not tagged as macros.
Keep in mind that if you do <style> inside a tiddler it still applies to all other tiddlers while this one tiddler is currently displayed.
I think the only way to satisfy this requirement would be for the <$stylesheet> widget to read the CSS from that stylesheet, dynamically modify it to add a randomly-generated ID to every selector and then wrap the contents in a div containing the same ID. It’s definitely doable and now you are making me want to write a JS widget to do just that :D. If only I had the time, though.
The ability to overcome the complexity of tiddlywiki being a single page wiki whilst treating individual tiddlers with a custom CSS treatment without resorting to specific selectors, is I believe a long standing issue. It is truthfully somewhat “against the grain” of CSS yet it would be wonderful if we could do it.
There are ways to do it but the stylesheet or the use of the resulting CSS is no longer “un-adulterated” but perhaps someone with better CSS knowledge can find a way, or at least to minimise it.
Perhaps there is a way using the body cascade to only apply the CSS to a specific tiddler? Somehow apply only to the body with a particular field/field value or tag?
This would do the trick. The problem would be: when would that temporary tiddler be suppressed? It would be best that it is deleted when sample009 is closed or deleted. If sample 009 is renamed, it would also be mandatory that it be updated.
This snippet will automatically prefix your css rules (here, in the field “css”) with a prefix (here, in the field “prefix”), allowing to scope your css rules to something specific.
I think the iframe approach has great possibilities because we can use a custom body to do this and transclude the custom stylesheet (between the style tags) knowing it will only effect the contents of the iframe, or the current tiddler.
I will test ASAP
I already have a “local view template” solution (in another field of the tiddler) that only applies to the current tiddler, I plan to make a local-stylesheet, and local-macros field as well.
All to assist in development or solutions within a single tiddler scope.
[Edited]
I am not sure how to get the text inside the iframe wikified. Will experiment
Having a iddler candidate for special stylesheet named $:/user/database/test/blobs/461/testsol/example with its stylesheet named $:/user/database/test/blobs/461/testsol/example.css, I have something like that in that css tiddler, typed as ‘‘tw5’’ instead of text/css but of course tagged as $:/tags/Stylesheet