Index: trunk/extensions/Poem/Poem.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | $wgExtensionMessagesFiles['Poem'] = dirname(__FILE__) . '/Poem.i18n.php'; |
32 | 32 | |
33 | 33 | function wfPoemExtension( &$parser ) { |
34 | | - $parser->setHook("poem","PoemExtension"); |
| 34 | + $parser->setHook( 'poem', 'wfRenderPoemTag' ); |
35 | 35 | return true; |
36 | 36 | } |
37 | 37 | |
— | — | @@ -41,19 +41,21 @@ |
42 | 42 | * @param bool $frame |
43 | 43 | * @return string |
44 | 44 | */ |
45 | | -function PoemExtension( $in, $param=array(), $parser=null, $frame=false ) { |
| 45 | +function wfRenderPoemTag( $in, $param=array(), $parser=null, $frame=false ) { |
46 | 46 | |
47 | 47 | /* using newlines in the text will cause the parser to add <p> tags, |
48 | | - * which may not be desired in some cases |
| 48 | + * which may not be desired in some cases |
49 | 49 | */ |
50 | 50 | $nl = isset( $param['compact'] ) ? '' : "\n"; |
51 | | - |
| 51 | + |
52 | 52 | $tag = $parser->insertStripItem( "<br />", $parser->mStripState ); |
| 53 | + |
53 | 54 | $text = preg_replace( |
54 | | - array( "/^\n/", "/\n$/D", "/\n/", "/^( +)/me" ), |
55 | | - array( "", "", "$tag\n", "str_replace(' ',' ','\\1')" ), |
| 55 | + array( "/^\n/", "/\n$/D", "/\n/" ), |
| 56 | + array( "", "", "$tag\n" ), |
56 | 57 | $in ); |
57 | | - $text = $parser->recursiveTagParse( $text, $frame ); |
| 58 | + $text = preg_replace_callback( '/^( +)/m', 'wfPoemReplaceSpaces', $text ); |
| 59 | + $text = $parser->recursiveTagParse( $text, $frame ); |
58 | 60 | |
59 | 61 | $attribs = Sanitizer::validateTagAttributes( $param, 'div' ); |
60 | 62 | |
— | — | @@ -64,8 +66,15 @@ |
65 | 67 | $attribs['class'] = 'poem'; |
66 | 68 | } |
67 | 69 | |
68 | | - return Xml::openElement( 'div', $attribs ) . |
69 | | - $nl . |
70 | | - trim( $text ) . |
71 | | - "$nl</div>"; |
| 70 | + return array( |
| 71 | + Html::rawElement( 'div', $attribs, $nl . trim( $text ) . $nl ), |
| 72 | + 'markerType' => 'none', |
| 73 | + ); |
72 | 74 | } |
| 75 | + |
| 76 | +/** |
| 77 | + * Callback for preg_replace_callback() |
| 78 | + */ |
| 79 | +function wfPoemReplaceSpaces( $m ) { |
| 80 | + return str_replace( ' ', ' ', $m[1] ); |
| 81 | +} |