Pārlūkot izejas kodu

Ordered lists indexed from number of first item

main
Rocketsoup 1 gadu atpakaļ
vecāks
revīzija
78c9c539fb
1 mainītis faili ar 23 papildinājumiem un 7 dzēšanām
  1. 23
    7
      js/markdown.js

+ 23
- 7
js/markdown.js Parādīt failu

1
+// FIXME: Nested lists not working right
2
+// FIXME: Nested blockquotes require blank line
1
 // TODO: HTML tags probably need better handling. Consider whether interior of matched tags should be interpreted as markdown.
3
 // TODO: HTML tags probably need better handling. Consider whether interior of matched tags should be interpreted as markdown.
2
 // TODO: {.class #cssid lang=fr}
4
 // TODO: {.class #cssid lang=fr}
3
 //     # Header {.class}
5
 //     # Header {.class}
5
 //     ---
7
 //     ---
6
 //     [link](url){.class}
8
 //     [link](url){.class}
7
 //     ``` {.class}
9
 //     ``` {.class}
8
-// FIXME: Nested lists not working right
9
-// FIXME: Nested blockquotes require blank line
10
-// FIXME: Ordered list should start with first number
11
 
10
 
12
 class _MDHAlign {
11
 class _MDHAlign {
13
 	static Left = new _MDHAlign('Left');
12
 	static Left = new _MDHAlign('Left');
561
 	/** @var {_MDListItemBlock[]} */
560
 	/** @var {_MDListItemBlock[]} */
562
 	items;
561
 	items;
563
 
562
 
563
+	/** @var {Number|null} */
564
+	startOrdinal;
565
+
564
 	/**
566
 	/**
565
 	 * @param {_MDListItemBlock[]} items
567
 	 * @param {_MDListItemBlock[]} items
566
 	 */
568
 	 */
567
-	constructor(items) {
569
+	constructor(items, startOrdinal=null) {
568
 		super();
570
 		super();
569
 		this.items = items;
571
 		this.items = items;
572
+		this.startOrdinal = startOrdinal;
573
+	}
574
+
575
+	htmlAttributes() {
576
+		var html = super.htmlAttributes();
577
+		if (this.startOrdinal !== null) {
578
+			html += ` start="${this.startOrdinal}"`;
579
+		}
580
+		return html;
570
 	}
581
 	}
571
 
582
 
572
 	toHTML(state) {
583
 	toHTML(state) {
578
 class _MDListItemBlock extends _MDBlock {
589
 class _MDListItemBlock extends _MDBlock {
579
 	/** @var {_MDBlock} */
590
 	/** @var {_MDBlock} */
580
 	content;
591
 	content;
592
+	/** @var {Number|null} */
593
+	ordinal;
581
 
594
 
582
 	/**
595
 	/**
583
 	 * @param {_MDBlock} content
596
 	 * @param {_MDBlock} content
584
 	 */
597
 	 */
585
-	constructor(content) {
598
+	constructor(content, ordinal=null) {
586
 		super();
599
 		super();
587
 		this.content = content;
600
 		this.content = content;
601
+		this.ordinal = ordinal;
588
 	}
602
 	}
589
 
603
 
590
 	toHTML(state) {
604
 	toHTML(state) {
1627
 		let line = state.lines[p];
1641
 		let line = state.lines[p];
1628
 		let groups = this.#orderedListRegex.exec(line);
1642
 		let groups = this.#orderedListRegex.exec(line);
1629
 		if (groups === null) return null;
1643
 		if (groups === null) return null;
1630
-		return new _MDListItemBlock(this.#readInteriorContent(state, groups[1].length + groups[2].length, this.#orderedListItemRegex, true));
1644
+		let ordinal = parseInt(groups[1]);
1645
+		let content = this.#readInteriorContent(state, groups[1].length + groups[2].length, this.#orderedListItemRegex, true);
1646
+		return new _MDListItemBlock(content, ordinal);
1631
 	}
1647
 	}
1632
 
1648
 
1633
 	/**
1649
 	/**
1642
 			if (item) items.push(item);
1658
 			if (item) items.push(item);
1643
 		} while (item);
1659
 		} while (item);
1644
 		if (items.length == 0) return null;
1660
 		if (items.length == 0) return null;
1645
-		return new _MDOrderedListBlock(items);
1661
+		return new _MDOrderedListBlock(items, items[0].ordinal);
1646
 	}
1662
 	}
1647
 
1663
 
1648
 	/**
1664
 	/**

Notiek ielāde…
Atcelt
Saglabāt