//***** LargeEdit Scripting *****
//
// Title: HTML Style Sections to Inline Style Tags
// Author: Tim O'Brien
// Date: May 8, 2008
// Purpose: Performs a JScript regular expression search on the HTML document for
// style attributes and replace class references.
//
//*******************************
function Run() {
var scanlines= "(.+)\\s\\x7b([^\\x7d]*)";
var scansection="<(style).+>(.+)[^\/\1]*"
LargeEdit.ResultLog(' HTML Style Section to Inline Style Tags (Start)');
var styletext;
var inpStr = LargeEdit.CurrentFile.Text;
var newtext = inpStr;
//Update InpStr to only Style Sections
var arrStyle;
var oReSections;
var oRe;
oReSections = new RegExp(scansection, "gmi");
var retStr;
var objtag;
var objval;
var classidx;
var classname;
while ((arrStyle = oReSections.exec(inpStr)) != null) {
styletext = arrStyle[0];
// Get the Matches collection
oRe = new RegExp(scanlines, "gmi");
retStr = '';
objtag = '';
objval = '';
classidx = -1;
classname = '';
while ((arr = oRe.exec(styletext)) != null) {
//retStr = arr[1] + ' = ' + arr[2];
objtag = arr[1];
objval = arr[2];
//LargeEdit.ResultLog(retStr);
//Do Replacement of class ids
classidx = objtag.indexOf(".");
if (classidx >= 0) {
classname = objtag.substr(classidx+1);
LargeEdit.ResultLog('Class Tab Found: ' + classname);
newtext = newtext.rep('class="' + classname + '"', 'style="' + objval.trim() + '"');
}
}
} //Each Style Section
LargeEdit.New();
LargeEdit.CurrentFile.Text = newtext;
LargeEdit.ResultLog(' HTML Style Section to Inline Style Tags (Finish)');
}
function StringReplace(findstr, replacestr) {
var regEx, strout;
regEx = new RegExp(findstr, "igm");
strout = this.replace(regEx, replacestr);
return strout;
}
String.prototype.rep = StringReplace;
function StringTrim()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.trim = StringTrim;
//copyright 2008 All rights reserved
Friday, May 9, 2008
HTML Style Sections to Inline Style Tags
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment