SVG in HTML5 Notes

From SVG

Current SVG in HTML5 status



3.1.1 Documents in the DOM

Requires that Document implements both HTMLDocument and SVGDocument, if SVG is supported.


3.1.4 DOM tree accessors

Says that getting and setting document.title will use the SVGDocument.title if the document is an SVG document. (It's wrong about throwing an exception when read only.)

It mentions that SVG elements (as well as HTML and MathML) define which classes they are in with a "class" attribute. This is done to make getElementsByClassName() find SVG elements.


3.2.5.1.2 Flow content

Defines 'svg' as flow content.


3.2.5.1.5 Phrasing content

Defines 'svg' as phrasing content.


3.2.5.1.6 Embedded content

Defines 'svg' as embedded content. Also says "Elements that are from namespaces other than the HTML namespace and that convey content but not metadata, are embedded content for the purposes of the content models defined in this specification. (For example, MathML, or SVG.)" but only the 'svg' element itself seems to be defined as embedded content.

(Embedded content is used to delinate paragraphs (just semantics AFAICT),


4.8.2 The img element

<img src> must not reference SVG documents with script.


3.8.10.13 Security and privacy considerations

A non-normative note says "For instance, if an SVG animation was embedded in a video element, the user agent would not give it access to the DOM of the outer page. From the perspective of scripts in the SVG resource, the SVG file would appear to be in a lone top-level browsing context with no parent."

No mention in the definition of 'video' or HTMLMediaElement that SVGs can be used in video, though.


4.8.11 The canvas element

Mentions that toDataURL("image/svg+xml") might work.


4.8.16 SVG

Encourages interactive HTML user agents to provide a way to export an SVG fragment as an nswf XML fragment.

Requires that any HTML child elements of foreignObject must be flow content.

Requires that <svg:title> inside HTML documents have only phrasing content.

States that the semantics of SVG elements are defined by SVG (or other relevant specs).

"The SVG specification states that elements that are not in the SVG namespace, that are in SVG fragments, and that are not included in a foreignObject element, are to be ignored. Similarly, this specification does not define any processing for elements in SVG fragments that are not in the HTML namespace; they are considered neither conforming nor non-conforming from the perspective of this specification."


4.12.1 Tag clouds

Suggests that SVG could be used for tag clouds.


6.12.3.8 Link type "icon"

Allows <link rel="icon" sizes="any">:

 The any keyword represents that the resource contains a scalable icon, e.g.
 as provided by an SVG image.


9.1.2 Elements

Elements in the SVG namespace (or MathML) are defined as "foreign elements".

Foreign elements can have the self-closing tag syntax.

Foreign elements cannot text content with the character "<" or an ambiguous ampersand. (A non-ambiguous one would be one followed by a space character, a "<" or another "&".) That's the same as normal HTML elements.

An example states:

 The HTML syntax does not support namespace declarations, even in foreign elements.
 
 For instance, consider the following HTML fragment:
  <p>
   <svg>
    <metadata>
     <!-- this is invalid -->
     <cdr:license xmlns:cdr="http://www.example.com/cdr/metadata" name="MIT"/>
    </metadata>
   </svg>
  </p>
 The innermost element, cdr:license, is actually in the SVG namespace, as the
 "xmlns:cdr" attribute has no effect (unlike in XML). In fact, as the comment
 in the fragment above says, the fragment is actually non-conforming. This is
 because the SVG specification does not define any elements called
 "cdr:license" in the SVG namespace.

9.2.4.17 Markup declaration open state

Defines how CDATA sections are parsed in foreign content.

9.2.5.1 Creating and inserting elements

This defines the attribute name case conversion table. It also defines the mapping of XML, XMLNS and XLink attributes into attributes with appropriate namespaces.

9.2.5.10 The "in body" insertion mode

When an 'svg' element is encountered:

 * Reconstructs active formatting elements
 * Fixes up SVG and foreign attributes
 * Inserts the SVG element
 * Remembers the current insertion mode ("secondary insertion mode") so that
   it can return to it when the closing </svg> is encountered.
 * Switches to in foreign content.

9.2.5.21 The "in foreign content" insertion mode


</script> causes the script element to be processed as defined in SVG (if the UA supports SVG).


If the current node is <annotation-xml> and this is an <svg> start tag, or if the current node is <foreignObject> and this is anything, or if the current node is <desc> and this is anything, or if the current node is <title> and this is anything, or if the current node is an HTML node and this is anything, or this is anything:

 Process the token using the rules for the secondary insertion mode.
 If after doing so the insertion mode is still "in foreign content", but there
 is no element in scope that has a namespace than the HTML namespace, switch
 to the secondary insertion mode.

it gets processed using the secondary insertion mode


These start tags cause a parse error:

 "b", "big", "blockquote", "body", "br", "center", "code", "dc", "dd", "div",
 "dl", "ds", "dt", "em", "embed", "h1", "h2", "h3", "h4", "h5", "h6", "head",
 "hr", "i", "img", "li", "listing", "menu", "meta", "nobr", "ol", "p", "pre",
 "ruby", "s", "small", "span", "strong", "strike", "sub", "sup", "table",
 "tt", "u", "ul", "var"

or

 "font" if it has color, face or size attribute

or

 EOF

This switches back to the secondary insertion mode.


Other start tags get their element names fixed up. http://www.w3.org/Bugs/Public/show_bug.cgi?id=7378 -- no textArea or solidColor


9.3 Namespaces

Mentions the SVG namespace.


References

Normative reference to 1.2T, due to its better <script> processing definition. http://www.w3.org/Bugs/Public/show_bug.cgi?id=7379