From 3b59425c3dca058482fb8d129f1c93378dbc73ee Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Thu, 28 May 2015 19:58:45 +0300 Subject: [PATCH] support implicit head and body for html4 #WEB-2409 fixed --- .../html/dtd/HtmlElementDescriptorImpl.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/dtd/HtmlElementDescriptorImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/dtd/HtmlElementDescriptorImpl.java index aec421651439..969129e22022 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/dtd/HtmlElementDescriptorImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/html/dtd/HtmlElementDescriptorImpl.java @@ -17,6 +17,7 @@ package com.intellij.psi.impl.source.html.dtd; import com.intellij.html.impl.RelaxedHtmlFromSchemaElementDescriptor; import com.intellij.psi.PsiElement; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlTag; import com.intellij.xml.XmlAttributeDescriptor; import com.intellij.xml.XmlElementDescriptor; @@ -70,6 +71,30 @@ public class HtmlElementDescriptorImpl extends BaseXmlElementDescriptorImpl { if (!myCaseSensitive) name = name.toLowerCase(); XmlElementDescriptor xmlElementDescriptor = getElementDescriptor(name, element); + if (xmlElementDescriptor == null && "html".equals(getName())) { + XmlTag head = null; + XmlTag body = null; + + for (XmlTag child : PsiTreeUtil.getChildrenOfTypeAsList(contextTag, XmlTag.class)) { + if ("head".equals(child.getName())) head = child; + if ("body".equals(child.getName())) body = child; + } + if (head == null) { + if (body == null || element.getTextOffset() < body.getTextOffset()) { + XmlElementDescriptor headDescriptor = getElementDescriptor("head", contextTag); + if (headDescriptor != null) { + xmlElementDescriptor = headDescriptor.getElementDescriptor(element, contextTag); + } + } + } + if (xmlElementDescriptor == null && body == null) { + XmlElementDescriptor bodyDescriptor = getElementDescriptor("body", contextTag); + if (bodyDescriptor != null) { + xmlElementDescriptor = bodyDescriptor.getElementDescriptor(element, contextTag); + } + } + + } if (xmlElementDescriptor == null && myRelaxed) { xmlElementDescriptor = RelaxedHtmlFromSchemaElementDescriptor.getRelaxedDescriptor(this, element); }