I know some people on this list have mentioned the need for XHTML valid code from WYSIWYG editors like SoEditor and Activedit... usually for government contracts etc.
 
Obviously it's damn near impossible to find anything on the MM exchange, which in some respects is a blessing, since there's quite a lot of crap on there anyway. If you still need this, I've written a fairly basic UDF which runs through the tags and sets all the non-quoted code to lower case. This is the first version of the function, so there may be bugs etc.
 
Feel free to use it, or hack it to pieces. But if you do make any modifications or find bugs, let me know what they are and I'll add them to the pot.
 
Cheers
Taz
 
 
 
<cfscript>
 // ***************
 // ValidXHTML - Written By Taz on the back of a beer mat
 // Parses html input from a WYSIWYG editor and validates as xhtml (lowercase tags)
 // Note: tag attribute values must be in double quotes
 // Use it as much as you like, but let me know if you find any bugs or add
 //  functionality via the contact form on www.tazmedia.co.uk
 // ***************
 
 function ValidXHTML(myString) {
  // initialise the start tag index
  startIndex = 1;
  
  while (startIndex LTE Len(myString)) {
   // get the index of the next tag opening and closing angle bracket
   openTag = Find("<", myString, startIndex);
   closeTag = Find(">", myString, openTag) + 1;
   // grab that tag
   myTag = Mid(myString, openTag, closeTag-openTag);
   
   // if there are upper case letters, process case converter
   if (REFind("[A-Z]", MyTag, 1)) {   
    // initialise start sub tag index
    startSubIndex = 1;
    myLCaseTag = myTag;
    
    while (startSubIndex LT Len(myLCaseTag)) {
     if (Find('"', myLCaseTag, startSubIndex)) {
      endSubindex = Find('"', myLCaseTag, startSubIndex);
      // grab start, current part and end as individual sub strings
      if (startSubIndex GT 1) {
       tagHead = Left(myLCaseTag, startSubIndex-1);
      } else {
       tagHead = "";
      }
      mySubStr = Mid(myLCaseTag, startSubIndex, endSubIndex-startSubIndex);      
      tagTail = Right(myLCaseTag, Len(myLCaseTag)-endSubindex + 1);
      
      // rebuild the tag with lowercase letters
      myLCaseTag = tagHead&LCase(mySubStr)&tagTail;
      startSubIndex = Find('"', myTag, endSubIndex+1) + 1;
     } else {
      myLCaseTag = LCase(myTag);
      startSubIndex = Len(myLCaseTag) + 1;
     }
    }    
    // Now replace all instances of this tag in the string
    myString = Replace(myString, myTag, myLCaseTag, 'all');
   }
   // Set start index past current tag
   startIndex = closeTag;
  }
  return myString;
 }
</cfscript>

Reply via email to