How to support formatting non-standard tag in eclipse html editor

You might found that your eclipse html editor does not support formatting some customized tags, such as tabset and tab which are introduced by Angular JS.

For example:

<tabset><tab heading="Apples"></tab><tab heading="Oranges"></tab></tabset>

When you click "format" in menu, or press "Ctrl + Shift + F", you must want the following result:

<tabset>
        <tab heading="Apples"></tab>
        <tab heading="Oranges"></tab>
</tabset>

Unfortunately, it doe's not give a formatted result at all.


Now I found that we can add some customized tags into HTML pluging jar file, then the formatter will take effect.

1. find the jar location

# if your eclipse is installed with P2 pool
C:\Users\<USERNAME>\.p2\pool\plugins

# if your eclipse is not with P2 pool
eclipse\plugins

2. find the jar file

org.eclipse.wst.html.core_1.1.802.vYYYYMMDDxxx.jar

Take my Mars (eclipse version) as Example:

org.eclipse.wst.html.core_1.1.802.v201501312139.jar

3. Use Java Decompiler to locate the following class

org.eclipse.wst.html.core.internal.contentmodel.HTML5ElementCollection

4. Create a new Java project to do this hack

It will need another jar file as lib:
org.eclipse.wst.xml.core_xxxxxxxxxxxxxx.jar

screen capture of the eclipse project

5. Edit part 1)

# Before change
private static final String[] SECTIONING = { "article", "aside", "nav", "section"};

# After change
private static final String[] SECTIONING = { "article", "aside", "nav", "section", "tabset", "tab" };

6. Edit part 2)

protected CMNode create(String elementName) {
        CMNode edec = null;
        if (elementName.equalsIgnoreCase("ACRONYM")) {
        //......
        } else if (elementName.equalsIgnoreCase("tabset")) {
                edec = new HedSectioning("tabset", this);
        } else if (elementName.equalsIgnoreCase("tab")) {
                edec = new HedSectioning("tab", this);

        }

6. Edit part 3)

        private static String[] getNames() {
                if (fNames == null) {
                        fNames = new String[Ids50.getNumOfIds()];
                        fNames[0] = "A";
                        //......
                        fNames[133] = "video";
                        fNames[134] = "tabset";
                        fNames[135] = "tab";

                }
                return fNames;
        }

7. Edit part 4)

private static class Ids50 extends ElementCollection.Ids {
        //........
        public static final int ID_VIDEO = 133;
        public static final int ID_TABSET = 134;
        public static final int ID_TAB = 135;

}

8. Update the jar with new class

jar uf org.eclipse.wst.html.core_1.1.802.v201501312139.jar  org/eclipse/wst/html/core/internal/contentmodel/HTML5ElementCollection.class
 org/eclipse/wst/html/core/internal/contentmodel/HTML5ElementCollection$Ids50.class

Finally

Now you can replace the plugin jar with your new jar, then the format for tabset and tab will be supported.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,991评论 19 139
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,769评论 18 399
  • //Clojure入门教程: Clojure – Functional Programming for the J...
    葡萄喃喃呓语阅读 3,777评论 0 7
  • “不争,却越优”,是娱乐圈里对演员孙俪的评价。 孙俪是我喜爱的明星之一,喜欢她某处的特点,说不出具体哪里,今天在看...
    Lin小懒阅读 350评论 0 1
  • 最近在卖火车票的时候经常遇到顾客问道:“能刷卡么?”,我手里没有那么多现金,遇到这种情况,我都会第一时间说:“不好...
    心逸道阅读 838评论 11 6