Brian Dunning's FileMaker Custom Functions

HTMLtoText ( text ; returns )

Convert HTML text to text preserving bold and italic styles (v. 1.04).

  Average rating: 3.7 (57 votes) Log in to vote

Mogens Brun   Mogens Brun
FM Integrator
http://filemakerintegrator.dk

Share on Facebook Share on Twitter

  Sample input:
HTMLtoText ( "

Product Description:


Over 50 Conversions Very Quick
Copy With click of 1 button

What's new in this version:

" ; "single" )
  Sample output:

Product Description:

Over 50 Conversions Very Quick
Copy With click of 1 button

What's new in this version:

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Together with two subordinate custom functions "HTMLtoText_deleteTags" and "HTMLtoText_convertStyle" (also found on this site) this function will parseHTML text to plain text with preservation of any italic or bold markup in the HTML text. Several pages of text may be converted with reasonable text formating. The HTML text could be imported in a field by Troi URL plug-in, Fusion TCPdirect plug-in or by FileMaker GetLayoutObjectAttribute ( "WebViewerName" ; "content" ).

The second parameter (returns) controls if no empty lines should be allowed ( returns = "single") or one empty line may be allowed between paragraphs (returns = "double") with "double" as default.

Note: Requires FileMaker 10 or higher - unless 3 special char-values are stored in global fields.

 

Comments

Dennis Burnham   Dennis Burnham, Dallas, TX
Aug 10, 2010
There is an error in this function; it can't be pasted into Custom Functions without a FM error message about bad punctuation or a missing text constant or field name.
 
Mogens Brun   Mogens Brun, Gentofte, Denmark
Aug 11, 2010
I did not escape the "&" char with "&" when I pasted the function to this site, so therefor there were several errors in the substitute section. This has now been corrected.
 
Dennis Burnham   Dennis Burnham, Dallas, TX
Aug 5, 2011
Is there a comparable function that will translate text to HTML?
 
Peter   Peter, Dublin, Ireland
May 25, 2013
I'd like to leave "</br>" in my text but get rid of all of the rest of the text. How can I alter this custom function to do this. I see no reference to "</br>" in the custom function. But when I tried it out it took away all "</br>"
 
Michael Kupietz   Michael Kupietz, Internet
Mar 23, 2014
Peter, just perform two substitutions to encode and decode the </BR>s as follows:

Substitute(
HTMLtoText (
substitute(text;
"</br>";
"LongArbitraryStringThatIsNotLikelyToEverTurnUpInText24681357AAZ"
) ;
returns );
"LongArbitraryStringThatIsNotLikelyToEverTurnUpInText24681357AAZ";
"</br>"
)
 
Peter   Peter, Internet
Jun 10, 2014
Hello,

i would like to have to output of the field into DB readable format like

"field1-1.row", "field2-1.row", "field3-1.row"
"field1-2.row", "field2-2.row", "field3-2.row"

any ideas?
 
Alastair   Alastair, Edinburgh
Feb 10, 2015
I've copied and pasted all three functions so I think they're accurate but the function is converting both <i> and <b> tags to bold.

I'm seriously impressed with the rest, though!

Any ideas what I might have done wrong?

Thanks.
 
Alastair   Alastair, Edinburgh
Feb 10, 2015
I answered my own question by adding a parameter, StyleToAdd to the HTMLtoText_convertStyle function and then using the parameter instead of 'Bold' in the second bottom line.

Then I added either 'Bold' or 'Italic' (without apostrophes) to the relevant lines of this function.

Thanks again.
 
Holly Headhunter   Holly Headhunter, Nashville TN
Sep 23, 2016
Very helpful custom function - have been using it for a few years. Getting one unexpected result; any ideas?

This HTML:

From: <b class="gmail_sendername">John Doe</b> <span dir="ltr">&lt;<a href="mailto:jdoe@acme.com">jdoe@acme.com</a>&gt;

Displays in a browser as:
From: John Doe <jdoe@acme.com>

But the custom function seems to delete the space and the less than symbol that proceeds the email address giving this result:

From: John Doejdoe@acme.com>
 
Tigrou83   Tigrou83, France
Aug 27, 2017
Really really marvelous. Thanks a lot !!! I added some special characters like "&mdash" or &rsquo; for example, that are not converted. Very nice result.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.