Rocketsoup пре 1 година
родитељ
комит
612a53bb53
2 измењених фајлова са 67 додато и 26 уклоњено
  1. 24
    23
      js/markdown.js
  2. 43
    3
      testjs.html

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

135
 	/** @var {String[]} */
135
 	/** @var {String[]} */
136
 	cssClasses = [];
136
 	cssClasses = [];
137
 	/** @var {String|null} */
137
 	/** @var {String|null} */
138
-	id = null;
138
+	cssId = null;
139
 	/** @var {Object} */
139
 	/** @var {Object} */
140
 	attributes = {};
140
 	attributes = {};
141
 
141
 
152
 		if (this.cssClasses.length > 0) {
152
 		if (this.cssClasses.length > 0) {
153
 			html += ` class="${this.cssClasses.join(' ')}"`;
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
 		for (const name in this.attributes) {
158
 		for (const name in this.attributes) {
159
 			let value = this.attributes[name];
159
 			let value = this.attributes[name];
290
 }
290
 }
291
 
291
 
292
 class _MDReferencedLinkSpan extends _MDLinkSpan {
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
 		super(null, content);
297
 		super(null, content);
298
-		this.id = id;
298
+		this.ref = ref;
299
 	}
299
 	}
300
 
300
 
301
 	/**
301
 	/**
303
 	 */
303
 	 */
304
 	toHTML(state) {
304
 	toHTML(state) {
305
 		if (!this.link) {
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
 			this.link = url;
308
 			this.link = url;
309
 			this.title = title || this.title;
309
 			this.title = title || this.title;
310
 		}
310
 		}
312
 			return super.toHTML(state);
312
 			return super.toHTML(state);
313
 		} else {
313
 		} else {
314
 			let contentHTML = this.content.toHTML(state);
314
 			let contentHTML = this.content.toHTML(state);
315
-			return `[${contentHTML}][${this.id}]`;
315
+			return `[${contentHTML}][${this.ref}]`;
316
 		}
316
 		}
317
 	}
317
 	}
318
 }
318
 }
422
 
422
 
423
 class _MDReferencedImageSpan extends _MDImageSpan {
423
 class _MDReferencedImageSpan extends _MDImageSpan {
424
 	/** @var {String} */
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
 		super(null, alt);
432
 		super(null, alt);
432
-		this.id = id;
433
+		this.ref = ref;
433
 	}
434
 	}
434
 
435
 
435
 	toHTML(state) {
436
 	toHTML(state) {
436
 		if (!this.source) {
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
 			this.source = url;
440
 			this.source = url;
440
 			this.title = title || this.title;
441
 			this.title = title || this.title;
441
 		}
442
 		}
442
 		if (this.source) {
443
 		if (this.source) {
443
 			return super.toHTML(state);
444
 			return super.toHTML(state);
444
 		} else {
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
 	/** @var {String[]} */
473
 	/** @var {String[]} */
473
 	cssClasses = [];
474
 	cssClasses = [];
474
 	/** @var {String|null} */
475
 	/** @var {String|null} */
475
-	id = null;
476
+	cssId = null;
476
 	/** @var {Object} */
477
 	/** @var {Object} */
477
 	attributes = {};
478
 	attributes = {};
478
 
479
 
488
 		if (this.cssClasses.length > 0) {
489
 		if (this.cssClasses.length > 0) {
489
 			html += ` class="${this.cssClasses.join(' ')}"`;
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
 		for (const name in this.attributes) {
495
 		for (const name in this.attributes) {
495
 			let value = this.attributes[name];
496
 			let value = this.attributes[name];
964
 	/** @var {String[]} */
965
 	/** @var {String[]} */
965
 	cssClasses = [];
966
 	cssClasses = [];
966
 	/** @var {String|null} */
967
 	/** @var {String|null} */
967
-	id = null;
968
+	cssId = null;
968
 	/** @var {Object} */
969
 	/** @var {Object} */
969
 	attributes = {};
970
 	attributes = {};
970
 
971
 
984
 	applyTo(elem) {
985
 	applyTo(elem) {
985
 		if (elem instanceof _MDBlock || elem instanceof _MDSpan) {
986
 		if (elem instanceof _MDBlock || elem instanceof _MDSpan) {
986
 			elem.cssClasses = elem.cssClasses.concat(this.cssClasses);
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
 			for (const name in this.attributes) {
989
 			for (const name in this.attributes) {
989
 				elem.attributes[name] = this.attributes[name];
990
 				elem.attributes[name] = this.attributes[name];
990
 			}
991
 			}
1001
 			if (groups = this.#classRegex.exec(token)) {
1002
 			if (groups = this.#classRegex.exec(token)) {
1002
 				mod.cssClasses.push(groups[1]);
1003
 				mod.cssClasses.push(groups[1]);
1003
 			} else if (groups = this.#idRegex.exec(token)) {
1004
 			} else if (groups = this.#idRegex.exec(token)) {
1004
-				mod.id = groups[1];
1005
+				mod.cssId = groups[1];
1005
 			} else if (groups = this.#attributeRegex.exec(token)) {
1006
 			} else if (groups = this.#attributeRegex.exec(token)) {
1006
 				mod.attributes[groups[1]] = groups[2];
1007
 				mod.attributes[groups[1]] = groups[2];
1007
 			} else {
1008
 			} else {

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

8
 			:root {
8
 			:root {
9
 				font-family: sans-serif;
9
 				font-family: sans-serif;
10
 			}
10
 			}
11
-			.testcase {
11
+			.testclass {
12
 				border: 1px solid black;
12
 				border: 1px solid black;
13
 				padding: 0.5em 1em;
13
 				padding: 0.5em 1em;
14
 				margin-bottom: 1em;
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
 			.testcasename {
29
 			.testcasename {
18
 				font-size: 115%;
30
 				font-size: 115%;
186
 				}
198
 				}
187
 				toHTML() {
199
 				toHTML() {
188
 					var html = `<div class="testcase" id="${this.#cssId}">`;
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
 					switch (this.result) {
202
 					switch (this.result) {
191
 						case ResultType.untested:
203
 						case ResultType.untested:
192
 							html += '<div class="testcasestatus result-untested">Waiting to test</div>';
204
 							html += '<div class="testcasestatus result-untested">Waiting to test</div>';
418
 					this.assertEqual(actual, expected);
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
 				test_link_email() {
440
 				test_link_email() {
422
 					let markdown = 'Lorem [ipsum](user@example.com) dolor';
441
 					let markdown = 'Lorem [ipsum](user@example.com) dolor';
423
 					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>';
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
 					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
501
 					let actual = normalizeWhitespace(Markdown.toHTML(markdown));
483
 					this.assertEqual(actual, expected);
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
 			document.addEventListener('DOMContentLoaded', onLoad);
527
 			document.addEventListener('DOMContentLoaded', onLoad);

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