compress() public method

public compress ( string html ) : string
html string
return string
コード例 #1
0
        public void testCompress()
        {
            var source = Resources.testCompress;
            var result = Resources.testCompressResult;

            var compressor = new HtmlCompressor();

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #2
0
        public void testPreserveLineBreaks()
        {
            var source = Resources.testPreserveLineBreaks;
            var result = Resources.testPreserveLineBreaksResult;

            var compressor = new HtmlCompressor();
            compressor.setPreserveLineBreaks(true);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #3
0
        public void testEnabled()
        {
            var source = Resources.testEnabled;
            var result = Resources.testEnabledResult;

            var compressor = new HtmlCompressor();
            compressor.setEnabled(false);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #4
0
        public void Test01()
        {
            var comp = new HtmlCompressor();

            var input = Resources.Html01;
            var output = comp.compress(input);

            Assert.NotEmpty(output);
            var ratio = Math.Round((double)output.Length / input.Length * 100.0, 2);
            Assert.True(ratio < 100.0);
        }
コード例 #5
0
        public void testPreservePatterns()
        {
            var source = Resources.testPreservePatterns;
            var result = Resources.testPreservePatternsResult;

            var preservePatterns = new List<Regex>();
            preservePatterns.Add(HtmlCompressor.PHP_TAG_PATTERN); //<?php ... ?> blocks
            preservePatterns.Add(HtmlCompressor.SERVER_SCRIPT_TAG_PATTERN); //<% ... %> blocks
            preservePatterns.Add(HtmlCompressor.SERVER_SIDE_INCLUDE_PATTERN); //<!--# ... --> blocks
            preservePatterns.Add(new Regex("<jsp:.*?>", RegexOptions.Singleline | RegexOptions.IgnoreCase)); //<jsp: ... > tags

            var compressor = new HtmlCompressor();
            compressor.setPreservePatterns(preservePatterns);
            compressor.setRemoveComments(true);
            compressor.setRemoveIntertagSpaces(true);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #6
0
        public void testRemoveComments()
        {
            var source = Resources.testRemoveComments;
            var result = Resources.testRemoveCommentsResult;

            var compressor = new HtmlCompressor();
            compressor.setRemoveComments(true);
            compressor.setRemoveIntertagSpaces(true);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #7
0
        public void testSurroundingSpaces()
        {
            var source = Resources.testSurroundingSpaces;
            var result = Resources.testSurroundingSpacesResult;

            var compressor = new HtmlCompressor();
            compressor.setRemoveIntertagSpaces(true);
            compressor.setRemoveSurroundingSpaces("p,br");

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #8
0
        public void testSimpleDoctype()
        {
            var source = Resources.testSimpleDoctype;
            var result = Resources.testSimpleDoctypeResult;

            var compressor = new HtmlCompressor();
            compressor.setSimpleDoctype(true);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #9
0
        public void testRemoveStyleAttributes()
        {
            var source = Resources.testRemoveStyleAttributes;
            var result = Resources.testRemoveStyleAttributesResult;

            var compressor = new HtmlCompressor();
            compressor.setRemoveStyleAttributes(true);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #10
0
        public void testRemoveSpacesInsideTags()
        {
            var source = Resources.testRemoveSpacesInsideTags;
            var result = Resources.testRemoveSpacesInsideTagsResult;

            var compressor = new HtmlCompressor();
            compressor.setRemoveMultiSpaces(false);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }
コード例 #11
0
        public void testRemoveJavaScriptProtocol()
        {
            var source = Resources.testRemoveJavaScriptProtocol;
            var result = Resources.testRemoveJavaScriptProtocolResult;

            var compressor = new HtmlCompressor();
            compressor.setRemoveJavaScriptProtocol(true);

            var compress = compressor.compress(source);
            Assert.Equal(result, compress);
        }