public void testCompress() { var source = Resources.testCompress; var result = Resources.testCompressResult; var compressor = new HtmlCompressor(); var compress = compressor.compress(source); Assert.Equal(result, compress); }
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); }
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); }
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); }
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); }
/// <summary> /// Removes unnecessary whitespace and markup from HTML documents. /// </summary> /// <param name="removeComments">Removes comments</param> /// <param name="removeMultiSpaces">Removes multiple spaces</param> /// <param name="removeLineBreaks">Removes linebreaks</param> /// <param name="removeIntertagSpaces">Removes spaces between tags</param> /// <param name="removeQuotes">Remove unneeded quotes</param> /// <param name="simpleDoctype">Change doctype to <!DOCTYPE html></param> /// <param name="removeStyleAttributes">Remove TYPE attribute from STYLE tags</param> /// <param name="removeLinkAttributes">Remove TYPE attribute from LINK tags</param> /// <param name="removeScriptAttributes">Remove TYPE and LANGUAGE from SCRIPT tags</param> /// <param name="removeFormAttributes">Remove METHOD="GET" from FORM tags</param> /// <param name="removeInputAttribtues">Remove TYPE="TEXT" from INPUT tags</param> /// <param name="simpleBooleanAttributes">Remove values from boolean tag attributes</param> /// <param name="removeJavaScriptProtocol">Remove "javascript:" from inline event handlers</param> /// <param name="removeHttpProtocol">Remove "http:" from tag attributes</param> /// <param name="removeHttpsProtocol">Remove "https:" from tag attributes</param> /// <param name="removeSurroundingSpacesTags">Predefined or custom comma separated list of tags [min|max|all|custom_list]</param> public PvcHtmlCompressor( bool concurrent = true, bool removeComments = true, bool removeMultiSpaces = true, bool removeLineBreaks = true, bool removeIntertagSpaces = false, bool removeQuotes = false, bool simpleDoctype = false, bool removeStyleAttributes = false, bool removeLinkAttributes = false, bool removeScriptAttributes = false, bool removeFormAttributes = false, bool removeInputAttributes = false, bool simpleBooleanAttributes = false, bool removeJavaScriptProtocol = false, bool removeHttpProtocol = false, bool removeHttpsProtocol = false, string removeSurroundingSpacesTags = "" ) { this.compressor = new HtmlCompressor(); this.concurrent = concurrent; compressor.setRemoveComments(removeComments); compressor.setRemoveMultiSpaces(removeMultiSpaces); compressor.setPreserveLineBreaks(!removeLineBreaks); compressor.setRemoveIntertagSpaces(removeIntertagSpaces); compressor.setRemoveQuotes(removeQuotes); compressor.setSimpleDoctype(simpleDoctype); compressor.setRemoveStyleAttributes(removeStyleAttributes); compressor.setRemoveLinkAttributes(removeLinkAttributes); compressor.setRemoveScriptAttributes(removeScriptAttributes); compressor.setRemoveFormAttributes(removeFormAttributes); compressor.setRemoveInputAttributes(removeInputAttributes); compressor.setSimpleBooleanAttributes(simpleBooleanAttributes); compressor.setRemoveJavaScriptProtocol(removeJavaScriptProtocol); compressor.setRemoveHttpProtocol(removeHttpProtocol); compressor.setRemoveHttpsProtocol(removeHttpsProtocol); compressor.setRemoveSurroundingSpaces(removeSurroundingSpacesTags); }
private HtmlCompressor createCompressorClone() { var clone = new HtmlCompressor(); clone.setJavaScriptCompressor(javaScriptCompressor); clone.setCssCompressor(cssCompressor); clone.setRemoveComments(_removeComments); clone.setRemoveMultiSpaces(_removeMultiSpaces); clone.setRemoveIntertagSpaces(_removeIntertagSpaces); clone.setRemoveQuotes(_removeQuotes); clone.setCompressJavaScript(_compressJavaScript); clone.setCompressCss(_compressCss); clone.setSimpleDoctype(_simpleDoctype); clone.setRemoveScriptAttributes(_removeScriptAttributes); clone.setRemoveStyleAttributes(_removeStyleAttributes); clone.setRemoveLinkAttributes(_removeLinkAttributes); clone.setRemoveFormAttributes(_removeFormAttributes); clone.setRemoveInputAttributes(_removeInputAttributes); clone.setSimpleBooleanAttributes(_simpleBooleanAttributes); clone.setRemoveJavaScriptProtocol(_removeJavaScriptProtocol); clone.setRemoveHttpProtocol(_removeHttpProtocol); clone.setRemoveHttpsProtocol(_removeHttpsProtocol); clone.setPreservePatterns(preservePatterns); //clone.setYuiJsNoMunge(yuiJsNoMunge); //clone.setYuiJsPreserveAllSemiColons(yuiJsPreserveAllSemiColons); //clone.setYuiJsDisableOptimizations(yuiJsDisableOptimizations); //clone.setYuiJsLineBreak(yuiJsLineBreak); //clone.setYuiCssLineBreak(yuiCssLineBreak); //clone.setYuiErrorReporter(yuiErrorReporter); return clone; }
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); }
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); }
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); }
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); }
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); }
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); }