component output = false { /********************************************************** * HTMLHelper.cfc Version 0.9.5: * A lambda function expressions delivering component that enables * basic HTML minifying and html encoding features for trusted HTML * For more information please visit: * https://github.com/andreasRu/htmlHelper or * https://www.rhein-berg-digital.de * License: MIT License * (c)2023 C. Andreas RĂ¼ger * https://github.com/andreasRu/ ************************************************************/ public function init() { local.service = { "version" : "0.9.5", "startTickCount": getTickCount(), "timerTickCount": getTickCount(), "debug" : false, "demarkerStart": "_1.", "demarkerEnd" : "_e2.", "debugResult" : function( htmlstring, label = "", regexForDump ) { // if set to debug force output! if( service.debug ) { if( !arguments.label=="result" ){ writeOutput( "
" & encodeForHTML( htmlstring ) & "
" );
}
},
"reduceArrayAndReplaceString": function( arrayWithElements, contentString, replaceWith ) {
replaceWith = arguments.replaceWith;
return arguments.arrayWithElements.reduce( function( acc, element, index, theArray ) {
return acc.replace( element, replaceWith );
}, arguments.contentString );
},
"stripMultlineComments": function( htmlcontent ) {
stringsToRemove = [];
result = arguments.htmlcontent;
service.debugResult( htmlstring = result, label = "stripMultlineComments", regexForDump = "(\s)+\/\*(.|\n)*?\*\/" );
stringsToRemove.append( result.reMatch( "(\s)+\/\*(.|\n)*?\*\/" ), true );
result = service.reduceArrayAndReplaceString( stringsToRemove, result, "" );
service.debugResult( htmlstring = result, label = "Result" );
return result;
},
"stripSingleLineComments": function( htmlcontent ) {
stringsToRemove = [];
result = arguments.htmlcontent;
service.debugResult( htmlstring = result, label = "stripSingleLineComments", regexForDump = "(\s)+(?:\/\/)(.*?)[\r|\n]" );
stringsToRemove.append( result.reMatch( "(\s)+(?:\/\/)(.*?)[\r|\n]" ), true );
result = service.reduceArrayAndReplaceString( stringsToRemove, result, chr( 10 ) );
service.debugResult( htmlstring = result, label = "Result" );
return result;
},
"stripHtmlComments": function( htmlcontent ) {
stringsToRemove = [];
result = arguments.htmlcontent;
service.debugResult( htmlstring = result, label = "stripHtmlComments", regexForDump = "" );
stringsToRemove.append( result.reMatch( "" ), true );
result = service.reduceArrayAndReplaceString( stringsToRemove, result, "" );
service.debugResult( htmlstring = result, label = "Result" );
return result;
},
"compressBlankSpaces": function( htmlcontent ) {
stringsToRemove = [];
result = arguments.htmlcontent;
service.debugResult( htmlstring = result, label = "compressBlankSpaces", regexForDump = "[ \t]+" );
resure=result.reReplace( "[ \t]+", " ", "All" ).reReplace( "\s+[\n\r]+", chr( 10 ), "ALL" );
// stringsToRemove.append( result.reMatch( "[ \t]+" ), true ); // compress spaces/tabs to single spaces
// result = service.reduceArrayAndReplaceString( stringsToRemove, result, " " ).reReplace( "\s+[\n\r]+", chr( 10 ), "ALL" );
service.debugResult( htmlstring = result, label = "Result" );
return result;
},
"compressNewLines": function( htmlcontent, replaceWith ) {
stringsToRemove = [];
result = arguments.htmlcontent;
service.debugResult( htmlstring = result, label = "compressNewLines" );
stringsToRemove.append( result.reMatch( "[\s\n\r]+" ), true ); // compress spaces/tabs to single spaces
result = service.reduceArrayAndReplaceString( stringsToRemove, result, arguments.replaceWith );
service.debugResult( htmlstring = result, label = "Result" );
return result;
},
"stripEmptySpacesBetweenHtmlElements": function( htmlcontent, replaceWith ) {
stringsToRemove = [];
result = arguments.htmlcontent;
service.debugResult( htmlstring = result, label = "stripEmptySpacesBetweenHtmlElements" );
stringsToRemove.append( result.reMatch( ">\s+<" ), true ); // compress spaces/tabs to single spaces
result = service.reduceArrayAndReplaceString( stringsToRemove, result, arguments.replaceWith );
service.debugResult( htmlstring = result, label = "Result" );
return result;
},
"encodeTrustedHtml": function( required string htmlString ) {
stringsToMap = [];
unmapper = [ : ];
result = arguments.htmlString;
stringsToMap.append( result.reMatch( "(?i)(|