Java 如何将多行 html 代码转换为单行 html 代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18372807/
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-08-12 00:57:50  来源:igfitidea点击:

How to convert multiline html code to single line html code

javajavascripthtmlcss

提问by chakri

My code is test.html:

我的代码是 test.html:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

converting to

转换为

<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>

I am using manual converting , please tell me there is any online converter for converting multiline html code to single line html

我正在使用手动转换,请告诉我有任何在线转换器可以将多行 html 代码转换为单行 html

采纳答案by Mandeep Pasbola

Try this :

尝试这个 :

Minify HTML (or XHTML), and any CSS or JS included in your markup

缩小 HTML(或 XHTML),以及标记中包含的任何 CSS 或 JS

http://www.willpeavy.com/minifier/

http://www.willpeavy.com/minifier/

回答by Tushar Gupta - curioustushar

Check below good site

检查下面的好网站

minifier

压缩器

回答by user2706024

Here is a website that claims to do this..
http://www.odditysoftware.com/page-webtools16.htm

这是一个声称这样做的网站..
http://www.odditysoftware.com/page-webtools16.htm

回答by Yuvaraj P

use http://htmlcompressor.com/compressor/Click 'Show options' and check 'Single line html output'

使用http://htmlcompressor.com/compressor/单击“显示选项”并选中“单行 html 输出”

回答by newuser

Try to use StringUtils.chomp

尝试使用StringUtils.chomp

BufferedReader bufferedReader = new BufferedReader(new FileReader(FILE_NAME));
        String s = null;
        StringBuilder stringBuilder = new StringBuilder();
        while((s = bufferedReader.readLine()) != null)
        {
            stringBuilder.append(StringUtils.chomp(s));
        }

        System.out.println("stringBuilder : "+stringBuilder);

回答by shemy

you can use any of the following to do this:

您可以使用以下任何一种方法来执行此操作:

http://www.willpeavy.com/minifier/or http://www.iwebtool.com/html_optimizer

http://www.willpeavy.com/minifier/http://www.iwebtool.com/html_optimizer