AnsweredAssumed Answered

Custom function to take away html code

Question asked by PeterMontague on May 25, 2013
Latest reply on Dec 12, 2013 by PeterMontague

Title

Custom function to take away html code

Post

     I'm using this custom function from Brian Dunning. I want to take away all html except for "</br>". I see that the function doesn't even have a reference to "</br>". Yet it took away all of my "</br>". 

      

     // Convert HTML text to text preserving bold and italic styles. Only HTML body text will be processed. Multiple spaces are removed
     // Version: 1.06.
     // Parameters: "text" = HTML text to be converted. "returns" = [ "single" ; "double" ] if no empty lines - or one empty line - are allowed.
     // NOTE 1: This version is only for use in FileMaker Pro 10 or higher.
     // NOTE 2: If you need to convert other HTML encodings like "&#230" -> "æ", you may add the needed substitution pairs in the "//Transform" section.
     // NOTE 3: Requires HTMLtoText_deleteTags ( text ) and HTMLtoText_convertStyle ( text )
     // 24oct06 ; Mogens Brun ; FM Integrator ; mogens_brun@mac.com
     // Mail to mogens_brun@mac.com if you want a demo file with the custom function and instructions for using the function in earlier versions than FileMaker 10.
      
     Let (
           [
     //Setup
           $Returns = If ( returns = "single" ; 1 ; 2 ) ;
           $Return1 = Left ( "¶¶" ; $Returns ) ;
           $Return2 = Left ( "¶¶¶" ; $Returns + 1 ) ;
           $Return3 = Left ( "¶¶¶¶" ; $Returns + 2 ) ;
           $Return4 = Left ( "¶¶¶¶¶¶" ; $Returns + 4 ) ;
           $Return5 = Left ( "¶¶¶¶¶¶¶¶¶¶" ; $Returns + 8 ) ;
     //Isolate body, remove comment lines (may contain characters given reason to unbalanced tags) and script and noscript lines
           $SearchStart = "<form " ;
           $SearchEnd = "</form>" ;
           $Text = HTMLtoText_deleteTags ( text ) ;
           $SearchStart = "<script" ;
           $SearchEnd = "</script>" ;
           $Text = HTMLtoText_deleteTags ( $Text ) ;
           $SearchStart = "<noscript" ;
           $SearchEnd = "</noscript>" ;
           $Text = HTMLtoText_deleteTags ( $Text ) ;
           $SearchStart = "<option" ;
           $SearchEnd = "</option>" ;
           $Text = HTMLtoText_deleteTags ( $Text ) ;
           $SearchStart = "<input " ;
           $SearchEnd = " />" ;
           $Text = HTMLtoText_deleteTags ( $Text ) ;
           $StartBody = Position ( $Text ; "<body" ; 1 ; 1 ) ;
           $SearchStart = "¶//" ;
           $SearchEnd = "¶" ;
           $Text = HTMLtoText_deleteTags ( Right ( $Text ; Length ( $Text ) - $StartBody + 1 ) ) ;
     //Convert bold style
           $SearchStart = "<b>" ;
           $SearchEnd = "</b>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
           $SearchStart = "<h1" ;
           $SearchEnd = "</h1>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
           $SearchStart = "<h2" ;
           $SearchEnd = "</h2>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
           $SearchStart = "<h3" ;
           $SearchEnd = "</h3>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
           $SearchStart = "<strong>" ;
           $SearchEnd = "</strong>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
     //Convert italic style
           $SearchStart = "<i>" ;
           $SearchEnd = "</i>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
           $SearchStart = "<em>" ;
           $SearchEnd = "</em>" ;
           $Text = HTMLtoText_convertStyle ( $Text ) ;
     //Delete HTML tags and convert special characters
           $SearchStart = "<" ;
           $SearchEnd = ">" ;
           $Text = HTMLtoText_deleteTags ( Substitute ( $Text ; 
     //Blank
        [ "¶" ; "" ] ;
        [ "</li>" ; "" ] ;
        [ "<tr>" ; "¶" ] ;
        [ "</tr>" ; "" ] ;
        [ "</a>" ; "" ] ;
        [ "</td>" ; "" ] ;
        [ "&middot;" ; "" ] ;
        [ "<td>" ; "" ] ; 
        [ "’" ; "'" ] ; 
        [ Char ( 10 ) ; "" ] ;
        [ Char ( 65533 ) ; "" ] ;
        [ Char ( 0 ) ; "" ] ;
     //Space
        [ "</div>" ; " </div>" ] ;
        [ "</option>" ; " </option>" ] ;
        [ "<a href" ; " <a href" ] ;
        [ "</span>" ; " " ] ;
        [ "|" ; " | " ] ;
     // Transform
        [ "<td>" ; Char ( 9 ) ] ;
        [ " " ; " " ] ; //non-breaking space
        [ "<li>" ; "¶• " ] ;
        [ "<li " ; "¶• <li " ] ;
        [ "</p>" ; "¶¶" ] ;
        [ "<p>" ; "¶¶" ] ;
        [ "<p " ; "¶¶<p " ] ;
        [ "<br>" ; "¶" ] ;
        [ "<br />" ; "¶" ] ;
        [ "<tr " ; "¶<tr " ] ;
        [ "<ul>" ; "¶¶" ] ;
        [ "</ul>" ; "¶¶" ] ;
        [ "</table>" ; "¶¶" ] ;
        [ "&amp;" ; "&" ] ;
        [ "&hellip;" ; "…" ] ;
        [ "&quot;" ; "\"" ] ;
        [ "&8220;" ; "\“" ] ;
        [ "&8221;" ; "\”" ] ;
        [ "&#174;" ; "®" ] ;
        [ "&copy;" ; "®" ] ;
        [ "&ldquo;" ; "\“" ] ;
        [ "&rdquo;" ; "\”" ] ;
        [ "&raquo;" ; "»" ] ;
        [ "&laquo;" ; "«" ] ;
        [ "&gt;" ; ">" ] ;
        [ "&lt;" ; "<" ] ;
        [ "&#8217;" ; "'" ] ;
        [ "&#8482;" ; "™" ] ;
        [ "&#194;" ; "Å" ] ;
        [ "&#196;" ; "Ä" ] ;
        [ "&#198;" ; "Æ" ] ;
        [ "&#201;" ; "É" ] ;
        [ "&#214;" ; "Ö" ] ;
        [ "&#216;" ; "Ø" ] ;
        [ "&#220;" ; "Ü" ] ;
        [ "&#228;" ; "ä" ] ;
        [ "&#229;" ; "å" ] ;
        [ "&#230;" ; "æ" ] ;
        [ "&#233;" ; "é" ] ;
        [ "&#246;" ; "ö" ] ;
        [ "&#248;" ; "ø" ] ;
        [ "&#252;" ; "ü" ] ;
     //Clean space & tab & return
        [ " " ; " " ] ;
        [ "         " ; " " ] ;
        [ "     " ; " " ] ;
        [ "   " ; " " ] ;
        [ "  " ; " " ] ;
        [ "> <" ; "" ] ;
        [ "><" ; "" ] ;
        [ " ¶" ; "¶" ] ;
        [ "¶ " ; "¶" ]            ) )
           ;
           $SearchStart = "&#" ;
           $SearchEnd = ";"
           ] ;
           Substitute ( "Ÿ" & HTMLtoText_deleteTags ( $Text ) & "Ÿ"  ;
     //Clean successive returns
        [ $Return5 ; $Return1 ] ;
        [ $Return4 ; $Return1 ] ;
        [ $Return3 ; $Return1 ] ;
        [ $Return2 ; $Return1 ] ;
     //Trim for returns at start and end
        [ "Ÿ¶¶" ; "" ] ;
        [ "Ÿ¶" ; "" ] ;
        [ "¶¶Ÿ" ; "" ] ;
        [ "¶Ÿ" ; "" ] ;
        [ "Ÿ" ; "" ]
      )
     )

Outcomes