用于自动缩进 Java 和 HTML 文件的脚本或程序

发布于 2024-12-02 00:22:10 字数 147 浏览 1 评论 0原文

我想知道您是否有一些自动缩进一些 Java 和 HTML 文件的想法。 HTML 文件可以包含 JavaScript 和 JSP 代码。

理想的程序应该通过命令行同时对所有文件执行。

编辑:还有其他解决方案吗?

谢谢你,
蝙蝠

I'd like to know if you have some idea for indenting automatically some Java and HTML files. The HTML files could contain JavaScript and JSP code.

The ideal program should be executed through the command line on all files in the same time.

Edit : Any other solution?

Thank you,
Bat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

冬天旳寂寞 2024-12-09 00:22:10

HtmlTidy 至少应该可以解决 HTML 文件的问题。

下面是一个示例:

#$ cat test.html 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head><title>Test page
</title></head><body><b>Hello World</b>
</body>
</html>

#$ tidy -i -q test.html 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">

  <title>Test page</title>
</head>

<body>
  <b>Hello World</b>
</body>
</html>
aioobe@e6510:~/tmp$ 

如果您希望 tidy 实际修改文件,请添加 -m。 (是的,您可以一次提供多个文件:-)

HtmlTidy should do the trick for HTML files at least.

Here's an example:

#$ cat test.html 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head><title>Test page
</title></head><body><b>Hello World</b>
</body>
</html>

#$ tidy -i -q test.html 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">

  <title>Test page</title>
</head>

<body>
  <b>Hello World</b>
</body>
</html>
aioobe@e6510:~/tmp$ 

Add -m if you want tidy to actually modify the files. (And yes, you can supply multiple files at once :-)

泛泛之交 2024-12-09 00:22:10

使用 eclipse 之类的 IDE。它有一个源清理选项,您可以使用它来设置自己的自定义规则(或使用默认值)来格式化代码。

如果您正在寻找命令行调用,请阅读此链接。复制粘贴以供参考:

<path-to-eclipse>\eclipse.exe -vm <path-to-vm>\java.exe -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config <path-to-config-file>\org.eclipse.jdt.core.prefs <path-to-your-source-files>\*.java

类似地用于格式化其他源,如 HTML、XML 等

Use an IDE like eclipse. It has a source cleanup option that you could use to set your own custom rule(or use default) for formatting code.

If you are looking for command line invocation, read this link. Copy pasting for reference:

<path-to-eclipse>\eclipse.exe -vm <path-to-vm>\java.exe -application org.eclipse.jdt.core.JavaCodeFormatter -verbose -config <path-to-config-file>\org.eclipse.jdt.core.prefs <path-to-your-source-files>\*.java

Similarly use for formatting other source like HTML, XML etc

寄居人 2024-12-09 00:22:10

如果我没记错的话,DrJava( http://drjava.org/ ) 有一个用于缩进 java 文件的命令行工具。

是的,http://drjava.org/docs/user/apc.html

DrJava( http://drjava.org/ ) has a command line tool for indenting java files if I remember right.

Yes it does http://drjava.org/docs/user/apc.html

絕版丫頭 2024-12-09 00:22:10

您可以尝试 checkstyle http://checkstyle.sourceforge.net/cmdline.html。我不确定它是否适用于 html。然而,对于java来说它就像一个魅力,你还可以添加可定制的规则。

You can try checkstyle http://checkstyle.sourceforge.net/cmdline.html. I am not sure if it would work for html. However, for java it works like a charm and you can also add customizable rules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文