full SVG support: xlink schema provided

This commit is contained in:
Dennis Ushakov
2014-09-04 14:08:40 +04:00
parent e4d73d688b
commit 998397403a
4 changed files with 83 additions and 4 deletions
@@ -69,6 +69,9 @@ public class RelaxedHtmlFromRngElementDescriptor implements XmlElementDescriptor
@Override
public XmlAttributeDescriptor getAttributeDescriptor(XmlAttribute attribute) {
XmlAttributeDescriptor descriptor = myDelegate.getAttributeDescriptor(attribute);
if (descriptor != null) return descriptor;
return getAttributeDescriptor(attribute.getName(), attribute.getParent());
}
@@ -94,9 +97,7 @@ public class RelaxedHtmlFromRngElementDescriptor implements XmlElementDescriptor
@Override
public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
XmlAttributeDescriptor descriptor = myDelegate.getAttributeDescriptor(attributeName.toLowerCase(), context);
// some elements in HTML5 schema (e.g. SVG) are case sensitive
descriptor = descriptor == null ? myDelegate.getAttributeDescriptor(attributeName, context) : descriptor;
final XmlAttributeDescriptor descriptor = myDelegate.getAttributeDescriptor(attributeName.toLowerCase(), context);
if (descriptor != null) return descriptor;
return RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(attributeName, context);
@@ -0,0 +1,66 @@
<!ELEMENT simple ANY>
<!ATTLIST simple
xlink:type (simple) #FIXED "simple"
xlink:href CDATA #IMPLIED
xlink:role CDATA #IMPLIED
xlink:arcrole CDATA #IMPLIED
xlink:title CDATA #IMPLIED
xlink:show (new
|replace
|embed
|other
|none) #IMPLIED
xlink:actuate (onLoad
|onRequest
|other
|none) #IMPLIED>
<!ELEMENT extended ((title|resource|locator|arc)*)>
<!ATTLIST extended
xmlns:xlink CDATA #FIXED "http://www.w3.org/1999/xlink"
xlink:type (extended) #FIXED "extended"
xlink:role CDATA #IMPLIED
xlink:title CDATA #IMPLIED>
<!ELEMENT title ANY>
<!-- xml:lang is not required, but provides much of the motivation
for title elements in addition to attributes, and so is provided
here for convenience -->
<!ATTLIST title
xlink:type (title) #FIXED "title"
xml:lang CDATA #IMPLIED>
<!ELEMENT resource ANY>
<!ATTLIST resource
xlink:type (resource) #FIXED "resource"
xlink:role CDATA #IMPLIED
xlink:title CDATA #IMPLIED
xlink:label NMTOKEN #IMPLIED>
<!ELEMENT locator (title*)>
<!-- label is not required, but locators have no particular XLink
function if they are not labeled -->
<!ATTLIST locator
xlink:type (locator) #FIXED "locator"
xlink:href CDATA #REQUIRED
xlink:role CDATA #IMPLIED
xlink:title CDATA #IMPLIED
xlink:label NMTOKEN #IMPLIED>
<!ELEMENT arc (title*)>
<!-- from and to have default behavior when values are missing -->
<!ATTLIST arc
xlink:type (arc) #FIXED "arc"
xlink:arcrole CDATA #IMPLIED
xlink:title CDATA #IMPLIED
xlink:show (new
|replace
|embed
|other
|none) #IMPLIED
xlink:actuate (onLoad
|onRequest
|other
|none) #IMPLIED
xlink:from NMTOKEN #IMPLIED
xlink:to NMTOKEN #IMPLIED>
@@ -63,5 +63,6 @@ public class InternalResourceProvider implements StandardResourceProvider{
// svg and mathML
impl.addIgnoredResource(HtmlUtil.MATH_ML_NAMESPACE);
impl.addIgnoredResource(HtmlUtil.SVG_NAMESPACE);
impl.addInternalResource("http://www.w3.org/1999/xlink", "xlink.dtd");
}
}
@@ -3,6 +3,7 @@ package com.intellij.xml;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlDocument;
import com.intellij.xml.util.HtmlUtil;
import org.jetbrains.annotations.Nullable;
/**
@@ -19,6 +20,16 @@ public class HtmlXmlExtension extends DefaultXmlExtension {
@Nullable
@Override
public String[][] getNamespacesFromDocument(XmlDocument parent, boolean declarationsExist) {
return super.getNamespacesFromDocument(parent, false);
String[][] namespaces = super.getNamespacesFromDocument(parent, false);
if (namespaces == null || !HtmlUtil.isHtml5Document(parent)) return namespaces;
for (String[] namespace : namespaces) {
if ("xlink".equals(namespace[0])) return namespaces;
}
String[][] newNamespaces = new String[namespaces.length + 1][2];
System.arraycopy(namespaces, 0, newNamespaces, 0, namespaces.length);
newNamespaces[namespaces.length] = new String[] {"xlink", "http://www.w3.org/1999/xlink"};
return newNamespaces;
}
}