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.

Read More

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.

Related posts

Leave a Reply

4 comments

  1. Yep, it’s a total pain. 99% of the ‘disable wpautop’ tutorials completely miss the tab switch event. Anyway, you should try my plugin – http://wordpress.org/extend/plugins/preserved-html-editor-markup/

    Not only will it protect your markup from being mangled by wpautop, but it will preserve line breaks and indentation while still allowing you to use both the HTML editor and the Visual editor.

    The current version will really disable wpautop, so if you have existing content that depends on wpautop your site may not render properly without modifying the existing content. I’m working on a new version that will batch reformat existing content to correct this. It should be ready by the end of the week.