Skip to content

Conversation

chowette
Copy link
Contributor

According to the svg.xsd, the content attribute is only allowed to be "structured text" or None

svg.py/svg.xsd

Line 3209 in 9e3bece

<xs:attribute name="content" type="xs:string" fixed="structured text"/>

The MDN is not documenting this attribute. And the SVG spec did not mention it ( I checked svg 1.1 2nd, svg tiny )

According to the svg.xsd, the content attribute is only allowed to be "structured text" or None

The MDN is not documenting this attribute. And the SVG spec did not mention it ( I checked svg 1.1 2nd, svg tiny )
Change "content" attribute of ForeignObject from str to Literal
@orsinium
Copy link
Member

If it's not in the spec, would it make sense to remove it? Have you tried using it, does it do anything?

@chowette
Copy link
Contributor Author

I only tried to use it incorrectly: by putting some html tags in it to see if it works, but obviously it did nothing....

My guess is this content ="structured text" stuff is a leftover from a xsd saying the content ( eg inner text ) should be some xml text, but it does not make sens considering the mixed="true" in the tag:

    <xs:complexType name="foreignObjectType" mixed="true">

So i vote for removing the attribute.


For the record, the proper way to use the <foreignobject> is to put some string in the text

<svg width="200" height="200">
   <foreignobject x="20" y="20" width="160" height="160" transform="rotate (20, 80, 80)">
      <div xmlns="http://www.w3.org/1999/xhtml">some html stuff like a <button>Button</button>
      </div>
  </foreignobject>
 </svg>

which look like this in python

from svg import *

s = SVG(width=200, height=200, elements = [
        ForeignObject(x=20, y=20, width=160, height=160, transform=[Rotate(a=20,x=80,y=80)],
        text='<div xmlns="http://www.w3.org/1999/xhtml">some html stuff like a <button>Button</button></div>')])
  
print(s.as_str())

@orsinium
Copy link
Member

Thank you!

@orsinium orsinium merged commit 9f25e04 into orsinium-labs:master Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants