Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Did I understand this right? You want to stop the editor to remove line breaks inside code? –  kaiser Feb 7 '12 at 4:05
    
yes, if you include code on the html-editor and switch to the visual mode, WP remove all breaks, paragraph. This works with the editor.js and i dont fond an filter for this; maybe is hard coded and my only goal is to replace this js; but its not very fine; i will deactivate this once feature. –  bueltge Feb 7 '12 at 8:35

4 Answers 4

up vote 1 down vote accepted

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

share|improve this answer
    
Current I don't have the problem in 3.5 and 3.6-alpha. Thanks for the hint in your answer to the bug. –  bueltge Feb 9 '13 at 13:42
    
yes, in 3.5 it's fixed –  OzzyCzech Feb 13 '13 at 10:43

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.

share|improve this answer
    
Version 1.5 is about to be released, that will also include support for real script blocks. And version 1.4 (current stable) allows for conditional inclusion of p tags or br tags, so you can use either based on your preference. –  Marcus Pope Aug 31 '12 at 21:59
    
Do you realised the functions for my question with JS or PHP, via Filter? I search only an functions, that the code inside pre or code was unchanged from tinyMCE. I will not an solution, there are filter after the_content, while is more performance. Thanks! –  bueltge Sep 3 '12 at 8:20
    
@bueltge - I didn't quite understand the question. My plugin does a lot to fix this problem, so I can't briefly describe the specific filters I used. You can certainly look at the source code of my plugin to find out how I did it. –  Marcus Pope Sep 3 '12 at 17:42
    
Yes, I can read in your source; but maybe its easier if you give me a note about the solution for only my problem of the question. Your plugin fix a lot of topics in this area. –  bueltge Sep 4 '12 at 9:21

Use Scripts n Styles plugin. http://wordpress.org/extend/plugins/scripts-n-styles/ It was invented to "Jump through hoops" and avoid wpautop bugs, specifically the tab-switching bugs.

You'd enter [sns_shortcode name="{name}"] in the editor, and your content in the Shortcodes tab. It's syntax highlighted and I've worked hard to code it well.

share|improve this answer

I think the easiest solution for what you're describing is a plugin like: http://wordpress.org/extend/plugins/wp-no-format/

However, you might also want to look at syntax highlighting plugins... there is even one for embedding gists by id.

share|improve this answer
    
I think, this it's not an solution, this plugin filter only the_content-Hook. This hook is only on frontend to get the content, not inside the editor. –  bueltge May 9 '12 at 11:43
    
Sorry. That is correct, this does not prevent the visual editor switch from reformatting the code.... It's been a long time since id actually used it and looking now at the old site I used it in conjunction with Disable Visual Editor. –  jb510 May 9 '12 at 17:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.