foreach ( $lines as $outLine ) {
$line = trim( $outLine );
- if ( $line === '' ) { // empty line, go to next line
- $out .= $outLine . "\n";
+ # empty line, go to next line,
+ # but only append \n if outside of table
+ if ( $line === '' ) {
+ $out .= $outLine;
+ if ( !isset( $tables[0] ) ) {
+ $out .= "\n";
+ }
continue;
}
$firstChars = $line[0];
if ( empty( $lastRow ) ) {
$lastRow = NULL;
}
+ $o = '';
$curtable = array_pop( $tables );
- $o = $this->generateTableHTML( $curtable ) . $line;
+
+ #Add a line-ending before the table, but only if there isn't one already
+ if ( substr( $out, -1 ) !== "\n" ) {
+ $o .= "\n";
+ }
+ $o .= $this->generateTableHTML( $curtable ) . $line . "\n";
if ( count( $tables ) > 0 ) {
$table =& $this->last( $tables );
if ( isset( $tables ) && count( $tables ) > 0 ) {
for ( $i = 0; $i < count( $tables ); $i++ ) {
$curtable = array_pop( $tables );
- $out .= $this->generateTableHTML( $curtable );
+ $curtable = $this->generateTableHTML( $curtable );
+ #Add a line-ending before the table, but only if there isn't one already
+ if ( substr( $out, -1 ) !== "\n" && $curtable !== "" ) {
+ $out .= "\n";
+ }
+ $out .= $curtable;
}
}
* @private
*/
function generateTableHTML ( &$table ) {
- $return = "\n";
+ $return = "";
$return .= str_repeat( '<dl><dd>' , $table['indent'] );
$return .= '<table';
$return .= isset( $table['attributes'] ) ? $table['attributes'] : '';
</table></dd></dl>
!! end
+
+!! test
+Arbitrary whitespace should not be prepended
+!! input
+{|
+| 1 || 2
+
+|-
+
+
+| 3 || 4
+|-
+
+| 6 || 8
+|}
+!! result
+<table>
+<tr>
+<td>1
+</td>
+<td>2
+</td>
+</tr>
+<tr>
+<td>3
+</td>
+<td>4
+</td>
+</tr>
+<tr>
+<td>6
+</td>
+<td>8
+</td>
+</tr>
+</table>
+
+!! end
+
+
###
### Internal links
###
!!result
<p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
</p>
-
!! end
# Known to produce bad XML for now
<p>{{{|
</p><p><u class="|">}}}} >
</p><p><br style="onmouseover='alert(document.cookie);'" />
-</p><p><br />
-MOVE YOUR MOUSE CURSOR OVER THIS TEXT
+</p><p>MOVE YOUR MOUSE CURSOR OVER THIS TEXT
</p>
<table>
<tr>
</td>
<td>4
</td>
-</tr></table>
+</tr>
+</table>
<p>y
</p>
!! end