Add Custom HTML Tags

How can I add custom html tags through the open api? I would like to define some new elements so they do not register as warnings. I know how to do this through the UI, but how can I accomplish this programatically. I'm using the HTMLFileType.INSTANCE as my language instance. I would also like to offer the new elements up as auto completion, but I realize that might be a topic for another post.

Screen Shot 2015-05-31 at 2.59.37 PM.png

2 comments
Comment actions Permalink

I was able to make the new tags available for completion, but they are still not showing up as valid input. I thought I'd paste the code if anyone else was looking to do the same. I would still like to add the same elements to the custom tags in the unknown tag inspection.


public class ISMLTagDescriptorsProvider implements XmlElementDescriptorProvider, XmlTagNameProvider {
    private final String[] ismlTagNames = {
            "isactivedatacontext",
            "isactivedatahead",
            "isanalyticsoff",
            "isbreak",
            "iscache",
            "iscomment",
            "iscomponent",
            "iscontent",
            "iscontinue",
            "iscookie",
            "isdecorate",
            "iselse",
            "iselseif",
            "isif",
            "isinclude",
            "isloop",
            "ismodule",
            "isobject",
            "isprint",
            "isredirect",
            "isremove",
            "isreplace",
            "isscript",
            "isselect",
            "isset",
            "isslot",
            "isstatus",
    
};


    @Nullable
    @Override
    public
XmlElementDescriptor getDescriptor(XmlTag tag) {
        return null;
    
}

    @Override
    public void addTagNameVariants
(List<LookupElement> elements, XmlTag tag, String prefix) {
        for (String tagName : ismlTagNames) {
            elements.add(LookupElementBuilder.create(tagName));
        
}
    }
}
0
Comment actions Permalink

You need to provide implementation of getDescriptor() to make it work. see com.intellij.codeInspection.htmlInspections.HtmlUnknownTagInspectionBase#checkTag

0

Please sign in to leave a comment.