java IntelliJ 社区版 JSP 语法高亮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33782187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:07:59  来源:igfitidea点击:

IntelliJ community edition JSP Syntax highlighting

javajspintellij-idea

提问by Peter Catalin

I just downloaded IntelliJ 15.0.1 Community Edition because i'm sick of Eclipse and it looks horrible on my laptop (Ubuntu 14.04 LTS). Everything was going pretty well until I saw that syntax highlighting in JSP files was not working.

我刚刚下载了 IntelliJ 15.0.1 社区版,因为我厌倦了 Eclipse,而且它在我的笔记本电脑(Ubuntu 14.04 LTS)上看起来很糟糕。一切都很顺利,直到我看到 JSP 文件中的语法突出显示不起作用。

I went to Settings/Editor/File Types

我去了设置/编辑器/文件类型

In the Recognized File Types,among other options, I have this one:

在 Recognized File Types 中,除其他选项外,我有这个:

JSP Files (syntax Highlighting Only)

JSP 文件(仅语法高亮显示)

When I select it I can see in the registered patterns: *.jsp, *.tag which is exactly what I want ... but it doesn't work ...any ideas?

当我选择它时,我可以在注册模式中看到: *.jsp, *.tag 这正是我想要的......但它不起作用......有什么想法吗?

Thanks

谢谢

回答by Roland

IntelliJ IDEA allows to manually add syntax highlighting settings in "Settings > File Types" even in the Community Edition BUT it ignores these settings after a restart.

IntelliJ IDEA 允许在“设置 > 文件类型”中手动添加语法高亮设置,即使在社区版中也是如此,但它会在重新启动后忽略这些设置

These settings are stored in the user's home directory at e.g. ~/.IdeaIC2016.1/config/filetypes/*.xml. Unfortunately, after a restart of the IDE, these settings are NOT read, therefore it seems useless to configure any settings :-(

这些设置存储在用户的主目录中,例如 ~/.IdeaIC2016.1/config/filetypes/*.xml。不幸的是,在重新启动 IDE 后,不会读取这些设置,因此配置任何设置似乎都没有用:-(

<filetype binary="false" description="JSP files (syntax highlighting only)" name="JSP">
  <highlighting>
    <options>
      <option name="LINE_COMMENT" value="" />
      <option name="COMMENT_START" value="&lt;%--" />
      <option name="COMMENT_END" value="--%&gt;" />
      <option name="HEX_PREFIX" value="#" />
      <option name="NUM_POSTFIXES" value="" />
      <option name="HAS_BRACES" value="true" />
      <option name="HAS_BRACKETS" value="true" />
      <option name="HAS_PARENS" value="true" />
      <option name="HAS_STRING_ESCAPES" value="true" />
    </options>
    <keywords keywords="%&gt;;&lt;%!;&lt;%@;include;page;taglib" ignore_case="false" />
    <keywords2 keywords="c:choose;c:if;c:otherwise;c:set;c:url;c:when;fmt:message;fmt:setBundle;fmt:setLocale;s:eval;s:message;sec:authorize" />
    <keywords3 keywords="html;head;title;meta;header;nav;section;footer;body;a;br;hr;div;form;input;button;submit;textarea;p;script;noscript;span;style;table;td;th;tr;ol;ul;li;label;i;h1;h2;h3;h4;h5;img" />
    <keywords4 keywords="if;else;function;for;do;let;this;while;with;thows;true;false;char;case;continue;alert;confirm;console;length;return;var;boolean;forms;" />
  </highlighting>
</filetype>

(~/.IdeaIC2016.1/config/filetypes/JSP.xml )

(~/.IdeaIC2016.1/config/filetypes/JSP.xml)

IntelliJ Community Edition also ignores any file-type settings for CSS-files that could look like this:

IntelliJ 社区版还会忽略 CSS 文件的任何文件类型设置,这些设置可能如下所示:

<filetype binary="false" description="CSS files (syntax highlighting only)" name="CSS">
  <highlighting>
    <options>
      <option name="LINE_COMMENT" value="" />
      <option name="COMMENT_START" value="/*" />
      <option name="COMMENT_END" value="*/" />
      <option name="HEX_PREFIX" value="#" />
      <option name="NUM_POSTFIXES" value="" />
      <option name="HAS_BRACES" value="true" />
    </options>
    <keywords keywords="a;body;button;div;font;font-face;form;frame;h1;h2;h3;h4;iframe;img;import;input;li;link;media;nav;ol;option;p;select;span;table;td;th;title;tr;u;ul;video" ignore_case="false" />
    <keywords2 keywords="  box-shadow;background;background-color;border;border-radius;bottom;box-shadow;color;content;cursor;display;float;font-family;font-size;font-weight;height;left;line-height;list-style-type;margin;margin-bottom;margin-left;margin-right;margin-top;outline;overflow;padding;padding-bottom;padding-left;padding-right;padding-top;position;right;text-align;text-decoration;text-transform;top;vertical-align;white-space;width;z-index;zoom" />
    <keywords3 keywords="em;pt;px;rgb;rgba" />
    <keywords4 keywords="!important;active;after;before;hover;none;visited" />
  </highlighting>
</filetype>

(~/.IdeaIC2016.1/config/filetypes/CSS.xml)

(~/.IdeaIC2016.1/config/filetypes/CSS.xml)

回答by Swerner1975

You must create a own JSP File Type e.g. "My JSP". The registered File Patterns must be:

您必须创建自己的 JSP 文件类型,例如“我的 JSP”。注册的文件模式必须是:

*.j?p

*。J.P

*.j?pf

*.j?pf

(*.jsp are reserved)

(*.jsp 保留)

In the default File Type: "JSP Files (syntax Highlighting Only)" you must delete the File Patterns *.jsp. Set it to e.g. *.jjj.

在默认文件类型:“JSP 文件(仅语法高亮显示)”中,您必须删除文件模式 *.jsp。将其设置为例如*.jjj

Then the IntelliJ Idea saves this File Type and after a Restart the Settings are still available.

然后 IntelliJ Idea 保存此文件类型,重启后设置仍然可用。

回答by aarjithn

IntelliJ supports JSP syntax highlighting, but strangely none of the syntax is predefined. It allows us to define the syntax though if you double click "JSP Files (syntax highlighting only)".

IntelliJ 支持 JSP 语法高亮,但奇怪的是没有任何语法是预定义的。如果您双击“JSP 文件(仅语法高亮显示)”,它允许我们定义语法。

The + / - buttons below allows to add keywords and 1 / 2 / 3 / 4 tabs give different syntax colours. It is not possible to add all HTML/JSP keywords manually one by one but I've defined most common used keywords and it is much better than having no highlighting at all.

下面的 + / - 按钮允许添加关键字和 1 / 2 / 3 / 4 个选项卡给出不同的语法颜色。不可能一一手动添加所有 HTML/JSP 关键字,但我已经定义了最常用的关键字,这比根本没有突出显示要好得多。

Edit File Type

编辑文件类型