Recent Topics

1 Feb 02, 2009 17:17    

My b2evolution Version: 2.x

Hi, I use a [url=http://josephhall.org/b2evo_markdown/README.html]plugin for Markdown[/url] that supports a syntax element where the following:

<http://www.example.com/>

would be turned into:

<a href="http://www.example.com/">http://www.example.com/</a>

However, after just upgrading from 1.10.2 to 2.4.6, this kind of a link is modified before it hits the Markdown plugin to insert a space between `http` and the rest of the URL string, like so:

<http ://www.example.com/>

I can't seem to find a way of tinkering with the security filters in Blog Settings -> Group Permissions that makes this not happen.

Any advice?

2 Feb 07, 2009 21:28

You might try giving the markdown plugin a priority number of 1 so that it goes first. Or does 99 make it go first? Either way, if you try both and nothing changes then we can rule out a conflict with another plugin. OTOH if 1 or 99 produces a different end result then we're on to something :)

I wonder if the plugin needs upgrading?

3 Feb 07, 2009 22:39

Thanks for the suggestion, EdB!

I did that -- chaning priority from 59 to 1 and then 99 and then a few in between -- and the weirdness still happens. I didn't notice this before, but what actually happens is something like

<http://www.example.com/>

is changed to:

<http ://www.example.com/></http>

So, I suspect some sort of xhtml (or other validator) is doing this before any of the other filtering. (AFAICT)

I tried adding the following code to inc/_xhtml_validator.class.php which would do a replacement for this special case... however, this doesn't seem to help (probably because I have XHTML validation turned off for administrators in the backoffice.... I've got everything turned off that I can to debug this):


--- _xhtml_validator.class.php  2009-02-07 13:23:00.000000000 -0800
+++ _xhtml_validator.class.php.new      2009-02-07 13:25:31.000000000 -0800
@@ -170,6 +170,14 @@
                // Open comments or '<![CDATA[' are dangerous
                $xhtml = str_replace('<!', '', $xhtml);
 
+               // Replace <http...> with a self-link
+               $temp_string = $xhtml;
+               $temp_pattern = '/<http(\S+)>/i';
+               $temp_replacement = '<a href="http$1">http$1</a>';
+               preg_replace($temp_pattern, $temp_replacement, $temp_string);
+               $xhtml = $temp_string;
+
+
                // Convert isolated & chars
                $xhtml = preg_replace( '#(\s)&(\s)#', '\\1&amp;\\2', $xhtml );
 

Any other thoughts would be welcome... if I can get something like the above to work, that would be ok. Obviously, I'm gunning for a more elegant solution for the long term. (Although I have no problem manually typing self-links when I need them. And I can't use the autolinks plugin because it interferes with other markdown syntax)

4 Feb 07, 2009 23:47

If it was something I had to fix I'd be making faces at my monitor and calling my keyboard a noob until everything worked, so I'm gonna go out on a limb here and say your path is probably a heck of a lot more likely to succeed ;)

Or wait a minute. markdown lets you type stuff in a 'simplified' format that includes making links that happen to look like tags. ... okay never mind ... I was gonna suggest rendering the < to a % before letting the validator sink it's teeth into it, but your priority experiment sort of showed the validator goes first. So unless you (a) changed your habits to use %link stuff% and (b) taught markdown that meant the same thing as <link stuff> it wouldn't work. And if you did it wouldn't be markdown anymore.

Good luck with this!

(I wonder if the dev team can be convinced to include your ultimate solution so anyone who wants to use markdown could without a core hack?)

5 Feb 08, 2009 19:47

Did you change anything else apart from upgrading?

¥

6 Feb 09, 2009 17:24

Hey guys...

@EdB: Ok, I'll hunt a bit further... I'd like the plugin to support as much of Markdown's syntax as possible, so changing Markdown for b2evo is very low on my list. But if I can produce a patch that takes care of this, then I'd at least feel confident I grasp what is happening in terms of flow of content.

@(characters): I didn't change anything in the plugin yet... which is related to EdB's "did you upgrade the plugin?" question. I'll have to look deeper into what changed in terms of plugins from when I wrote this to now. (A cursory glance at the _markdown_plugin.php file and other renderer plugins shows them to be very similar... I guess I could diff a plugin file from back when I wrote this one and one from now to get a handle on what has changed).

8 Feb 09, 2009 17:51

If it's the 'normal' one add a line in /markdown_plugin/_markdown.plugin.php

	function RenderItemAsHtml( & $params )
	{
		$content = & $params['data'];
		$content = preg_replace( array ('http ://', '</http>' ), array( 'http://', '' ), $content ) // Add this line
		$content = Markdown( $content );
		return true;
	}

It looks like the substitution is made before the $content gets to the plugin, so changing it back looks to be the easiest answer.

Good luck

