No filter of code on switch from html to visual editor, how?

[*]

Yes, i have found other questions to this topic, but no have the same topic exactly and no solution for my problem.

If you include code inside the html-tab and you switch to the visual mode, then format WP the code to a block, remove all breaks and leave lines, see the screenshots. I think this easier to understand as my bad english.

my example in html-tab
enter image description here

the same example after switch to visual
enter image description here

My tests for an solution.
i have test this to stop WP for this with the follow test plugin, also readable in this Gist 1663554

add_filter( 'tiny_mce_before_init', 'fb_tinymce', 9 );

function fb_tinymce( $init ) {

    $init['fix_list_elements'] = FALSE;
    $init['wpautop'] = FALSE;
    $init['remove_linebreaks'] = FALSE;
    $init['apply_source_formatting'] = TRUE;
    $init['extended_valid_elements'] .= ',pre[*],code[*]';

    return $init;
}

Maybe an other reader has an solution for this topic.

4 s
4

[*]

There is my solution – tehere is my solution of this problem:

Preserving tabs and line breaks in <pre><code> when switching from HTML to Visual Editor

Leave a Comment