Skip to:
Content

bbPress.org

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#2335 closed defect (bug) (fixed)

a href="" code breaking and backticks with inconsistent output

Reported by: alexanderagn's profile AlexanderAgn Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.3.3 Priority: high
Severity: normal Version: 2.3.2
Component: General Keywords: needs-patch editor code backticks link " posting
Cc:

Description

I think this screenshot explains it best:
http://i.imgur.com/Ud8iuS9.png

The text in the textarea is how the text is written to result in the reply above.

Code output:
http://i.imgur.com/mwEoEMQ.png

Issues:

  1. Backticks without linebreak results in code tag only
  2. Backticks with linebreaks results in pre+code tag
  3. Backticks with linebreak adds a space inside the "code box"
  4. a href tags incorrectly breaks code, as " is added in the end of the link and recognized as part of the link, instead of a " sign.

There was also a problem where formatting would change when editing a post, removing the linebreaks before/after backticks in 2.3.1 - and turning it into code tag only, instead of pre+code. I believe this has been fixed in 2.3.2 however.

The a href issue is annoying for a support forum which uses a lot of HTML-code. We always have to use pastebin or something similar as soon as it contains a link.

As the two latest bbPress releases has been about fixing posting of code, it would be nice to have it all fully fixed while you're at it.

---

Additional:

The Miohki Backticks plugin, which this forum has used before code managing was improved in bbPress, does not affect the a href or code output ( https://github.com/daltonrooney/Miohki-Backticks ), whether turned on or off - it still breaks. However, old replies with backticks does not get recognized by bbPress it seems, when this plugin is disabled - which forces us to keep it activated. Not sure why that would be.

Attachments (1)

2335.patch (4.4 KB) - added by johnjamesjacoby 12 years ago.
Introduce bbp_make_clickable()

Download all attachments as: .zip

Change History (10)

#1 in reply to: ↑ description @AlexanderAgn
12 years ago

Ignore the double && signs in the screenshots by the way, that was just me not pasting it properly. What it normally shows is just "

#2 follow-up: @alexvorn2
12 years ago

maybe you should replace the " with " before posting the html text

#3 in reply to: ↑ 2 @AlexanderAgn
12 years ago

Replying to alexvorn2:

maybe you should replace the " with " before posting the html text

Thanks for the suggestion, but that kind of defeats the purpose though, doesn't it?

You shouldn't need to edit code and replace certain HTML characters every time they are included, when you have told the editor that you are pasting code. It should be able to recognize it and fix it without manual editing.

I'm fairly sure it has to do with the way bbPress auto-converts typed links into clickable ones when posting, and that this action runs inside code/pre tags as well - which breaks it.

Last edited 12 years ago by AlexanderAgn (previous) (diff)

#4 @johnjamesjacoby
12 years ago

  • Milestone changed from Awaiting Review to 2.3.3

@johnjamesjacoby
12 years ago

Introduce bbp_make_clickable()

#5 @johnjamesjacoby
12 years ago

In 4942:

Introduce bbp_make_clickable() and use it in place of make_clickable() filter. Fixes issues with making links clickable inside pre and code blocks. See #2335 (trunk)

#6 @johnjamesjacoby
12 years ago

  • Owner set to johnjamesjacoby
  • Resolution set to fixed
  • Status changed from new to closed

In 4943:

Introduce bbp_make_clickable() and use it in place of make_clickable() filter. Fixes issues with making links clickable inside pre and code blocks. Fixes #2335 (2.3 branch)

#7 follow-ups: @johnjamesjacoby
12 years ago

This is running on bbpress.org now, if anyone wants to test it out.

#8 in reply to: ↑ 7 @alex-ye
12 years ago

Replying to johnjamesjacoby:

This is running on bbpress.org now, if anyone wants to test it out.

Great !, I was mention this in #2317, and very happy because this is lately solved.. I am not geek in the Regular Expressions but I think bbp_make_clickable() is too complicated now.

I was using this code in my site, and maybe it will help someone:

/**
 * Convert plaintext URI to HTML links, except those links in pre,code tags .
 * 
 * @credits ( WP SyntaxHighlighter & bbPress Code Snippets  ) Plugins .
 * @since 0.1.4
 */
function ArWP_make_clickable( $content ) {
    
    $new_content = '';

    foreach( ArWP_split_content_by_html_tag( 'pre' , $content ) as $piece ) {
 
        if ( !ArWP_is_contents_html_tag( 'pre' , $piece ) ) {

            $new_piece = '';

            // Only apply make_clickable() if not in a <code> tag.
            foreach(  ArWP_split_content_by_html_tag( 'code' , $piece ) as $small_piece ) {

                if ( !ArWP_is_contents_html_tag( 'code' , $piece ) )
                     $small_piece = make_clickable( $small_piece );

                $new_piece .= $small_piece;
                
            } // end foreach

            $new_content .= $new_piece;

        } else {

            // Display raw content between <pre> tags .
            $new_content .= trim( $piece );
                
        } // end if
                    
    } // end foreach

    return $new_content;
    
} // end ArWP_make_clickable()

/**
 * Check if the text content's a <$tag></$tag> HTML tag .
 * 
 * @since 0.1.4
 * @return boolean
 */
function ArWP_is_contents_html_tag( $tag , $text ) {    
    return ( preg_match( "|(<{$tag}[^>]*?>)(.*?)(</{$tag}>)|is" , $text ) > 0 );
} // end ArWP_is_contents_html_tag()

/**
 * Split content by <$tag></$tag>
 * 
 * @since 0.1.4
 * @return array 
 */
function ArWP_split_content_by_html_tag( $tag , $text ) {
    return preg_split( "{(<{$tag}[^>]*?>.*?\</{$tag}>)}is", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
} // end ArWP_split_content_by_html_tag()

#9 in reply to: ↑ 7 @AlexanderAgn
12 years ago

Replying to johnjamesjacoby:

This is running on bbpress.org now, if anyone wants to test it out.

Perfect - all working fine here, added the fix to our forum as well. No more a href issues. Thank you.

Note: See TracTickets for help on using tickets.