9 Feb 09, 2009 17:58

Neat! I'll try that right now...

10 Feb 09, 2009 18:44

joebeone wrote:

@(characters)

:p

I didn't mean just the plugin, I meant "apart from upgrading to 1.10.x to 2.4.x did you change anything else" ... settings / server config / new plugin / anything ?

I'm guessing the </http> comes from balance_tags() ... I'm just confused to the space that's being inserted ;)

¥

11 Feb 09, 2009 18:44

Afwas' suggestion was the key to the solution!

It now works as intended by undoing the changes made to both these kinds of autolinks supported by Markdown:


<http://www.example.com>
<address@example.com>

I've added this code to the plugin and will update the thing to a new version.


                /*  Here we have to do a replacement to support                                                                                 
                Markdown's automatic link syntax (see:                                                                                          
                http://daringfireball.net/projects/markdown/syntax#autolink                                                                     
                ). The problem is that some part of b2evos validation                                                                           
                engine turns a link like `<http://www.example.com>`                                                                             
                into `<http ://www.example.com></http>` and                                                                                     
                `<address@example.com>` into `<address                                                                                          
                @example.com></address>`.  To correctly pass these                                                                              
                kinds of entities on to the Markdown renderer, we need                                                                          
                to effectively undo this. (-jlh 2009-02-09) */                                                                                  
                                                                                                                                                
                $temp_pattern     = array ('%<http ://(\S+)>%',        //match broken autolink                                                  
                                           '%</http>%',                //match errant close tag                                                 
                                           '%<(\S+) @(\S+)></\S+>%' ); //match broken email autolink                                            
                $temp_replacement = array( '<http://$1>',              //fix and replace with match (to `(\S+)`)                                
                                           ''         ,                //fix by delete                                                          
                                           '<$1@$2>');                 //fix and replace with matches                                           
                $content = preg_replace( $temp_pattern, $temp_replacement, $content );                                                          

12 Feb 09, 2009 18:52

¥åßßå wrote:

I didn't mean just the plugin, I meant "apart from upgrading to 1.10.x to 2.4.x did you change anything else" ... settings / server config / new plugin / anything ?

I'm guessing the </http> comes from balance_tags() ... I'm just confused to the space that's being inserted ;)

¥

I'm not sure... I followed the install directions that say to blast everything but the "media/" directory and then I essentially only made changes in the backoffice (that is, not changing the PHP files). If you suspect something specific, I can help you track it down.

It easily could be balance tags. Note that the following:


<http://www.example.com/>
<https://www.example.com/>
<address@example.com>

are converted like so under my install:


<http ://www.example.com/></http>
<https ://www.example.com/></https>
<address @example.com></address>

so, I suspect balance_tags or something like it is looking for a special character (a character invalid for the name of a tag?) and then inserting the space. Come to think of it, it's probably done before balance_tags and then balance_tags then slaps on the end tags.

13 Feb 09, 2009 18:55

You can use function FilterItemContents() to make changes before balance tags et al get hold of the content ;)

Knowing which settings you changed may help, probably easier if I just install the plugin and have a play I guess :P

¥

14 Feb 09, 2009 19:52

turns out that setting balance_tags to 0 in conf/_formatting.php negates needing to change the plugin at all!

However, since balance tags hasn't made it into the backoffice yet, I'm going to push this as an update to the plugin and remove the installation step where I tell people to disable balance tags.

15 Feb 10, 2009 09:11

Try moving your RenderItemAsHtml functionality to FilterItemContents and you shouldn't need hacks or to disable balance tags ;)

¥

16 Feb 10, 2009 12:07

that's in `inc/plugins/model/_plugins_admin.class.php`?

I'd rather not require people to make edits to other plugins if I can avoid it.

17 Feb 10, 2009 13:08

(characters) is suggesting editing your plugin by calling another hook:

    function FilterItemContents( & $params )
    {
        $content = & $params['data'];
        $content = Markdown( $content );
        return true;
    } 


remove the RenderItemAsHtml function if you try this.

Good luck

18 Feb 10, 2009 13:43

Ah, now I understand. Thanks very much guys for helping me with this.

I just tried this -- added Afwas' hook to FilterItemContents, commented out the RenderItemAsHTML call and set balance_tags back to 1 -- and it didn't work (that is, both in preview and in a test post the autolinks don't show up due to the `<http ://...>` and such substitution). :-/

Let me know if you have any further thoughts.

19 Feb 10, 2009 15:04

Did you remember to reload plugin events? ( admin > global settings > plugin install > reload plugins )

¥

20 Feb 10, 2009 19:25

Hi, yes I did do that and no dice (it still inserted a space and then tried to balance the tags).

21 Feb 11, 2009 10:03

Hmmm, ok, I'll have a play and see what I can come up with

¥


Form is loading...