summaryrefslogtreecommitdiff
path: root/xml/xml-psi-impl/src/com/intellij/xml/HtmlXmlExtension.java
blob: e54a93394242eb4617bc1a193678cd2f49ecf24a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;

/**
 * @author Dmitry Avdeev
 *         Date: 24.10.13
 */
public class HtmlXmlExtension extends DefaultXmlExtension {

  @Override
  public boolean isAvailable(PsiFile file) {
    return file.getFileType() == HtmlFileType.INSTANCE;
  }

  @Nullable
  @Override
  public String[][] getNamespacesFromDocument(XmlDocument parent, boolean declarationsExist) {
    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;
  }
}