parser = new Markdown(array_merge(Markdown::allReaders(), [ new MDSpreadsheetReader() ]));
}
private function md(string $markdown): string {
return $this->normalizeWhitespace($this->parser->toHTML($markdown));
}
private function normalizeWhitespace(string $str): string {
$str = mb_eregi_replace('\\s+', ' ', $str);
$str = mb_eregi_replace('>\\s+<', '><', $str);
return trim($str);
}
public function test_integration() {
$markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B |";
$expected = '
' .
'| A | B | C |
' .
'' .
'| 3 | ' .
'4 | ' .
'12 | ' .
'
';
$actual = $this->md($markdown);
$this->assertSame($expected, $actual);
}
public function test_bailOut() {
// If no formulas found table isn't modified
$markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | A*B |";
$expected = '' .
'| A | B | C |
' .
'' .
'| 3 | ' .
'4 | ' .
'A*B | ' .
'
';
$actual = $this->md($markdown);
$this->assertSame($expected, $actual);
}
public function test_observedError1() {
// Saw "Uncaught Error: columnIndex must be number, got string" from this
$markdown = "| Unit Price | Qty | Subtotal |\n| ---: | ---: | ---: |\n| $1.23 | 2 | =A*B FILL |\n| $4.99 | 6 | |\n| Total | | =SUM(C:C) |";
$expected = '' .
'| Unit Price | ' .
'Qty | ' .
'Subtotal | ' .
'
' .
'| $1.23 | ' .
'2 | ' .
'$2.46 | ' .
'
' .
'| $4.99 | ' .
'6 | ' .
'$29.94 | ' .
'
' .
'| Total | ' .
' | ' .
'$32.40 | ' .
'
';
$actual = $this->md($markdown);
$this->assertSame($expected, $actual);
}
}
?>