Last modified: 2011-04-14 20:14:30 UTC
Created attachment 5012 [details] Patch to remove <p> tags preceding parser function output As I wrote to the list, I came across undesired feature in Parser that forces </p><p> in front of all parser function output. It was apparently introduced in 1.5.0 and is still the case in the trunk (although Parser.php is moved to includes/parser/ folder). Here's the piece of code in question (line 2975 on 1.12.0 branch): # Replace raw HTML by a placeholder # Add a blank line preceding, to prevent it from mucking up # immediately preceding headings if ( $isHTML ) { $text = "\n\n" . $this->insertStripItem( $text ); } The problem is that the assumption that users don't want parser function output directly after the preceding text is wrong, especially when <p> tags are inserted. I think that "\n\n" should be removed, but please correct me if I'm wrong with this. Patch against 1.12.0 (includes/Parser.php) is attached.
Obviously it doesn't happen that paragraph breaks are forced in front of all parser function output; otherwise they could not be used inside paragraphs. Can you provide a test case?
+testme
I've ran into this, too. What has yet to be explicitly stated (though it was implied) is that this issue only occurs when 'isHTML' in the output array of a parser function is set to true. (See http://www.mediawiki.org/wiki/Manual:Parser_functions#Controlling_the_parsing_of_output) A simple test case to demonstrate the issue. First a simple parser function extension: <?php $wgHooks[ 'ParserFirstCallInit' ][] = 'wfInitIsHTMLDemo'; $wgHooks[ 'LanguageGetMagic' ][] = 'wfDemoMagic'; function wfInitIsHTMLDemo( $parser ) { $parser->setFunctionHook( 'demo', 'wfDemo' ); return true; } function wfDemoMagic( &$magicWords ) { $magicWords[ 'demo' ] = array( 0, 'demo' ); return true; } function wfDemo( $parser ) { return array( '<input type="checkbox"/>', 'noparse' => true, 'isHTML' => true ); } Next is some test wiki markup: I would like {{#demo:}} this entire line {{#demo:}} to be contained {{#demo:}} in one paragraph. Which yields four paragraphs, all but the first starting with a checkbox. There's little point in singling out HTML-generating parser functions when any text after a wiki heading will muck the heading up.
I have also run into this problem when attempting to inline special page transclusions, since they are also marked with isHTML. It is currently the bane of my existence. Removing that \n\n would fix it for me, but it seems the problem may be a bit more complicated than that.
I fooled myself by reading too much into the comments that attempt to justify the "\n\n". I can see a need to insert things into headings, even. A proper patch would be against trunk and would also remove the second and third comment line there. I'll generate one tomorrow morning and add it to this issue. Has it been noted that this issue is basically a dup of 12974?
Created attachment 6650 [details] Trunk patch to remove <p> and associated comments Added patch against trunk that removes the two associated comment lines as well.
Just a note, that this change breaks 2 parser tests, which will also have to be modified to check for the new output.
Created attachment 6652 [details] Patch to fix <p> issues, remove associated comments, and fix two parser tests
*** This bug has been marked as a duplicate of bug 10781 ***