Преглед изворни кода

Lots of cleanup, commenting

main
Rocketsoup пре 1 година
родитељ
комит
bc73ee66d7
3 измењених фајлова са 481 додато и 253 уклоњено
  1. 0
    9
      js/markdown.js
  2. 408
    228
      js/spreadsheet.js
  3. 73
    16
      testjs.html

+ 0
- 9
js/markdown.js Прегледај датотеку

1
-// FIXME: Nested blockquotes require blank line
2
-// TODO: HTML tags probably need better handling. Consider whether interior of matched tags should be interpreted as markdown.
3
-// TODO: Test broken/incomplete syntax thoroughly
4
-// TODO: Sanity checks on loops/recursion
5
-// TODO: Spreadsheet functions in tables
6
-// TODO: Support document differentiators for CSS identifiers (using markdown to render 2+ documents in the same page, need ids to be unique within the page)
7
-// TODO: Support language marker in ``` to at least add a CSS class to the <pre>
8
-// TODO: Better way to detect start of new block inside of list item without line break
9
-
10
 class MDTokenType {
1
 class MDTokenType {
11
 	static Text = new MDTokenType('Text');
2
 	static Text = new MDTokenType('Text');
12
 	static Whitespace = new MDTokenType('Whitespace');
3
 	static Whitespace = new MDTokenType('Whitespace');

+ 408
- 228
js/spreadsheet.js
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 73
- 16
testjs.html Прегледај датотеку

11
 				--color-failed: #a00;
11
 				--color-failed: #a00;
12
 				--color-errored: #a80;
12
 				--color-errored: #a80;
13
 				--color-untested: #888;
13
 				--color-untested: #888;
14
+				--color-background: #fff;
15
+				--color-text: #000;
16
+				--color-secondary: #888;
17
+				background-color: var(--color-background);
18
+				color: var(--color-text);
14
 			}
19
 			}
15
 			.testclass {
20
 			.testclass {
16
-				border: 1px solid black;
21
+				border: 1px solid var(--color-secondary);
17
 				padding: 0.5em 1em;
22
 				padding: 0.5em 1em;
18
 				margin-bottom: 1em;
23
 				margin-bottom: 1em;
19
 				max-width: 50em;
24
 				max-width: 50em;
23
 				font-size: 1.25rem;
28
 				font-size: 1.25rem;
24
 				padding-bottom: 0.25em;
29
 				padding-bottom: 0.25em;
25
 			}
30
 			}
26
-			.testclassstatus {
27
-
28
-			}
29
 			.testclassstatus.passed { color: var(--color-passed); }
31
 			.testclassstatus.passed { color: var(--color-passed); }
30
 			.testclassstatus.failed { color: var(--color-failed); }
32
 			.testclassstatus.failed { color: var(--color-failed); }
31
 			.testclassstatus.errored { color: var(--color-errored); }
33
 			.testclassstatus.errored { color: var(--color-errored); }
36
 				margin-left: 2em;
38
 				margin-left: 2em;
37
 			}
39
 			}
38
 			.testcase {
40
 			.testcase {
39
-				border-top: 1px solid #888;
41
+				border-top: 1px solid var(--color-secondary);
40
 			}
42
 			}
41
 			.testcasename {
43
 			.testcasename {
42
 				font-family: monospace;
44
 				font-family: monospace;
48
 			}
50
 			}
49
 			.testcasetiming {
51
 			.testcasetiming {
50
 				float: right;
52
 				float: right;
51
-				color: #888;
53
+				color: var(--color-secondary);
52
 				font-size: 80%;
54
 				font-size: 80%;
53
 			}
55
 			}
54
 			.testcaseresult {
56
 			.testcaseresult {
58
 				clear: both;
60
 				clear: both;
59
 			}
61
 			}
60
 			.result-untested {
62
 			.result-untested {
61
-				color: #888;
63
+				color: var(--color-untested);
62
 			}
64
 			}
63
 			.result-testing {
65
 			.result-testing {
64
-				color: black;
66
+				color: var(--color-text);
65
 			}
67
 			}
66
 			.result-passed {
68
 			.result-passed {
67
-				color: #090;
69
+				color: var(--color-passed);
68
 			}
70
 			}
69
 			.result-failed {
71
 			.result-failed {
70
-				color: #a00;
72
+				color: var(--color-failed);
71
 			}
73
 			}
72
 			.result-errored {
74
 			.result-errored {
73
-				color: #a80;
75
+				color: var(--color-errored);
76
+			}
77
+			@media (prefers-color-scheme: dark) {
78
+				:root {
79
+					--color-passed: #090;
80
+					--color-failed: #a00;
81
+					--color-errored: #a80;
82
+					--color-untested: #888;
83
+					--color-background: #000;
84
+					--color-text: #fff;
85
+					--color-secondary: #888;
86
+				}
74
 			}
87
 			}
75
 		</style>
88
 		</style>
76
 		<script src="js/markdown.js"></script>
89
 		<script src="js/markdown.js"></script>
424
 		<script>
437
 		<script>
