WordPress.org

Ready to get started?Download WordPress

Forums

Leaving untouched in Visual Editor (11 posts)

  1. tboerman
    Member
    Posted 2 years ago #

    Hello,

    I'm trying to incorporate some sourcecode in a post, but the visual editor is giving me problems.

    I enter this in HTML mode:

    Here is some code:
    
    <pre>
    #include <stdio.h>
    
    void main()
    {
      printf("Hello!\n");
    }
    </pre>

    Then switch to visual mode, and back. The code then becomes:

    Here is some code:
    <pre>#include <stdio.h> void main() { printf("Hello!\n"); } </stdio.h></pre>

    Is there a way to tell the editor to leave the stuff inside
    <pre> tags alone? I have searched the forums and tried various plugin, but I can't get it to work.

    Regards,
    tboerman

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Is there a way to tell the editor to leave the stuff inside
    tags alone?

    Short answer: Nope.

    Longer answer: It's a known issue with the TinyMCE Editor. Mos (if not all) of the markup entered via the HTML tab will be stripped out by the Visual Editor. If you simply can't restrict yourself to the HTML tab, then you need to look around for a suitable WYSIWYG editor plugin.

  3. tboerman
    Member
    Posted 2 years ago #

    Short answer: Nope.

    Longer answer: It's a known issue with the TinyMCE Editor. Mos (if not all) of the markup entered via the HTML tab will be stripped out by the Visual Editor. If you simply can't restrict yourself to the HTML tab, then you need to look around for a suitable WYSIWYG editor plugin.

    Hey,

    I'm aware that this is a notorious problem/feature in WordPress. Setting valid_elements to "*[*]" with the Advanced TinyMCE Config plugin seemed to improve things, but it is still far from fixed.

    It would be great if there was a way to tell the editor to leave the <pre> contents completely untouched. Hopefully someone can point me at a plugin that can do this ("Save my Pre" didn't do the trick).

  4. esmi
    Forum Moderator
    Posted 2 years ago #

    How about approaching this from a completely different angle and looking for a code editing/publishing plugin?

  5. tboerman
    Member
    Posted 2 years ago #

    I'm using the WP-Syntax plugin to do highlighting, but this requires the use of <pre> tags. Hence the question.

  6. esmi
    Forum Moderator
    Posted 2 years ago #

  7. tboerman
    Member
    Posted 2 years ago #

    Thanks. Unfortunately that plugin requires you to define code snippets in the plugin settings before you can use them. Is there really no way to edit code in-line? :(

    I can understand why so many people are raging at WordPress over this, its just stupid! The WordPress authors don't have much love for people who want to blog about coding, that is for sure.

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    To be honest, I think that most people who blog about coding use the HTML tab. I know I do.

  9. tboerman
    Member
    Posted 2 years ago #

    Yeah, I guess that's the bottom line. Still, how hard could it be for the the editor to just leave things in <pre> tags completely untouched when switching back and forth?

  10. esmi
    Forum Moderator
    Posted 2 years ago #

    Having worked on a (very rough) WYSIWYG) editor myself in the past. I'd say it can be incredibly hard. I have nothing but respect for the people behind editors like TinyMCE - for all its flaws.

    What about creating a simple shortcode in your theme that allows you to wrap code in <pre></pre> tags?

  11. tboerman
    Member
    Posted 2 years ago #

    Yeah, I guess it's harder than it looks or it would have been fixed long ago. Even plugins such as Preserve Code Formatting do not support using the visual editor. I will stick with the HTML editor for now, thanks for the help!

Topic Closed

This topic has been closed to new replies.

About this Topic