|
|
@@ -7,6 +7,8 @@
|
|
7
|
7
|
// ---
|
|
8
|
8
|
// [link](url){.class}
|
|
9
|
9
|
// ``` {.class}
|
|
|
10
|
+// TODO: Test broken/incomplete syntax thoroughly
|
|
|
11
|
+// TODO: Sanity checks on loops/recursion?
|
|
10
|
12
|
|
|
11
|
13
|
class _MDHAlign {
|
|
12
|
14
|
static Left = new _MDHAlign('Left');
|
|
|
@@ -920,7 +922,7 @@ class Markdown {
|
|
920
|
922
|
* @param {String} line
|
|
921
|
923
|
*/
|
|
922
|
924
|
static #stripIndent(line, count=1) {
|
|
923
|
|
- let regex = new RegExp(`^(: {1,4}|\\t){${count}}`);
|
|
|
925
|
+ let regex = new RegExp(`^(?: {1,4}|\\t){${count}}`);
|
|
924
|
926
|
return line.replace(regex, '');
|
|
925
|
927
|
}
|
|
926
|
928
|
|
|
|
@@ -1497,7 +1499,9 @@ class Markdown {
|
|
1497
|
1499
|
var seenBlankLine = false;
|
|
1498
|
1500
|
var needsBlocks = false;
|
|
1499
|
1501
|
var lines = [];
|
|
1500
|
|
- while (p < state.lines.length) {
|
|
|
1502
|
+ var hasNestedList = false;
|
|
|
1503
|
+ var firstNestedListLine = -1;
|
|
|
1504
|
+ while (state.hasLines(1, p)) {
|
|
1501
|
1505
|
let line = state.lines[p++];
|
|
1502
|
1506
|
if (p == state.p + 1) {
|
|
1503
|
1507
|
line = line.substring(firstLineStartPos);
|
|
|
@@ -1514,6 +1518,12 @@ class Markdown {
|
|
1514
|
1518
|
if (seenBlankLine) {
|
|
1515
|
1519
|
needsBlocks = true;
|
|
1516
|
1520
|
}
|
|
|
1521
|
+ if (inList && /^\s*(?:\*|\+|\-|\d+\.)\s+/.exec(line)) {
|
|
|
1522
|
+ hasNestedList = true;
|
|
|
1523
|
+ if (firstNestedListLine < 0) {
|
|
|
1524
|
+ firstNestedListLine = lines.length;
|
|
|
1525
|
+ }
|
|
|
1526
|
+ }
|
|
1517
|
1527
|
lines.push(this.#stripIndent(line));
|
|
1518
|
1528
|
} else {
|
|
1519
|
1529
|
if (seenBlankLine) {
|
|
|
@@ -1526,6 +1536,15 @@ class Markdown {
|
|
1526
|
1536
|
while (lines.length > 0 && lines[lines.length - 1].trim().length == 0) {
|
|
1527
|
1537
|
lines.pop();
|
|
1528
|
1538
|
}
|
|
|
1539
|
+ if (inList && hasNestedList) {
|
|
|
1540
|
+ let parentLines = lines.slice(0, firstNestedListLine);
|
|
|
1541
|
+ let parentContent = this.#readInline(state, parentLines.join("\n"));
|
|
|
1542
|
+ let nestedLines = lines.slice(firstNestedListLine);
|
|
|
1543
|
+ let substate = state.copy(nestedLines);
|
|
|
1544
|
+ let nestedContent = this.#readBlocks(substate);
|
|
|
1545
|
+ state.p = p;
|
|
|
1546
|
+ return new _MDMultiBlock([parentContent].concat(nestedContent));
|
|
|
1547
|
+ }
|
|
1529
|
1548
|
if (needsBlocks) {
|
|
1530
|
1549
|
let substate = state.copy(lines);
|
|
1531
|
1550
|
let blocks = this.#readBlocks(substate);
|