includes/wikiengine/parse_mediawiki.php
changeset 1127 4b858862c35c
parent 1106 01315acbc22b
child 1130 c308b471ed82
equal deleted inserted replaced
1125:367768040a61 1127:4b858862c35c
   180     // First we need a list of block level elements (http://htmlhelp.com/reference/html40/block.html + some Enano extensions)
   180     // First we need a list of block level elements (http://htmlhelp.com/reference/html40/block.html + some Enano extensions)
   181     $blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot';
   181     $blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot';
   182     
   182     
   183     // Wrap all block level tags
   183     // Wrap all block level tags
   184     RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
   184     RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
   185     $text = preg_replace("/<($blocklevel)(?: .+?>|>)(?:(?R)|.*?)<\/\\1>/s", '<_paragraph_bypass>$0</_paragraph_bypass>', $text);
   185     // I'm not sure why I had to go through all these alternatives. Trying to bring it
       
   186     // all down to one by ?'ing subpatterns was causing things to return empty and throwing
       
   187     // errors in the parser. Eventually, around ~3:57AM I just settled on this motherf---er
       
   188     // of a regular expression.
       
   189     $regex = ";
       
   190               <($blocklevel)
       
   191               (?:
       
   192                 # self closing, no attributes
       
   193                 [ ]*/>
       
   194               |
       
   195                 # self closing, attributes
       
   196                 [ ][^>]+? />
       
   197               |
       
   198                 # with inner text, no attributes
       
   199                 >
       
   200                 (?: (?R) | .*? )*</\\1>
       
   201               |
       
   202                 # with inner text and attributes
       
   203                 [ ][^>]+?     # attributes
       
   204                 >
       
   205                 (?: (?R) | .*? )*</\\1>
       
   206               )
       
   207                 ;sx";
       
   208                 
       
   209     $text = preg_replace($regex, '<_paragraph_bypass>$0</_paragraph_bypass>', $text);
   186     RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw, true);
   210     RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw, true);
   187     
   211     
   188     // This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags
   212     // This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags
   189     // to prevent the paragraph parser from interfering with pretty HTML generated elsewhere.
   213     // to prevent the paragraph parser from interfering with pretty HTML generated elsewhere.
   190     RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
   214     RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);