add html5 descriptors table to provide documentation and CSS selectors

This commit is contained in:
Eugene.Kudelevsky
2010-05-16 18:17:42 +04:00
parent 3f91d9096a
commit a864ca0f0d
2 changed files with 571 additions and 88 deletions
@@ -19,12 +19,11 @@ import com.intellij.openapi.util.JDOMUtil;
import com.intellij.util.ArrayUtil;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jetbrains.annotations.NonNls;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.*;
/**
* @author maxim
@@ -37,6 +36,9 @@ public class HtmlDescriptorsTable {
@NonNls
public static final String HTMLTABLE_RESOURCE_NAME = "htmltable.xml";
@NonNls
public static final String HTML5TABLE_RESOURCE_NAME = "html5table.xml";
@NonNls
public static final String TAG_ELEMENT_NAME = "tag";
@@ -73,100 +75,107 @@ public class HtmlDescriptorsTable {
static {
try {
final Document document = JDOMUtil.loadDocument(HtmlDescriptorsTable.class.getResourceAsStream(HTMLTABLE_RESOURCE_NAME));
final List elements = document.getRootElement().getChildren(TAG_ELEMENT_NAME);
HtmlDocumentationProvider.setBaseHtmlExtDocUrl(
document.getRootElement().getAttribute(BASE_HELP_REF_ATTR).getValue()
);
List<String> htmlTagNames = new ArrayList<String>();
ourHtmlTagNames = new String[elements.size()];
loadHtmlElements(HTMLTABLE_RESOURCE_NAME, htmlTagNames);
int i = 0;
for (Object object : elements) {
final Element element = (Element)object;
ourHtmlTagNames[i] = element.getAttributeValue(NAME_ATTR);
loadHtmlElements(HTML5TABLE_RESOURCE_NAME, htmlTagNames);
HtmlTagDescriptor value = new HtmlTagDescriptor();
ourTagTable.put(ourHtmlTagNames[i], value);
value.setHelpRef(element.getAttributeValue(HELPREF_ATTR));
value.setDescription(element.getAttributeValue(DESCRIPTION_ATTR));
value.setName(ourHtmlTagNames[i]);
ourHtmlTagNames = ArrayUtil.toStringArray(htmlTagNames);
value.setHasStartTag(element.getAttribute(STARTTAG_ATTR).getBooleanValue());
value.setHasEndTag(element.getAttribute(ENDTAG_ATTR).getBooleanValue());
value.setEmpty(element.getAttribute(EMPTY_ATTR).getBooleanValue());
String attributeValue = element.getAttributeValue(DTD_ATTR);
if (attributeValue.length() > 0) {
value.setDtd(attributeValue.charAt(0));
}
++i;
}
final List attributes = document.getRootElement().getChildren(ATTRIBUTE_ELEMENT_NAME);
for (Object attribute : attributes) {
final Element element = (Element)attribute;
String attrName = element.getAttributeValue(NAME_ATTR);
HtmlAttributeDescriptor value = new HtmlAttributeDescriptor();
HtmlAttributeDescriptor previousDescriptor = ourAttributeTable.get(attrName);
if (previousDescriptor == null) {
ourAttributeTable.put(attrName, value);
}
else {
CompositeAttributeTagDescriptor parentDescriptor;
if (!(previousDescriptor instanceof CompositeAttributeTagDescriptor)) {
parentDescriptor = new CompositeAttributeTagDescriptor();
ourAttributeTable.put(attrName, parentDescriptor);
parentDescriptor.attributes.add(previousDescriptor);
}
else {
parentDescriptor = (CompositeAttributeTagDescriptor)previousDescriptor;
}
parentDescriptor.attributes.add(value);
}
value.setHelpRef(element.getAttributeValue(HELPREF_ATTR));
value.setDescription(element.getAttributeValue(DESCRIPTION_ATTR));
value.setName(attrName);
String attributeValue = element.getAttributeValue(DTD_ATTR);
if (attributeValue.length() > 0) {
value.setDtd(attributeValue.charAt(0));
}
value.setType(element.getAttributeValue(TYPE_ATTR));
value.setHasDefaultValue(element.getAttribute(DEFAULT_ATTR).getBooleanValue());
StringTokenizer tokenizer = new StringTokenizer(element.getAttributeValue(RELATED_TAGS_ATTR), ",");
int tokenCount = tokenizer.countTokens();
for (i = 0; i < tokenCount; ++i) {
final String s = tokenizer.nextToken();
if (s.equals("!")) {
value.setParentSetIsExclusionSet(true);
}
else {
if (value.getSetOfParentTags() == null) {
value.setSetOfParentTags(new String[tokenCount - (value.isParentSetIsExclusionSet() ? 1 : 0)]);
}
value.getSetOfParentTags()[i - (value.isParentSetIsExclusionSet() ? 1 : 0)] = s;
}
}
Arrays.sort(value.getSetOfParentTags());
}
} catch (Exception ex) {
ex.printStackTrace();
ourHtmlTagNames = ArrayUtil.EMPTY_STRING_ARRAY;
}
}
private static void loadHtmlElements(final String resourceName, List<String> htmlTagNames) throws JDOMException, IOException {
final Document document = JDOMUtil.loadDocument(HtmlDescriptorsTable.class.getResourceAsStream(resourceName));
final List elements = document.getRootElement().getChildren(TAG_ELEMENT_NAME);
HtmlDocumentationProvider.setBaseHtmlExtDocUrl(
document.getRootElement().getAttribute(BASE_HELP_REF_ATTR).getValue()
);
for (Object object : elements) {
final Element element = (Element)object;
String htmlTagName = element.getAttributeValue(NAME_ATTR);
htmlTagNames.add(htmlTagName);
HtmlTagDescriptor value = new HtmlTagDescriptor();
ourTagTable.put(htmlTagName, value);
value.setHelpRef(element.getAttributeValue(HELPREF_ATTR));
value.setDescription(element.getAttributeValue(DESCRIPTION_ATTR));
value.setName(htmlTagName);
value.setHasStartTag(element.getAttribute(STARTTAG_ATTR).getBooleanValue());
value.setHasEndTag(element.getAttribute(ENDTAG_ATTR).getBooleanValue());
value.setEmpty(element.getAttribute(EMPTY_ATTR).getBooleanValue());
String attributeValue = element.getAttributeValue(DTD_ATTR);
if (attributeValue.length() > 0) {
value.setDtd(attributeValue.charAt(0));
}
}
final List attributes = document.getRootElement().getChildren(ATTRIBUTE_ELEMENT_NAME);
for (Object attribute : attributes) {
final Element element = (Element)attribute;
String attrName = element.getAttributeValue(NAME_ATTR);
HtmlAttributeDescriptor value = new HtmlAttributeDescriptor();
HtmlAttributeDescriptor previousDescriptor = ourAttributeTable.get(attrName);
if (previousDescriptor == null) {
ourAttributeTable.put(attrName, value);
}
else {
CompositeAttributeTagDescriptor parentDescriptor;
if (!(previousDescriptor instanceof CompositeAttributeTagDescriptor)) {
parentDescriptor = new CompositeAttributeTagDescriptor();
ourAttributeTable.put(attrName, parentDescriptor);
parentDescriptor.attributes.add(previousDescriptor);
}
else {
parentDescriptor = (CompositeAttributeTagDescriptor)previousDescriptor;
}
parentDescriptor.attributes.add(value);
}
value.setHelpRef(element.getAttributeValue(HELPREF_ATTR));
value.setDescription(element.getAttributeValue(DESCRIPTION_ATTR));
value.setName(attrName);
String attributeValue = element.getAttributeValue(DTD_ATTR);
if (attributeValue.length() > 0) {
value.setDtd(attributeValue.charAt(0));
}
value.setType(element.getAttributeValue(TYPE_ATTR));
value.setHasDefaultValue(element.getAttribute(DEFAULT_ATTR).getBooleanValue());
StringTokenizer tokenizer = new StringTokenizer(element.getAttributeValue(RELATED_TAGS_ATTR), ",");
int tokenCount = tokenizer.countTokens();
for (int i = 0; i < tokenCount; ++i) {
final String s = tokenizer.nextToken();
if (s.equals("!")) {
value.setParentSetIsExclusionSet(true);
}
else {
if (value.getSetOfParentTags() == null) {
value.setSetOfParentTags(new String[tokenCount - (value.isParentSetIsExclusionSet() ? 1 : 0)]);
}
value.getSetOfParentTags()[i - (value.isParentSetIsExclusionSet() ? 1 : 0)] = s;
}
}
Arrays.sort(value.getSetOfParentTags());
}
}
static HtmlTagDescriptor getTagDescriptor(String tagName) {
return ourTagTable.get(tagName);
}
@@ -0,0 +1,474 @@
<html-property-table baseHelpRef="http://dev.w3.org/html5/spec/">
<tag name = "section"
helpref = "sections.html#the-section-element"
description = "generic document or application section"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "article"
helpref = "sections.html#the-article-element"
description = "self-contained composition in a document, page, application, or site and that is intended to be independently distributable or reusable, e.g. in syndication"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "aside"
helpref = "sections.html#the-aside-element"
description = "a section of a page that consists of content that is tangentially related to the content around the aside element, and which could be considered separate from that content"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "hgroup"
helpref = "sections.html#the-hgroup-element"
description = "heading of a section"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "header"
helpref = "sections.html#the-header-element"
description = "group of introductory or navigational aids"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "footer"
helpref = "sections.html#the-footer-element"
description = "a footer for its nearest ancestor sectioning content or sectioning root element"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "nav"
helpref = "sections.html#the-nav-element"
description = "section of a page that links to other pages or to parts within the page"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "figure"
helpref = "grouping-content.html#the-figure-element"
description = "some flow content, optionally with a caption, that is self-contained and is typically referenced as a single unit from the main flow of the document"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "figcaption"
helpref = "grouping-content.html#the-figcaption-element"
description = "a caption or legend for the rest of the contents of the figcaption element's parent figure element, if any"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "video"
helpref = "video.html#video"
description = "used for playing videos or movies"
startTag = "true"
endTag = "false"
empty = "false"
dtd = ""
/>
<tag name = "audio"
helpref = "video.html#audio"
description = "a sound or audio stream"
startTag = "true"
endTag = "false"
empty = "false"
dtd = ""
/>
<tag name = "embed"
helpref = "the-iframe-element.html#the-embed-element"
description = "integration point for an external application or interactive content"
startTag = "true"
endTag = "true"
empty = "true"
dtd = ""
/>
<tag name = "mark"
helpref = "text-level-semantics.html#the-mark-element"
description = "a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "progress"
helpref = "the-button-element.html#the-progress-element"
description = "the completion progress of a task"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "meter"
helpref = "the-button-element.html#the-meter-element"
description = "a scalar measurement within a known range, or a fractional value"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "time"
helpref = "rendering.html#the-time-element-0"
description = "either a time on a 24 hour clock, or a precise date in the proleptic Gregorian calendar, optionally with a time and a time-zone offset"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "ruby"
helpref = "text-level-semantics.html#the-ruby-element"
description = "allows one or more spans of phrasing content to be marked with ruby annotation"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "rt"
helpref = "text-level-semantics.html#the-rt-element"
description = "marks the ruby text component of a ruby annotation"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "rp"
helpref = "text-level-semantics.html#the-rp-element"
description = "can be used to provide parentheses around a ruby text component of a ruby annotation, to be shown by user agents that don't support ruby annotations"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "canvas"
helpref = "the-canvas-element.html#the-canvas-element"
description = "provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, or other visual images on the fly"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "command"
helpref = "interactive-elements.html#the-command"
description = "provides scripts with a resolution-dependent bitmap canvas, which can be used for rendering graphs, game graphics, or other visual images on the fly"
startTag = "true"
endTag = "true"
empty = "true"
dtd = ""
/>
<tag name = "datalist"
helpref = "the-button-element.html#the-datalist-element"
description = "a set of option elements that represent predefined options for other controls"
startTag = "true"
endTag = "true"
empty = "false"
dtd = ""
/>
<tag name = "keygen"
helpref = "the-button-element.html#the-keygen-element"
description = "a key pair generator control"
startTag = "true"
endTag = "true"
empty = "true"
dtd = ""
/>
<tag name = "output"
helpref = "the-button-element.html#the-output-element"
description = "the result of a calculation"
startTag = "true"
endTag = "true"
empty = "true"
dtd = ""
/>
<attribute name = "media"
helpref = "links.html#attr-hyperlink-media"
description = "suppress word wrap"
relatedTags = "a,area"
dtd = ""
type = "common.data.mediaquery"
default = "false"
/>
<attribute name = "ping"
helpref = ""
description = "a space-separated list of URLs which have to be pinged when the hyperlink is followed"
relatedTags = "a,area"
dtd = ""
type = "common.data.uris"
default = "true"
/>
<attribute name = "hreflang"
helpref = "links.html#attr-hyperlink-hreflang"
description = "gives the language of the linked resource"
relatedTags = "area"
dtd = ""
type = "common.data.langcode"
default = "false"
/>
<attribute name = "rel"
helpref = "links.html#attr-hyperlink-rel"
description = ""
relatedTags = "area"
dtd = ""
type = "common.data.tokens"
default = "false"
/>
<attribute name = "charset"
helpref = "semantics.html#attr-meta-charset"
description = "the character encoding used by the document"
relatedTags = "meta"
dtd = ""
type = "common.data.charset"
default = "false"
/>
<attribute name = "autofocus"
helpref = "association-of-controls-and-forms.html#attr-fe-autofocus"
description = "allows the user to indicate that a control is to be focused as soon as the page is loaded, allowing the user to just start typing without having to manually focus the main control"
relatedTags = "input,select,textarea,button"
dtd = ""
type = "(autofocus)"
default = "true"
/>
<attribute name = "placeholder"
helpref = "common-input-element-attributes.html#attr-input-placeholder"
description = "short hint (a word or short phrase) intended to aid the user with data entry"
relatedTags = "input"
dtd = ""
type = "string"
default = "true"
/>
<attribute name = "placeholder"
helpref = "the-button-element.html#attr-textarea-placeholder"
description = "a hint (a word or short phrase) intended to aid the user with data entry"
relatedTags = "textarea"
dtd = ""
type = "string"
default = "false"
/>
<attribute name = "form"
helpref = "association-of-controls-and-forms.html#attr-fae-form"
description = ""
relatedTags = "input,output,select,textarea,button,fieldset"
dtd = ""
type = "common.data.idref"
default = "true"
/>
<attribute name = "required"
helpref = "common-input-element-attributes.html#attr-input-required"
description = "when specified, the element is required"
relatedTags = "input"
dtd = ""
type = "(required)"
default = "true"
/>
<attribute name = "required"
helpref = "the-button-element.html#attr-textarea-required"
description = "when specified, the user will be required to enter a value before submitting the form"
relatedTags = "textarea"
dtd = ""
type = "(required)"
default = "false"
/>
<attribute name = "disabled"
helpref = ""
description = "disabling all its contents when specified"
relatedTags = "fieldset"
dtd = ""
type = "(disabled)"
default = "false"
/>
<attribute name = "autocomplete"
helpref = "common-input-element-attributes.html#attr-input-autocomplete"
description = "autocompletion state"
relatedTags = "input"
dtd = ""
type = "(on | off)"
default = "true"
/>
<attribute name = "min"
helpref = "common-input-element-attributes.html#attr-input-min"
description = "indicate the allowed range of values for the element"
relatedTags = "input"
dtd = ""
type = "common.data.datetime"
default = "true"
/>
<attribute name = "max"
helpref = "common-input-element-attributes.html#attr-input-max"
description = "indicate the allowed range of values for the element"
relatedTags = "input"
dtd = ""
type = "common.data.datetime"
default = "true"
/>
<attribute name = "multiple"
helpref = "common-input-element-attributes.html#attr-input-multiple"
description = "whether the user is to be allowed to specify more than one value"
relatedTags = "input"
dtd = ""
type = "(multiple)"
default = "false"
/>
<attribute name = "pattern"
helpref = "common-input-element-attributes.html#attr-input-pattern"
description = "regular expression against which the control's value is to be checked"
relatedTags = "input"
dtd = ""
type = "form.data.pattern"
default = "true"
/>
<attribute name = "step"
helpref = "common-input-element-attributes.html#attr-input-step"
description = "the granularity that is expected (and required) of the value, by limiting the allowed values"
relatedTags = "input"
dtd = ""
type = "string"
default = "true"
/>
<attribute name = "list"
helpref = "common-input-element-attributes.html#attr-input-list"
description = "element that lists predefined options suggested to the user"
relatedTags = "input"
dtd = ""
type = "common.data.idref"
default = "true"
/>
<attribute name = "novalidate"
helpref = "association-of-controls-and-forms.html#attr-fs-novalidate"
description = "if the form is not to be validated during submission"
relatedTags = "form"
dtd = ""
type = "(novalidate)"
default = "true"
/>
<attribute name = "formnovalidate"
helpref = "association-of-controls-and-forms.html#attr-fs-formnovalidate"
description = "if the form is not to be validated during submission"
relatedTags = "input,button"
dtd = ""
type = "(formnovalidate)"
default = "true"
/>
<attribute name = "formaction"
helpref = "association-of-controls-and-forms.html#attr-fs-formaction"
description = "server-side form handler"
relatedTags = "input,button"
dtd = ""
type = "common.data.uri"
default = "true"
/>
<attribute name = "formenctype"
helpref = "association-of-controls-and-forms.html#attr-fs-formenctype"
description = ""
relatedTags = "input,button"
dtd = ""
type = "shared-form.attrs.formenctype.data"
default = "true"
/>
<attribute name = "formmethod"
helpref = "association-of-controls-and-forms.html#attr-fs-formmethod"
description = "HTTP method used to submit the form"
relatedTags = "input,button"
dtd = ""
type = "(GET | POST)"
default = "true"
/>
<attribute name = "formtarget"
helpref = "association-of-controls-and-forms.html#attr-fs-formtarget"
description = "render in this frame"
relatedTags = "input,button"
dtd = ""
type = "common.data.browsing-context-or-keyword"
default = "true"
/>
<attribute name = "type"
helpref = "interactive-elements.html#attr-menu-type"
description = "kind of menu being declared"
relatedTags = "menu"
dtd = ""
type = "(toolbar | context)"
default = "false"
/>
<attribute name = "label"
helpref = "interactive-elements.html#attr-menu-label"
description = "label of the menu"
relatedTags = "menu"
dtd = ""
type = "string"
default = "false"
/>
<attribute name = "scoped"
helpref = "interactive-elements.html#attr-menu-label"
description = "enables scoped style sheets"
relatedTags = "style"
dtd = ""
type = "(scoped)"
default = "true"
/>
<attribute name = "async"
helpref = "scripting-1.html#attr-script-async"
description = "influences script loading and execution"
relatedTags = "script"
dtd = ""
type = "(async)"
default = "true"
/>
<attribute name = "manifest"
helpref = "semantics.html#attr-html-manifest"
description = "address of the document's application cache manifest"
relatedTags = "html"
dtd = ""
type = "common.data.uri"
default = "true"
/>
<attribute name = "sizes"
helpref = "links.html#attr-link-sizes"
description = "the size of the referenced icon"
relatedTags = "link"
dtd = ""
type = "string"
default = "true"
/>
<attribute name = "reversed"
helpref = "grouping-content.html#attr-ol-reversed"
description = "if the list order is descending when present"
relatedTags = "ol"
dtd = ""
type = "(reversed)"
default = "true"
/>
<attribute name = "sandbox"
helpref = "the-iframe-element.html#attr-iframe-sandbox"
description = "enables a set of extra restrictions on any content hosted by the iframe"
relatedTags = "iframe"
dtd = ""
type = "SandboxType"
default = "true"
/>
<attribute name = "seamless"
helpref = "the-iframe-element.html#attr-iframe-seamless"
description = ""
relatedTags = "iframe"
dtd = ""
type = "(seamless)"
default = "true"
/>
<attribute name = "srcdoc"
helpref = "the-iframe-element.html#attr-iframe-srcdoc"
description = "content of the page that the nested browsing context is to contain"
relatedTags = "iframe"
dtd = ""
type = "string"
default = "true"
/>
</html-property-table>