瀏覽代碼

More tests

main
Rocketsoup 1 年之前
父節點
當前提交
612a53bb53
共有 2 個檔案被更改,包括 67 行新增26 行删除
  1. 24
    23
      js/markdown.js
  2. 43
    3
      testjs.html

+ 24
- 23
js/markdown.js 查看文件

@@ -135,7 +135,7 @@ class _MDSpan {
135 135
 	/** @var {String[]} */
136 136
 	cssClasses = [];
137 137
 	/** @var {String|null} */
138
-	id = null;
138
+	cssId = null;
139 139
 	/** @var {Object} */
140 140
 	attributes = {};
141 141
 
@@ -152,8 +152,8 @@ class _MDSpan {
152 152
 		if (this.cssClasses.length > 0) {
153 153
 			html += ` class="${this.cssClasses.join(' ')}"`;
154 154
 		}
155
-		if (this.id !== null) {
156
-			html += ` id="${this.id}"`;
155
+		if (this.cssId !== null) {
156
+			html += ` id="${this.cssId}"`;
157 157
 		}
158 158
 		for (const name in this.attributes) {
159 159
 			let value = this.attributes[name];
@@ -290,12 +290,12 @@ class _MDLinkSpan extends _MDSpan {
290 290
 }
291 291
 
292 292
 class _MDReferencedLinkSpan extends _MDLinkSpan {
293
-	/** @var {String} id */
294
-	id;
293
+	/** @var {String} */
294
+	ref;
295 295
 
296
-	constructor(id, content) {
296
+	constructor(ref, content) {
297 297
 		super(null, content);
298
-		this.id = id;
298
+		this.ref = ref;
299 299
 	}
300 300
 
301 301
 	/**
@@ -303,8 +303,8 @@ class _MDReferencedLinkSpan extends _MDLinkSpan {
303 303
 	 */
304 304
 	toHTML(state) {
305 305
 		if (!this.link) {
306
-			let url = state.urls[this.id.toLowerCase()];
307
-			let title = state.urlTitles[this.id.toLowerCase()];
306
+			let url = state.urls[this.ref.toLowerCase()];
307
+			let title = state.urlTitles[this.ref.toLowerCase()];
308 308
 			this.link = url;
309 309
 			this.title = title || this.title;
310 310
 		}
@@ -312,7 +312,7 @@ class _MDReferencedLinkSpan extends _MDLinkSpan {
312 312
 			return super.toHTML(state);
313 313
 		} else {
314 314
 			let contentHTML = this.content.toHTML(state);
315
-			return `[${contentHTML}][${this.id}]`;
315
+			return `[${contentHTML}][${this.ref}]`;
316 316
 		}
317 317
 	}
318 318
 }
@@ -422,27 +422,28 @@ class _MDImageSpan extends _MDSpan {
422 422
 
423 423
 class _MDReferencedImageSpan extends _MDImageSpan {
424 424
 	/** @var {String} */
425
-	id;
425
+	ref;
426 426
 
427 427
 	/**
428
-	 * @param {String} id
428
+	 * @param {String} ref
429
+	 * @param {String|null} alt
429 430
 	 */
430
-	constructor(id, alt) {
431
+	constructor(ref, alt) {
431 432
 		super(null, alt);
432
-		this.id = id;
433
+		this.ref = ref;
433 434
 	}
434 435
 
435 436
 	toHTML(state) {
436 437
 		if (!this.source) {
437
-			let url = state.urls[this.id.toLowerCase()];
438
-			let title = state.urlTitles[this.id.toLowerCase()];
438
+			let url = state.urls[this.ref.toLowerCase()];
439
+			let title = state.urlTitles[this.ref.toLowerCase()];
439 440
 			this.source = url;
440 441
 			this.title = title || this.title;
441 442
 		}
442 443
 		if (this.source) {
443 444
 			return super.toHTML(state);
444 445
 		} else {
445
-			return `![${_MDUtils.escapeHTML(this.alt)}][${_MDUtils.escapeHTML(this.id)}]`;
446
+			return `![${_MDUtils.escapeHTML(this.alt)}][${_MDUtils.escapeHTML(this.ref)}]`;
446 447
 		}
447 448
 	}
448 449
 }
@@ -472,7 +473,7 @@ class _MDBlock {
472 473
 	/** @var {String[]} */
473 474
 	cssClasses = [];
474 475
 	/** @var {String|null} */
475
-	id = null;
476
+	cssId = null;
476 477
 	/** @var {Object} */
477 478
 	attributes = {};
478 479
 
@@ -488,8 +489,8 @@ class _MDBlock {
488 489
 		if (this.cssClasses.length > 0) {
489 490
 			html += ` class="${this.cssClasses.join(' ')}"`;
490 491
 		}
491
-		if (this.id !== null) {
492
-			html += ` id="${this.id}"`;
492
+		if (this.cssId !== null) {
493
+			html += ` id="${this.cssId}"`;
493 494
 		}
494 495
 		for (const name in this.attributes) {
495 496
 			let value = this.attributes[name];
@@ -964,7 +965,7 @@ class _MDTagModifier {
964 965
 	/** @var {String[]} */
965 966
 	cssClasses = [];
966 967
 	/** @var {String|null} */
967
-	id = null;
968
+	cssId = null;
968 969
 	/** @var {Object} */
969 970
 	attributes = {};
970 971
 
@@ -984,7 +985,7 @@ class _MDTagModifier {
984 985
 	applyTo(elem) {
985 986
 		if (elem instanceof _MDBlock || elem instanceof _MDSpan) {
986 987
 			elem.cssClasses = elem.cssClasses.concat(this.cssClasses);
987
-			if (this.id) elem.id = this.id;
988
+			if (this.cssId) elem.cssId = this.cssId;
988 989
 			for (const name in this.attributes) {
989 990
 				elem.attributes[name] = this.attributes[name];
990 991
 			}
@@ -1001,7 +1002,7 @@ class _MDTagModifier {
1001 1002
 			if (groups = this.#classRegex.exec(token)) {
1002 1003
 				mod.cssClasses.push(groups[1]);
1003 1004
 			} else if (groups = this.#idRegex.exec(token)) {
1004
-				mod.id = groups[1];
1005
+				mod.cssId = groups[1];
1005 1006
 			} else if (groups = this.#attributeRegex.exec(token)) {
1006 1007
 				mod.attributes[groups[1]] = groups[2];
1007 1008
 			} else {

+ 43
- 3
testjs.html 查看文件

@@ -8,11 +8,23 @@
8 8
 			:root {
9 9
 				font-family: sans-serif;
10 10
 			}
11
-			.testcase {
11
+			.testclass {
12 12
 				border: 1px solid black;
13 13
 				padding: 0.5em 1em;
14 14
 				margin-bottom: 1em;
15
-				max-width: 70em;
15
+				max-width: 50em;
16
+			}
17
+			.testclassname {
18
+				font-weight: bold;
19
+				font-size: 1.25rem;
20
+				padding-bottom: 0.25em;
21
+			}
22
+			.testcase {
23
+				padding: 0.2em 0;
24
+				margin-left: 2em;
25
+			}
26
+			.testcase {
27
+				border-top: 1px solid #888;
16 28
 			}
17 29
 			.testcasename {
18 30
 				font-size: 115%;
@@ -186,7 +198,7 @@
186 198
 				}
187 199
 				toHTML() {
188 200
 					var html = `<div class="testcase" id="${this.#cssId}">`;
189
-					html += `<div class="testcasename"><span class="testcaseclass">${this.className}</span>.<span class="testcasemethod">${this.methodName}</span></div>`;
201
+					html += `<div class="testcasename"><span class="testcasemethod">${this.methodName}</span></div>`;
190 202
 					switch (this.result) {
191 203
 						case ResultType.untested:
192 204
 							html += '<div class="testcasestatus result-untested">Waiting to test</div>';
@@ -418,6 +430,13 @@
418 430
 					this.assertEqual(actual, expected);
419 431
 				}
420 432
 
433
+				test_link_ref() {
434
+					let markdown = "Lorem [ipsum][ref] dolor\n\n[ref]: https://example.com";
435
+					let expected = '<p>Lorem <a href="https://example.com">ipsum</a> dolor</p>';
436
+					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
437
+					this.assertEqual(actual, expected);
438
+				}
439
+
421 440
 				test_link_email() {
422 441
 					let markdown = 'Lorem [ipsum](user@example.com) dolor';
423 442
 					let expected = '<p>Lorem <a href="mailto:&#117;&#115;&#101;&#114;&#64;&#101;&#120;&#97;&#109;&#112;&#108;&#101;&#46;&#99;&#111;&#109;">ipsum</a> dolor</p>';
@@ -482,6 +501,27 @@
482 501
 					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
483 502
 					this.assertEqual(actual, expected);
484 503
 				}
504
+
505
+				test_orderedList() {
506
+					let markdown = "1. Lorem\n1. Ipsum\n5. Dolor";
507
+					let expected = '<ol start="1"> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ol>';
508
+					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
509
+					this.assertEqual(actual, expected);
510
+				}
511
+
512
+				test_orderedList_numbering() {
513
+					let markdown = "4. Lorem\n1. Ipsum\n9. Dolor";
514
+					let expected = '<ol start="4"> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ol>';
515
+					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
516
+					this.assertEqual(actual, expected);
517
+				}
518
+
519
+				test_blockquote() {
520
+					let markdown = '> Lorem ipsum dolor';
521
+					let expected = '<blockquote> <p>Lorem ipsum dolor</p> </blockquote>';
522
+					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
523
+					this.assertEqual(actual, expected);
524
+				}
485 525
 			}
486 526
 
487 527
 			document.addEventListener('DOMContentLoaded', onLoad);

Loading…
取消
儲存