PHP and Javascript implementations of a simple markdown parser
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

SpreadsheetMarkdownIntegrationTests.js 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. class SpreadsheetMarkdownIntegrationTests extends BaseTest {
  2. parser;
  3. setUp() {
  4. this.parser = new Markdown([ ...Markdown.allReaders, new MDSpreadsheetReader() ]);
  5. }
  6. md(markdown) {
  7. return normalizeWhitespace(this.parser.toHTML(markdown));
  8. }
  9. test_integration() {
  10. const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B |';
  11. const expected = '<table> <thead> ' +
  12. '<tr> <th>A</th> <th>B</th> <th>C</th> </tr> ' +
  13. '</thead> <tbody> <tr> ' +
  14. '<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td> ' +
  15. '<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td> ' +
  16. '<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12">12</td> ' +
  17. '</tr> </tbody> </table>';
  18. const result = this.md(markdown);
  19. this.assertEqual(result, expected);
  20. }
  21. test_bailOut() {
  22. // If no formulas found table isn't modified
  23. const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | A*B |';
  24. const expected = '<table> <thead> ' +
  25. '<tr> <th>A</th> <th>B</th> <th>C</th> </tr> ' +
  26. '</thead> <tbody> <tr> ' +
  27. '<td>3</td> ' +
  28. '<td>4</td> ' +
  29. '<td>A*B</td> ' +
  30. '</tr> </tbody> </table>';
  31. const result = this.md(markdown);
  32. this.assertEqual(result, expected);
  33. }
  34. test_observedError1() {
  35. // Saw "Uncaught Error: columnIndex must be number, got string" from this
  36. const markdown = '| Unit Price | Qty | Subtotal |\n| ---: | ---: | ---: |\n| $1.23 | 2 | =A*B FILL |\n| $4.99 | 6 | |\n| Total | | =SUM(C:C) |';
  37. const expected = '<table> <thead> <tr> ' +
  38. '<th style="text-align: right;">Unit Price</th> ' +
  39. '<th style="text-align: right;">Qty</th> ' +
  40. '<th>Subtotal</th> ' +
  41. '</tr> </thead> <tbody> <tr> ' +
  42. '<td class="spreadsheet-type-currency" style="text-align: right;" data-numeric-value="1.23" data-string-value="1.23">$1.23</td> ' +
  43. '<td class="spreadsheet-type-number" style="text-align: right;" data-numeric-value="2" data-string-value="2">2</td> ' +
  44. '<td class="calculated spreadsheet-type-currency" data-numeric-value="2.46" data-string-value="2.46">$2.46</td> ' +
  45. '</tr> <tr> ' +
  46. '<td class="spreadsheet-type-currency" style="text-align: right;" data-numeric-value="4.99" data-string-value="4.99">$4.99</td> ' +
  47. '<td class="spreadsheet-type-number" style="text-align: right;" data-numeric-value="6" data-string-value="6">6</td> ' +
  48. '<td class="calculated spreadsheet-type-currency" data-numeric-value="29.94" data-string-value="29.94">$29.94</td> ' +
  49. '</tr> <tr> ' +
  50. '<td class="spreadsheet-type-string" style="text-align: right;" data-string-value="Total">Total</td> ' +
  51. '<td class="spreadsheet-type-blank" style="text-align: right;" data-numeric-value="0" data-string-value=""></td> ' +
  52. '<td class="calculated spreadsheet-type-currency" data-numeric-value="32.4" data-string-value="32.4">$32.40</td> ' +
  53. '</tr> </tbody> </table>';
  54. const result = this.md(markdown);
  55. this.assertEqual(result, expected);
  56. }
  57. }