require "yui/compressor"
module HtmlCompressor
class Compressor
JS_COMPRESSOR_YUI = "yui";
JS_COMPRESSOR_CLOSURE = "closure";
# Predefined pattern that matches <?php ... ?>
tags.
# Could be passed inside a list to {@link #setPreservePatterns(List) setPreservePatterns} method.
PHP_TAG_PATTERN = /<\?php.*?\?>/im
# Predefined pattern that matches <% ... %>
tags.
# Could be passed inside a list to {@link #setPreservePatterns(List) setPreservePatterns} method.
SERVER_SCRIPT_TAG_PATTERN = /<%.*?%>/m
# Predefined pattern that matches <--# ... -->
tags.
# Could be passed inside a list to {@link #setPreservePatterns(List) setPreservePatterns} method.
SERVER_SIDE_INCLUDE_PATTERN = //m
# Predefined list of tags that are very likely to be block-level.
#Could be passed to {@link #setRemoveSurroundingSpaces(String) setRemoveSurroundingSpaces} method.
BLOCK_TAGS_MIN = "html,head,body,br,p"
# Predefined list of tags that are block-level by default, excluding <div>
and <li>
tags.
#Table tags are also included.
#Could be passed to {@link #setRemoveSurroundingSpaces(String) setRemoveSurroundingSpaces} method.
BLOCK_TAGS_MAX = BLOCK_TAGS_MIN + ",h1,h2,h3,h4,h5,h6,blockquote,center,dl,fieldset,form,frame,frameset,hr,noframes,ol,table,tbody,tr,td,th,tfoot,thead,ul"
# Could be passed to {@link #setRemoveSurroundingSpaces(String) setRemoveSurroundingSpaces} method
# to remove all surrounding spaces (not recommended).
ALL_TAGS = "all"
# temp replacements for preserved blocks
TEMP_COND_COMMENT_BLOCK = "%%%~COMPRESS~COND~{0,number,#}~%%%"
TEMP_PRE_BLOCK = "%%%~COMPRESS~PRE~{0,number,#}~%%%"
TEMP_TEXT_AREA_BLOCK = "%%%~COMPRESS~TEXTAREA~{0,number,#}~%%%"
TEMP_SCRIPT_BLOCK = "%%%~COMPRESS~SCRIPT~{0,number,#}~%%%"
TEMP_STYLE_BLOCK = "%%%~COMPRESS~STYLE~{0,number,#}~%%%"
TEMP_EVENT_BLOCK = "%%%~COMPRESS~EVENT~{0,number,#}~%%%"
TEMP_LINE_BREAK_BLOCK = "%%%~COMPRESS~LT~{0,number,#}~%%%"
TEMP_SKIP_BLOCK = "%%%~COMPRESS~SKIP~{0,number,#}~%%%"
TEMP_USER_BLOCK = "%%%~COMPRESS~USER{0,number,#}~{1,number,#}~%%%"
# compiled regex patterns
EMPTY_PATTERN = Regexp.new("\\s")
SKIP_PATTERN = Regexp.new("(.*?)", Regexp::MULTILINE | Regexp::IGNORECASE)
COND_COMMENT_PATTERN = Regexp.new("()(.*?)()", Regexp::MULTILINE | Regexp::IGNORECASE)
COMMENT_PATTERN = Regexp.new("|", Regexp::MULTILINE | Regexp::IGNORECASE)
INTERTAG_PATTERN_TAG_TAG = Regexp.new(">\\s+<", Regexp::MULTILINE | Regexp::IGNORECASE)
INTERTAG_PATTERN_TAG_CUSTOM = Regexp.new(">\\s+%%%~", Regexp::MULTILINE | Regexp::IGNORECASE)
INTERTAG_PATTERN_CUSTOM_TAG = Regexp.new("~%%%\\s+<", Regexp::MULTILINE | Regexp::IGNORECASE)
INTERTAG_PATTERN_CUSTOM_CUSTOM = Regexp.new("~%%%\\s+%%%~", Regexp::MULTILINE | Regexp::IGNORECASE)
MULTISPACE_PATTERN = Regexp.new("\\s+", Regexp::MULTILINE | Regexp::IGNORECASE)
TAG_END_SPACE_PATTERN = Regexp.new("(<(?:[^>]+?))(?:\\s+?)(/?>)", Regexp::MULTILINE | Regexp::IGNORECASE)
TAG_LAST_UNQUOTED_VALUE_PATTERN = Regexp.new("=\\s*[a-z0-9\\-_]+$", Regexp::IGNORECASE)
TAG_QUOTE_PATTERN = Regexp.new("\\s*=\\s*([\"'])([a-z0-9\\-_]+?)\\1(/?)(?=[^<]*?>)", Regexp::IGNORECASE)
PRE_PATTERN = Regexp.new("(
]*?>)(.*?)()", Regexp::MULTILINE | Regexp::IGNORECASE) TA_PATTERN = Regexp.new("()", Regexp::MULTILINE | Regexp::IGNORECASE) SCRIPT_PATTERN = Regexp.new("()", Regexp::MULTILINE | Regexp::IGNORECASE) STYLE_PATTERN = Regexp.new("()", Regexp::MULTILINE | Regexp::IGNORECASE) TAG_PROPERTY_PATTERN = Regexp.new("(\\s\\w+)\\s*=\\s*(?=[^<]*?>)", Regexp::IGNORECASE) CDATA_PATTERN = Regexp.new("\\s*\\s*", Regexp::MULTILINE | Regexp::IGNORECASE) DOCTYPE_PATTERN = Regexp.new("]*>", Regexp::MULTILINE | Regexp::IGNORECASE) TYPE_ATTR_PATTERN = Regexp.new("type\\s*=\\s*([\\\"']*)(.+?)\\1", Regexp::MULTILINE | Regexp::IGNORECASE) JS_TYPE_ATTR_PATTERN = Regexp.new("(