将HTML最小化为一行

时间:2013-02-17 16:30:43

标签: html compression

我需要将此代码最小化为一行。

我正在使用Adobe Edge,并在一个文本框中为某些段落创建了一些代码。如果您感兴趣的代码需要加载到名为document.compositionReady的区域。

最大的限制是通过javascript加载代码的方式不允许使用多行。

所以我已经手动完成了它并没有问题,它工作正常,但需要很长时间。我可以使用Aptana studio和format命令将代码解压缩回正常,问题是在开发期间我不断地将这些代码手动压缩成一行,这既耗时又分散注意力。

所以我需要一个手动工具来解决这个问题:

<style media='screen' type='text/css'>
    .text {
        padding: 1px 1px 1px 1px;
        font-size: 12px;
    }
</style>

<!-- now for html -->

<div style='width:550px;' >
    <div style='float:left;font-size:1.2em;' class='text'>
        Title goes here
    </div>
    <div style='width:60px;float:left;' class='text'>
        <span style='font-size:0.8em;'>
            ®
        </span>
    </div>
    <div style='float:left' class='text'>
        Some paragraph text
    </div>
    <div style='float:left;padding-top:10px;' class='text'>
        <span style='font-style:italic;'>
            A footer to the paragraph
        </span>
    </div>
</div>

进入这个:

<style media='screen' type='text/css'>.text {padding: 1px 1px 1px 1px;font-size:12px;}</style><!-- now for html --><div style='width:550px;' >  <div style='float:left;font-size:1.2em;' class='text'>MY BRILLIANCE</div><div style='width:60px;float:left;' class='text'>      <span style='font-size:0.8em;'>®</span> </div>  <div style='float:left' class='text'>       With release comes growth, through challenge comes wisdom, let us show you the way. </div>  <div style='float:left;padding-top:10px;' class='text'><span style='font-style:italic;'>Absolute Equal Acceptance through Thought, Conscience and Reunion.</span></div></div>

2 个答案:

答案 0 :(得分:4)

好吧,谷歌可能是你的朋友。

http://www.textfixer.com/html/compress-html-compression.php

<style media='screen' type='text/css'>
    .text {
        padding: 1px 1px 1px 1px;
        font-size: 12px;
    }
</style>

<!-- now for html -->

<div style='width:550px;' >
    <div style='float:left;font-size:1.2em;' class='text'>
        Title goes here
    </div>
    <div style='width:60px;float:left;' class='text'>
        <span style='font-size:0.8em;'>
            ®
        </span>
    </div>
    <div style='float:left' class='text'>
        Some paragraph text
    </div>
    <div style='float:left;padding-top:10px;' class='text'>
        <span style='font-style:italic;'>
            A footer to the paragraph
        </span>
    </div>
</div>

变为

<style media='screen' type='text/css'> .text { padding: 1px 1px 1px 1px; font-size: 12px; }</style><!-- now for html --><div style='width:550px;' > <div style='float:left;font-size:1.2em;' class='text'> Title goes here </div> <div style='width:60px;float:left;' class='text'> <span style='font-size:0.8em;'> ® </span> </div> <div style='float:left' class='text'> Some paragraph text </div> <div style='float:left;padding-top:10px;' class='text'> <span style='font-style:italic;'> A footer to the paragraph </span> </div></div>

或者,如果您想直接在桌面上压缩,可以使用AlentumHTML Compressor等软件......

答案 1 :(得分:-1)

类似于str_replace("\n", "", $text_to_be_compressed)