Joseph DeVore's Blog: Parsing styles recursively with ColdFusion


Viewing By Entry / Main
September 1, 2005
Looking to consolidate inline <style>'s into external stylesheets? This code will build an array of all of the CSS between <style> tags. The only thing missing from a complete solution is a recursive file loader/reader.

<cfscript>
// create array to store styles
styles=arrayNew(1);

// regular expression
re="<style>([^<]*)</style>";
// parse first result
results=reFindNoCase(re, trim(htmlToParse), 1, 1);

// loop over RE parsed results recursively
while(results.pos[1]) {
 // append style to styles array
 arrayAppend(styles, trim(mid(trim(htmlToParse), results.pos[2], results.len[2])) );

 // parse next style
 results=reFindNoCase(re, trim(htmlToParse), results.pos[2] + results.len[2],1);
}
</cfscript>

Comments

Comments are not allowed for this entry.













Editor Login ›