425
 			function onLoad() {
438
 			function onLoad() {
426
 				let testClasses = [
439
 				let testClasses = [
427
-					// FIXME: Reenable these! Disabled temporarily to test spreadsheets faster.
428
-					// TokenTests,
429
-					// UtilsTests,
430
-					// InlineTests,
431
-					// BlockTests,
440
+					TokenTests,
441
+					UtilsTests,
442
+					InlineTests,
443
+					BlockTests,
432
 					CellValueTests,
444
 					CellValueTests,
433
 					CellAddressRangeTests,
445
 					CellAddressRangeTests,
434
 					ExpressionSetTests,
446
 					ExpressionSetTests,
447
+					SpreadsheetMarkdownIntegrationTests,
435
 				];
448
 				];
436
 				TestClassRunner.runAll(testClasses);
449
 				TestClassRunner.runAll(testClasses);
437
 			}
450
 			}
1555
 					this._test_simple_formula('=AND(FALSE, TRUE)', false);
1568
 					this._test_simple_formula('=AND(FALSE, TRUE)', false);
1556
 					this._test_simple_formula('=AND(TRUE, FALSE)', false);
1569
 					this._test_simple_formula('=AND(TRUE, FALSE)', false);
1557
 					this._test_simple_formula('=AND(TRUE, TRUE)', true);
1570
 					this._test_simple_formula('=AND(TRUE, TRUE)', true);
1571
+					this._test_simple_formula('=AND(TRUE, TRUE, TRUE, TRUE)', true);
1572
+					this._test_simple_formula('=AND(TRUE, TRUE, TRUE, FALSE)', false);
1558
 				}
1573
 				}
1559
 
1574
 
1560
 				test_func_average() {
1575
 				test_func_average() {
1638
 					this._test_simple_formula('=ROUND(-3.1)', -3);
1653
 					this._test_simple_formula('=ROUND(-3.1)', -3);
1639
 					this._test_simple_formula('=ROUND(-3.5)', -3);
1654
 					this._test_simple_formula('=ROUND(-3.5)', -3);
1640
 					this._test_simple_formula('=ROUND(-3.9)', -4);
1655
 					this._test_simple_formula('=ROUND(-3.9)', -4);
1656
+					this._test_simple_formula('=ROUND(3.1415926535, 1)', 3.1);
1657
+					this._test_simple_formula('=ROUND(3.1415926535, 2)', 3.14);
1658
+					this._test_simple_formula('=ROUND(31.415926535, -1)', 30);
1641
 				}
1659
 				}
1642
 
1660
 
1643
 				test_func_sqrt() {
1661
 				test_func_sqrt() {
1671
 					this._test_simple_formula('=2.718281828459045 ; currency 2', new CellValue('$2.72', 2.718281828459045, 'currency', 2));
1689
 					this._test_simple_formula('=2.718281828459045 ; currency 2', new CellValue('$2.72', 2.718281828459045, 'currency', 2));
1672
 				}
1690
 				}
1673
 			}
1691
 			}
1692
+
1693
+			class SpreadsheetMarkdownIntegrationTests extends BaseTest {
1694
+				parser;
1695
+
1696
+				setUp() {
1697
+					this.parser = new Markdown([ ...Markdown.allBlockReaders, new SpreadsheetBlockReader() ], Markdown.allInlineReaders);
1698
+				}
1699
+
1700
+				md(markdown) {
1701
+					return normalizeWhitespace(this.parser.toHTML(markdown));
1702
+				}
1703
+
1704
+				test_integration() {
1705
+					const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | =A*B |';
1706
+					const expected = '<table> <thead> ' +
1707
+						'<tr> <th>A</th> <th>B</th> <th>C</th> </tr> ' +
1708
+						'</thead> <tbody> <tr> ' +
1709
+						'<td class="spreadsheet-type-number" data-numeric-value="3" data-string-value="3">3</td> ' +
1710
+						'<td class="spreadsheet-type-number" data-numeric-value="4" data-string-value="4">4</td> ' +
1711
+						'<td class="calculated spreadsheet-type-number" data-numeric-value="12" data-string-value="12">12</td> ' +
1712
+						'</tr> </tbody> </table>';
1713
+					const result = this.md(markdown);
1714
+					this.assertEqual(result, expected);
1715
+				}
1716
+
1717
+				test_bailOut() {
1718
+					// If no formulas found table isn't modified
1719
+					const markdown = '| A | B | C |\n| --- | --- | --- |\n| 3 | 4 | A*B |';
1720
+					const expected = '<table> <thead> ' +
1721
+						'<tr> <th>A</th> <th>B</th> <th>C</th> </tr> ' +
1722
+						'</thead> <tbody> <tr> ' +
1723
+						'<td>3</td> ' +
1724
+						'<td>4</td> ' +
1725
+						'<td>A*B</td> ' +
1726
+						'</tr> </tbody> </table>';
1727
+					const result = this.md(markdown);
1728
+					this.assertEqual(result, expected);
1729
+				}
1730
+			}
1674
 		</script>
1731
 		</script>
1675
 	</head>
1732
 	</head>
1676
 	<body>
1733
 	<body>

Loading…
Откажи
Сачувај