mirror of
https://github.com/mrclay/minify.git
synced 2025-08-18 03:41:35 +02:00
Merge pull request #48 from glensc/script-clean-comments
add jsCleanComments option to Minify_HTML
This commit is contained in:
@@ -17,6 +17,10 @@
|
|||||||
* @author Stephen Clay <steve@mrclay.org>
|
* @author Stephen Clay <steve@mrclay.org>
|
||||||
*/
|
*/
|
||||||
class Minify_HTML {
|
class Minify_HTML {
|
||||||
|
/**
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $_jsCleanComments = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Minify" an HTML page
|
* "Minify" an HTML page
|
||||||
@@ -37,7 +41,7 @@ class Minify_HTML {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function minify($html, $options = array()) {
|
public static function minify($html, $options = array()) {
|
||||||
$min = new Minify_HTML($html, $options);
|
$min = new self($html, $options);
|
||||||
return $min->process();
|
return $min->process();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +59,8 @@ class Minify_HTML {
|
|||||||
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
* 'jsMinifier' : (optional) callback function to process content of SCRIPT
|
||||||
* elements. Note: the type attribute is ignored.
|
* elements. Note: the type attribute is ignored.
|
||||||
*
|
*
|
||||||
|
* 'jsCleanComments' : (optional) whether to remove HTML comments beginning and end of script block
|
||||||
|
*
|
||||||
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
* 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
|
||||||
* unset, minify will sniff for an XHTML doctype.
|
* unset, minify will sniff for an XHTML doctype.
|
||||||
*
|
*
|
||||||
@@ -72,6 +78,9 @@ class Minify_HTML {
|
|||||||
if (isset($options['jsMinifier'])) {
|
if (isset($options['jsMinifier'])) {
|
||||||
$this->_jsMinifier = $options['jsMinifier'];
|
$this->_jsMinifier = $options['jsMinifier'];
|
||||||
}
|
}
|
||||||
|
if (isset($options['jsCleanComments'])) {
|
||||||
|
$this->_jsCleanComments = (bool)$options['jsCleanComments'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +224,9 @@ class Minify_HTML {
|
|||||||
$ws2 = ($m[4] === '') ? '' : ' ';
|
$ws2 = ($m[4] === '') ? '' : ' ';
|
||||||
|
|
||||||
// remove HTML comments (and ending "//" if present)
|
// remove HTML comments (and ending "//" if present)
|
||||||
|
if ($this->_jsCleanComments) {
|
||||||
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
$js = preg_replace('/(?:^\\s*<!--\\s*|\\s*(?:\\/\\/)?\\s*-->\\s*$)/', '', $js);
|
||||||
|
}
|
||||||
|
|
||||||
// remove CDATA section markers
|
// remove CDATA section markers
|
||||||
$js = $this->_removeCdata($js);
|
$js = $this->_removeCdata($js);
|
||||||
|
Reference in New Issue
Block a user