Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Double <br> after blockquote?

I'm automatically getting two line breaks after a blockquote? How can I can modify that?

Best Answer

  • hgtonighthgtonight MVP
    Answer ✓

    This is fixed in the 2.1b1 version. You can either a) port the affected changes, b) set Vanilla to not replace new lines as br tags, c) or deal with it.

    Solutions

    A) Add the function FixNl2Br() to functions.render.php. Don't forget the include guard! Modify class.format.php to call this after the regex replacements in the Html() formatter method. You can use the following diff as a starting point.

    class.format.php:

    @@ -697,7 +697,6 @@
      // nl2br
      if(C('Garden.Format.ReplaceNewlines', TRUE)) {
        $Mixed = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Mixed);
    + $Mixed = FixNl2Br($Mixed);
        // $Mixed = wpautop($Mixed);
      }
    
    @@ -714,7 +713,6 @@
      $Result = Gdn_Format::Links($Result);
      if(C('Garden.Format.ReplaceNewlines', TRUE)) {
        $Result = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Result);
    +   $Result = FixNl2Br($Result);
          // $Result = wpautop($Result);
        }
      }
    

    functions.render.php:

    @@ -281,19 +281,4 @@
        function SignOutUrl($Target = '') {
           return '/entry/signout?TransientKey='.urlencode(Gdn::Session()->TransientKey()).($Target ? '&Target='.urlencode($Target) : '');
        }
    +}
    +
    +if (!function_exists('FixNl2Br')) {
    +   /**
    +    * Removes the break above and below tags that have a natural margin.
    +    * @param string $Text The text to fix.
    +    * @return string
    +    * @since 2.1
    +    */
    +   function FixNl2Br($Text) {
    +      $allblocks = '(?:table|dl|ul|ol|pre|blockquote|address|p|h[1-6]|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    +      $Text = preg_replace('!(?:<br\s*/>){1,2}\s*(<' . $allblocks . '[^>]*>)!', "\n$1", $Text);
    +      $Text = preg_replace('!(</' . $allblocks . '[^>]*>)\s*(?:<br\s*/>){1,2}!', "$1\n", $Text);
    +      return $Text;
    +   }
    +}
    

    B) $Configuration['Garden']['Format']['ReplaceNewlines'] = FALSE;

    C) You are done!

    I prefer these solutions in reverse order. :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Answers

  • Ha. I forgot to wrap<br> in the title.

  • phreakphreak MVP
    edited May 2013

    But great bug discovered the same moment, i does make a linebreak in the Title tooo. Haha!

    Github!

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • Are you using any editor plugins? Buttonbar, NBBC, Wysihtml, CLEditor, etc.?

    What formatter? Html, BBCode, MarkDown?

    What version of Vanilla are you running? 2.0.18.8 or 2.1b1?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • No editor plugins, running 2.0.18, HTML.

  • hgtonighthgtonight MVP
    Answer ✓

    This is fixed in the 2.1b1 version. You can either a) port the affected changes, b) set Vanilla to not replace new lines as br tags, c) or deal with it.

    Solutions

    A) Add the function FixNl2Br() to functions.render.php. Don't forget the include guard! Modify class.format.php to call this after the regex replacements in the Html() formatter method. You can use the following diff as a starting point.

    class.format.php:

    @@ -697,7 +697,6 @@
      // nl2br
      if(C('Garden.Format.ReplaceNewlines', TRUE)) {
        $Mixed = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Mixed);
    + $Mixed = FixNl2Br($Mixed);
        // $Mixed = wpautop($Mixed);
      }
    
    @@ -714,7 +713,6 @@
      $Result = Gdn_Format::Links($Result);
      if(C('Garden.Format.ReplaceNewlines', TRUE)) {
        $Result = preg_replace("/(\015\012)|(\015)|(\012)/", "<br />", $Result);
    +   $Result = FixNl2Br($Result);
          // $Result = wpautop($Result);
        }
      }
    

    functions.render.php:

    @@ -281,19 +281,4 @@
        function SignOutUrl($Target = '') {
           return '/entry/signout?TransientKey='.urlencode(Gdn::Session()->TransientKey()).($Target ? '&Target='.urlencode($Target) : '');
        }
    +}
    +
    +if (!function_exists('FixNl2Br')) {
    +   /**
    +    * Removes the break above and below tags that have a natural margin.
    +    * @param string $Text The text to fix.
    +    * @return string
    +    * @since 2.1
    +    */
    +   function FixNl2Br($Text) {
    +      $allblocks = '(?:table|dl|ul|ol|pre|blockquote|address|p|h[1-6]|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
    +      $Text = preg_replace('!(?:<br\s*/>){1,2}\s*(<' . $allblocks . '[^>]*>)!', "\n$1", $Text);
    +      $Text = preg_replace('!(</' . $allblocks . '[^>]*>)\s*(?:<br\s*/>){1,2}!', "$1\n", $Text);
    +      return $Text;
    +   }
    +}
    

    B) $Configuration['Garden']['Format']['ReplaceNewlines'] = FALSE;

    C) You are done!

    I prefer these solutions in reverse order. :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.