1

Topic: Remove font-family from style attribute

Hi,

Some users of our application are pasting content from word into TinyMCE. So, it can be the case that there are various definitions
of the font-family attribute, like style="font-family:XYZ", style='font-family:XYZ;', and some others mixed up in a different way.
This makes it somewhat hard to use a regex to remove the font-family definition what we want to do.

So, i thought about using the invalid_elements option of Tiny, but I could not get it to work. Is it possible with it to remove
attribute values, like font-family of the style attribute?

Anyone who knows how to deal with this problem?

2

Re: Remove font-family from style attribute

You could do your regexp in the paste preprocess event.

3

Re: Remove font-family from style attribute

Thx for the hint, I will do that!

4

Re: Remove font-family from style attribute

Could you please maybe share your solution to this? I am not skilled in regexp, could you send here your postprocess code? I don't like font-family also that a user pastes from word but I have found no way to clean it :-(

5

Re: Remove font-family from style attribute

jerry2 wrote:

I am not skilled in regexp

The perfect reason to change that: regular-expressions.info

Greetings from Germany,

Felix Riesterer.
(-> about me and this forum <-)

6

Re: Remove font-family from style attribute

Use the undocumented valid_styles option. I didn't realize that we didn't document it will try to find time to do so. It's basically a comma separated list of valid style names.

Best regards,
Spocke - Main developer of TinyMCE

7

Re: Remove font-family from style attribute

I've tried to get valid_styles to work and keep getting this error: Invalid option valid_styles passed to tinymce

Can you give an example of how valid_styles is used?
I'm using version 3.3.6


        tinyMCE.init({
        content_css : '/stylesheets/compiled/tiny_mce.css',
        editor_selector : 'mceEditor',
        force_p_newlines : false,
        handle_node_change_callback : 'nodeChangeHandler',
        inline_styles : true,
        language : 'en',
        mode : 'none',
        plugins : "safari,autoresize,spellchecker,preelementfix",
        valid_styles : 'text-align',
        setup : 'setupEditor',
        spellchecker_rpc_url : '/blocks/spellchecker',
        theme : 'advanced',
        theme_advanced_buttons1 : "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,spellchecker,separator,code",
        theme_advanced_buttons2 : '',
        theme_advanced_buttons3 : '',
        theme_advanced_toolbar_location : 'external'
       
        });
        $(document).ready(function() {
          tinyMCE.execCommand("mceAddControl",true,"block_body");
        });

8

Re: Remove font-family from style attribute

tried to make this work but not success ..

            valid_styles : 'text-align,color,font-size',

no document for this if searching ..
please give some eg ..

9

Re: Remove font-family from style attribute

for temp: i using serverside php to clean up
============

function cleantxt($string){
    // remove unwanted style propeties     
    $except = array('color','text-align','font-size','height','width'); // declare your exceptions
    $allow = implode($except, '|');
    $regexp = '@([^;"]+)?(?<!'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';
    //$string = preg_replace($regexp, '', $string);
    //$string = preg_replace('@[a-z]*=""@is', '', $string); // remove any unwanted style attributes 
    $regexp = '@([^;"]+)?(?<!'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';//this line should be replaced with other gibberish that excludes certain strings of 4 characters...
    $string = preg_replace($regexp, '', $string); 
    // remove unwanted style propeties end
    $string = str_replace ( ' style=""', '', $string );
    return $string;
}

========

Last edited by binhaus (2010-10-16 06:29:48)

10

Re: Remove font-family from style attribute

Right syntax for valid styles is:

valid_styles : { '*' : 'color,font-size,font-weight,font-style,text-decoration' }

Put this in your config file. Woking on TinxMCE 3.3.9.2.

11

Re: Remove font-family from style attribute

The following seems to have issues when using ":" in the text. Im attempting to work through a solution but if anyone else can point out a way to ignore them in the content?

binhaus wrote:

for temp: i using serverside php to clean up
============

function cleantxt($string){
    // remove unwanted style propeties     
    $except = array('color','text-align','font-size','height','width'); // declare your exceptions
    $allow = implode($except, '|');
    $regexp = '@([^;"]+)?(?<!'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';
    //$string = preg_replace($regexp, '', $string);
    //$string = preg_replace('@[a-z]*=""@is', '', $string); // remove any unwanted style attributes 
    $regexp = '@([^;"]+)?(?<!'.$allow.'):(?!\/\/(.+?)\/)((.*?)[^;"]+)(;)?@is';//this line should be replaced with other gibberish that excludes certain strings of 4 characters...
    $string = preg_replace($regexp, '', $string); 
    // remove unwanted style propeties end
    $string = str_replace ( ' style=""', '', $string );
    return $string;
}

========