CSS class references being persisted in style attributes

Bug #167937 reported by Phidias
50
This bug affects 9 people
Affects Status Importance Assigned to Milestone
Inkscape
Invalid
Medium
Unassigned

Bug Description

When you make a CSS class reference in an element
Inkscape grabs the CSS class definition and sticks it
into the style attribute. The problem with this
approach is that if you make a change to the CSS
definition, Inkscape doesn't update the style
attribute, and you're now stuck with an out-of-date
look and feel. Here's how you reproduce this problem:

(1) Open the XML editor and add a class reference to
one of the nodes.
(2) Attempt to delete the style attribute. Inkscape
will instead replace the current style definition, with
the definition found in the CSS class reference.
(3) Update the CSS class definition. Notice that the
style attribute is not updated, and that you must
manually delete the style reference in order to see the
change reflected in the element.

Tags: css svg
Revision history for this message
Peter Lewerin (vermeil-deactivatedaccount) wrote :

AFAICT setting class has no effect at all.

http://wiki.inkscape.org/wiki/index.php/CSS_Support seems to indicate that a style element inside defs should have effect, but this doesn't seem to be the case.

Changed in inkscape:
importance: Undecided → Medium
status: New → Incomplete
hash (hash-g)
Changed in inkscape:
status: Incomplete → Confirmed
Revision history for this message
Will Pittenger (will-pittenger1) wrote :

I think we need to add a style editor. This would to some extent be a clone of the Fill & Stroke dialog by copying those tabs, but also adding text-type information. Custom attributes might also be useful for when Inkscape hasn't kept up with the standard or the user has added other namespaces.

Object Properties would then get a Class combo with an X button to clear the class tag.

Revision history for this message
sdaau (sd-imi) wrote :

Hi all,

Me too, +1 :)

I tried a small workaround with a Python extension for Inkscape (attached) - basically, it should iterate through all elements that have a "class" attribute, and then delete their "style" attribute - which then means, when you change the inline class, you should save and then "Revert" the file to force a refresh ( Inkscape does not seem to have a command that will refresh the file loaded in memory, without closing and reopening the file? )..

Of course, this is not much of a solution if you want to have a base class, and then add additional "overloads" in the style attribute, but for my case it helps :)

Since it was quite difficult to find basic stuff about extension (like proper syntax for iterating and such) I've left plenty of useless comments in .py file :)

PS: Since I have only option for a single attachment with this comment, I'm including the .inx file inline:

---------------
refreshcss.inx
---------------
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
 <_name>Refresh CSS</_name>
 <id>org.sdaau.refresh.css</id>
 <dependency type="executable" location="extensions">refreshcss.py</dependency>
 <dependency type="executable" location="extensions">inkex.py</dependency>
 <effect>
  <object-type>all</object-type>
  <effects-menu>
   <submenu _name="CSS"/>
  </effects-menu>
 </effect>
 <script>
  <command reldir="extensions" interpreter="python">refreshcss.py</command>
 </script>
</inkscape-extension>
---------------

su_v (suv-lp)
summary: - CSS definitions being persisted in style attributes
+ CSS class references being persisted in style attributes
Revision history for this message
Martin Owens (doctormo) wrote :

I'm investigating the issue, I found that css styles are merged in style.cpp using sp_style_merge_property which literally sets the style property. The parent style however is set by setting the computed variable only.

There may be a way to get css styles to set only the computed variable instead of the whole structure and this might protect the xml attribute from having css styles infect them with values.

Revision history for this message
Open-Elearning (open-elearning) wrote :

Thanks Sdaau (sd-imi), your extension is really useful. As the bug is not solved, maybe this extension could be integrate by default with the others extension, no ?

Revision history for this message
Evan Derickson (derickson-e) wrote :

I've created a bounty for this bug at https://freedomsponsors.org/issue/735/css-class-references-being-persisted-in-style-attributes. Please consider adding to it or taking this issue on.

Revision history for this message
Jonathan Hofinger (jhofinger) wrote :

This is nearly fixed in 1.1. There is a new dialog (Selectors & CSS, deactivated in 1.0) to manipulate styles, just as in a browser.

Some remnants of the bug remain on copy/paste: https://gitlab.com/inkscape/inkscape/-/issues/1153

In general, CSS handling has improved a lot.

Closed by: https://gitlab.com/jhofinger

Changed in inkscape:
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.