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 = '' . '' . '' . '' . '' . '' . '
ABC
3412
'; $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 = '' . '' . '' . '' . '' . '' . '
ABC
34A*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 PriceQtySubtotal
$1.232$2.46
$4.996$29.94
Total$32.40
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_styledValue() { $markdown = "| A | B | C |\n| --- | --- | --- |\n| **3** | _4_ | =A*B |"; $expected = '' . '' . '' . '' . '' . '' . '
ABC
3412
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_styledFormula() { $markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | **=A*B** |"; $expected = '' . '' . '' . '' . '' . '' . '
ABC
3412
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_styledFormula_multiple() { $markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | ~~**=A*B**~~ |"; $expected = '' . '' . '' . '' . '' . '' . '
ABC
3412
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } public function test_preservedOperators() { // Regular markdown will want to convert *B* into emphasized B $markdown = "| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B*4 |"; $expected = '' . '' . '' . '' . '' . '' . '
ABC
3448
'; $actual = $this->md($markdown); $this->assertSame($expected, $actual); } } ?>