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 (59 votes) Log in to vote

Mogens Brun   Mogens Brun - Show more from this author
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, Michael Kupietz FileMaker Consulting
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.
 
hollyheadhunter   hollyheadhunter
Oct 20, 2019
This is really helpful. We seem to have a lot of messages (via Gmail) that contain something like:




That HTML makes a line break but the function seems to remove the line break. What would be the best way to adjust things to let it remain a line break, regardless of specific font size?
 
hollyheadhunter   hollyheadhunter
Oct 25, 2019
This is really helpful. We seem to have a lot of messages (via Gmail) that contain something like:

< br style="font-size:12.8px" >

That HTML makes a needed line break but the function seems to remove the line break. What would be the best way to adjust things to let it remain a line break, regardless of specific font size?
 
Stam Kapetanakis   Stam Kapetanakis
Jun 12, 2020
very nice - some minor issues (for me   isn't substituted; strange as it's a common tag, but easy to work around) -- thank you.
 
mamourmb   mamourmb, FMH
Mar 21, 2022
Hi all.
Thanks to Morgens,
The CF doesn't take into account ordered lists and indents.
Do you have an updated version or help me with these issues.
Kind regards and thanks, in advance
Mamour
 

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.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: