The MU forums have moved to WordPress.org

insert multiple line breaks in posts (9 posts)

  1. quenting
    Member
    Posted 17 years ago #

    How can users do that ? They keep complaining that carriage returns get stripped out of their posts. It seems it's not possible to have more than one line break at a time.

    What can I do to change that ?

  2. drmike
    Member
    Posted 17 years ago #

    Tell them not to use TinyMCE/ Rich Text editor. It strips them. Common complaint over in WP.com land.

    You could also suggest to them that they use something like:

    <p>&nbsp;</p>
    <br />&nbsp;

    Hope this helps,
    -drmiek

  3. quenting
    Member
    Posted 17 years ago #

    disabling the rich editor is not an option. I'd rather fix it so it doesn't strip them anymore.
    I've tried changing the options in javascript, but it seems they are also stripped server side (which by the way would mean changing the editor won't sokve the problem).

  4. drmike
    Member
    Posted 17 years ago #

    Well, unfortunely disabling TinyMCE is your solution. if you would like, you can report the problem to the TinyMCE folks. My money is on them telling you your users are causing the error and it's not a fault with their code.

    Please remember that TinyMCE is just a plugin that WP uses and is used on a number of other projects. You will get complaints on how it throws in extra lines, mucks up fonts and boldness, modifies links, and (My personal favorite) how it doesn't work with Safari browser users.

    Sorry you don't want to hear the truth but after 6 months of being moderator on WP.com, doing hosting for over 4 years semi professional, and trying to work with the TinyMCE folks that's my solution.

  5. quenting
    Member
    Posted 17 years ago #

    I'm glad you're that experienced with wordpress, but i think you're missing the problem.
    I did disable TinyMCE for testing purposes, and it didn't solve the problem.

    Even with the simple editor, even entering stuff like you mentionned (brs and ps and nbsps;)
    Still the line breaks get all merged into one.
    So I'm guessing: it's not (only) a tinyMCE problem, and the line breaks get stripped server side.

  6. quenting
    Member
    Posted 17 years ago #

    ok, so i've done a bit more research on this and here's what i found:
    neither or <br> are stored in the db.
    Only \n carriage returns are. They are then re-interpreted at rendering time and this is when the issue comes (so it's unrelated to tinymce, it's a pure wp problem.

    It seems the function incriminated is wpautop in formatting.php (or functions-formatting.php depending on your version).

    I've narrowed the problem to the following two lines of code:

    $pee = preg_replace("/\n\n+/", "\n\n", $pee); // take care of duplicates
    $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "$1\n", $pee); // make paragraphs, including one at the end

    The first one replaces 2+ line breaks with only 2.
    The second one I'm not 100% sure but it seems to create paragraphs out of a given combination of text and line breaks.
    Basically everything starting or not with a \n, and ending with either 1\n , 2 \n or one \n and end of string gets wrapped in a .
    The combination of these 2 filters make it impossible to have brs in the output and the only line breaks are introduced by the tags, and there's never more than one.
    Now, I'm not a regexp expert, so I'm not too sure what to replace this with... We need to be able to have multiple breaks, and in the meantime generate proper code (and not mess with the following regexps in the function).
    Ideas ?

  7. quenting
    Member
    Posted 17 years ago #

    in case anyone's interested, this problem has been solved on my side (thanks to the french WP support) by upgrading tinymce, and commenting out the following line of code in plugins/wordpress/editor_plugin.js
    (around line 240)

    // Remove anonymous, empty paragraphs.
    // quentin: no don't, this prevents multiple line breaks
    // content = content.replace(new RegExp('(\\s| )*', 'mg'), '');

  8. slor
    Member
    Posted 16 years ago #

    Thanks quenting. That worked for me. Writers=happy again

  9. softlord
    Member
    Posted 16 years ago #

    @quenting: thanks to your input, i figured out a simpler way to address this: Go into your index.php in theloop and change <?php the_content(''); ?> to <?php echo nl2br(the_content('')); ?>. This will change the \n's back to <br/>s. then format appropriately via CSS.

About this Topic

  • Started 17 years ago by quenting
  • Latest reply from softlord