Ver código fonte

Ordered lists indexed from number of first item

main
Rocketsoup 1 ano atrás
pai
commit
78c9c539fb
1 arquivos alterados com 23 adições e 7 exclusões
  1. 23
    7
      js/markdown.js

+ 23
- 7
js/markdown.js Ver arquivo

@@ -1,3 +1,5 @@
1
+// FIXME: Nested lists not working right
2
+// FIXME: Nested blockquotes require blank line
1 3
 // TODO: HTML tags probably need better handling. Consider whether interior of matched tags should be interpreted as markdown.
2 4
 // TODO: {.class #cssid lang=fr}
3 5
 //     # Header {.class}
@@ -5,9 +7,6 @@
5 7
 //     ---
6 8
 //     [link](url){.class}
7 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 11
 class _MDHAlign {
13 12
 	static Left = new _MDHAlign('Left');
@@ -561,12 +560,24 @@ class _MDOrderedListBlock extends _MDBlock {
561 560
 	/** @var {_MDListItemBlock[]} */
562 561
 	items;
563 562
 
563
+	/** @var {Number|null} */
564
+	startOrdinal;
565
+
564 566
 	/**
565 567
 	 * @param {_MDListItemBlock[]} items
566 568
 	 */
567
-	constructor(items) {
569
+	constructor(items, startOrdinal=null) {
568 570
 		super();
569 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 583
 	toHTML(state) {
@@ -578,13 +589,16 @@ class _MDOrderedListBlock extends _MDBlock {
578 589
 class _MDListItemBlock extends _MDBlock {
579 590
 	/** @var {_MDBlock} */
580 591
 	content;
592
+	/** @var {Number|null} */
593
+	ordinal;
581 594
 
582 595
 	/**
583 596
 	 * @param {_MDBlock} content
584 597
 	 */
585
-	constructor(content) {
598
+	constructor(content, ordinal=null) {
586 599
 		super();
587 600
 		this.content = content;
601
+		this.ordinal = ordinal;
588 602
 	}
589 603
 
590 604
 	toHTML(state) {
@@ -1627,7 +1641,9 @@ class Markdown {
1627 1641
 		let line = state.lines[p];
1628 1642
 		let groups = this.#orderedListRegex.exec(line);
1629 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,7 +1658,7 @@ class Markdown {
1642 1658
 			if (item) items.push(item);
1643 1659
 		} while (item);
1644 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
 	/**

Carregando…
Cancelar
Salvar