Brian Dunning's FileMaker Custom Functions

CSStoFMText ( text )

Converts CSS inline styles to FileMaker Pro Text

  Average rating: 4.4 (41 votes) Log in to vote

Christopher Gauntt   Christopher Gauntt
Cordega Solutions
http://www.cordega.com

Share on Facebook Share on Twitter

  Sample input:
Let's see how it converts back.
  Sample output:
LET'S SEE HOW IT CONVERTS BACK.

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

This takes CSS styled text and converts it back to FileMaker Pro formatting.
The Hex to RGB converter calc was supplied by Klemens Müller, www.klemenso.de, 05.07.2006

Note: I don't have the fontScript variable figured out yet. I couldn't find anything in CSS documentation that seemed equivalent. But the variable is there in case someone else figures it out.

UPDATE: April 6, 2009
Added If statement to wrap around function in case text doesn't have any SPAN tags.

Note, if you not converting a field directly, don't forget to put the \ before the quote if you are embedding the tags into a calculation.

 

Comments

David Wikström   David Wikström, Vancouver, BC
Aug 24, 2009
This is a great custom function. However, when I copy-paste it, I get an error message saying "too many parameters...".
There's also a typo on the name of the function - the comment says CSStoFMText but the recursive call uses cscf_CSStoFMText.

I got the cf to work by adding an extra end-parenthesis just before the comment

// converts the text string between the span tags into the filemaker conversions from the above
 
Christopher Gauntt   Christopher Gauntt, North Hollywood
May 15, 2010
I finally got around to fixing it. Sorry for the ridiculously long delay. I didn't even know there was a problem until one of my colleagues found the function and the comment.
 
Peter F.   Peter F., Zurich
Dec 31, 2010
I convert GetAsCSS(field) back
I needed an additional Substitute(field," ¶","") . (that's substitute space newline with empty)

Thank you for the very helpful function CSSToFMText and Happy New Year 2011.
 
Mike   Mike, Taipei
Jan 19, 2011
Nice little function. Ive been working on building text editor functions into a FM database am trying to find a slick way to get formatted text into a MS word document. This kind of thing is helpful and may form part of the solution

One small bug:

"Strikethrough" is "Line-through" in CSS land.

Also It doesn't handle chinese characters. A must in this corner of the world.

Mike
 
Peter van Herk   Peter van Herk, Brisbane, Australia
Jul 16, 2015
I had to add the following for it to successfully render the line breaks.

Key changes are lower case line break and added extra substitute for <br/>

Here is the change and addition. Works just fine now in FM14 and thanks heaps.

// swaps out breaks with FileMaker return markers
; $_Text = Substitute ( $_TextSpan ; "<br>" ; "¶" )
; $_Text = Substitute ( $_TextSpan ; "<br/>" ; "¶" )
 
Alec   Alec, Brooklyn
Dec 1, 2016
Regarding your comment, Peter. The Substitute function is case sensitive and there is sometimes a space before the forward slash. So the full list should be:

// swaps out breaks with FileMaker return markers
; $_Text = Substitute ( $_TextSpan ; "<br>" ; "¶" )
; $_Text = Substitute ( $_TextSpan ; "<br/>" ; "¶" )
; $_Text = Substitute ( $_TextSpan ; "<br />" ; "¶" )
; $_Text = Substitute ( $_TextSpan ; "<BR>" ; "¶" )
; $_Text = Substitute ( $_TextSpan ; "<BR/>" ; "¶" )
; $_Text = Substitute ( $_TextSpan ; "<BR />" ; "¶" )

Or, the nested version:

$_Text =
Substitute (
$_TextSpan;
[ "<br>" ; "¶" ];
[ "<br/>" ; "¶" ];
[ "<br />" ; "¶" ];
[ "<BR>" ; "¶" ];
[ "<BR/>" ; "¶" ];
[ "<BR />" ; "¶" ];
)

Same goes for the Substitute function at the top as well.
 

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.