Skip to content

Commit b4175d7

Browse files
author
MarkedJS bot
committed
🗜️ build [skip ci]
1 parent 5f9cafd commit b4175d7

File tree

3 files changed

+67
-35
lines changed

3 files changed

+67
-35
lines changed

lib/marked.esm.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ var Tokenizer_1 = class Tokenizer {
509509
let raw = cap[0];
510510
const bull = cap[2];
511511
const isordered = bull.length > 1;
512-
const isparen = bull[bull.length - 1] === ')';
513512

514513
const list = {
515514
type: 'list',
@@ -526,17 +525,45 @@ var Tokenizer_1 = class Tokenizer {
526525
let next = false,
527526
item,
528527
space,
529-
b,
528+
bcurr,
529+
bnext,
530530
addBack,
531531
loose,
532532
istask,
533533
ischecked;
534534

535-
const l = itemMatch.length;
535+
let l = itemMatch.length;
536+
bcurr = this.rules.block.listItemStart.exec(itemMatch[0]);
536537
for (let i = 0; i < l; i++) {
537538
item = itemMatch[i];
538539
raw = item;
539540

541+
// Determine whether the next list item belongs here.
542+
// Backpedal if it does not belong in this list.
543+
if (i !== l - 1) {
544+
bnext = this.rules.block.listItemStart.exec(itemMatch[i + 1]);
545+
546+
if (bnext[1].length > bcurr[0].length || bnext[1].length > 3) {
547+
// nested list
548+
itemMatch.splice(i, 2, itemMatch[i] + '\n' + itemMatch[i + 1]);
549+
i--;
550+
l--;
551+
continue;
552+
} else {
553+
if (
554+
// different bullet style
555+
!this.options.pedantic || this.options.smartLists
556+
? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1]
557+
: isordered === (bnext[2].length === 1)
558+
) {
559+
addBack = itemMatch.slice(i + 1).join('\n');
560+
list.raw = list.raw.substring(0, list.raw.length - addBack.length);
561+
i = l - 1;
562+
}
563+
}
564+
bcurr = bnext;
565+
}
566+
540567
// Remove the list item's bullet
541568
// so it is seen as the next token.
542569
space = item.length;
@@ -551,18 +578,6 @@ var Tokenizer_1 = class Tokenizer {
551578
: item.replace(/^ {1,4}/gm, '');
552579
}
553580

554-
// Determine whether the next list item belongs here.
555-
// Backpedal if it does not belong in this list.
556-
if (i !== l - 1) {
557-
b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
558-
if (isordered ? b.length === 1 || (!isparen && b[b.length - 1] === ')')
559-
: (b.length > 1 || (this.options.smartLists && b !== bull))) {
560-
addBack = itemMatch.slice(i + 1).join('\n');
561-
list.raw = list.raw.substring(0, list.raw.length - addBack.length);
562-
i = l - 1;
563-
}
564-
}
565-
566581
// Determine whether item is loose or not.
567582
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
568583
// for discount behavior.
@@ -988,7 +1003,7 @@ const block = {
9881003
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
9891004
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
9901005
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
991-
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
1006+
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?! {0,3}bull )\n*|\s*$)/,
9921007
html: '^ {0,3}(?:' // optional indentation
9931008
+ '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
9941009
+ '|comment[^\\n]*(\\n+|$)' // (2)
@@ -1017,11 +1032,15 @@ block.def = edit$1(block.def)
10171032
.getRegex();
10181033

10191034
block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1020-
block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
1035+
block.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
10211036
block.item = edit$1(block.item, 'gm')
10221037
.replace(/bull/g, block.bullet)
10231038
.getRegex();
10241039

1040+
block.listItemStart = edit$1(/^( *)(bull)/)
1041+
.replace('bull', block.bullet)
1042+
.getRegex();
1043+
10251044
block.list = edit$1(block.list)
10261045
.replace(/bull/g, block.bullet)
10271046
.replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))')

lib/marked.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@
611611
var raw = cap[0];
612612
var bull = cap[2];
613613
var isordered = bull.length > 1;
614-
var isparen = bull[bull.length - 1] === ')';
615614
var list = {
616615
type: 'list',
617616
raw: raw,
@@ -625,37 +624,50 @@
625624
var next = false,
626625
item,
627626
space,
628-
b,
627+
bcurr,
628+
bnext,
629629
addBack,
630630
loose,
631631
istask,
632632
ischecked;
633633
var l = itemMatch.length;
634+
bcurr = this.rules.block.listItemStart.exec(itemMatch[0]);
634635

635636
for (var i = 0; i < l; i++) {
636637
item = itemMatch[i];
637-
raw = item; // Remove the list item's bullet
638+
raw = item; // Determine whether the next list item belongs here.
639+
// Backpedal if it does not belong in this list.
640+
641+
if (i !== l - 1) {
642+
bnext = this.rules.block.listItemStart.exec(itemMatch[i + 1]);
643+
644+
if (bnext[1].length > bcurr[0].length || bnext[1].length > 3) {
645+
// nested list
646+
itemMatch.splice(i, 2, itemMatch[i] + '\n' + itemMatch[i + 1]);
647+
i--;
648+
l--;
649+
continue;
650+
} else {
651+
if ( // different bullet style
652+
!this.options.pedantic || this.options.smartLists ? bnext[2][bnext[2].length - 1] !== bull[bull.length - 1] : isordered === (bnext[2].length === 1)) {
653+
addBack = itemMatch.slice(i + 1).join('\n');
654+
list.raw = list.raw.substring(0, list.raw.length - addBack.length);
655+
i = l - 1;
656+
}
657+
}
658+
659+
bcurr = bnext;
660+
} // Remove the list item's bullet
638661
// so it is seen as the next token.
639662

663+
640664
space = item.length;
641665
item = item.replace(/^ *([*+-]|\d+[.)]) ?/, ''); // Outdent whatever the
642666
// list item contains. Hacky.
643667

644668
if (~item.indexOf('\n ')) {
645669
space -= item.length;
646670
item = !this.options.pedantic ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '') : item.replace(/^ {1,4}/gm, '');
647-
} // Determine whether the next list item belongs here.
648-
// Backpedal if it does not belong in this list.
649-
650-
651-
if (i !== l - 1) {
652-
b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
653-
654-
if (isordered ? b.length === 1 || !isparen && b[b.length - 1] === ')' : b.length > 1 || this.options.smartLists && b !== bull) {
655-
addBack = itemMatch.slice(i + 1).join('\n');
656-
list.raw = list.raw.substring(0, list.raw.length - addBack.length);
657-
i = l - 1;
658-
}
659671
} // Determine whether item is loose or not.
660672
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
661673
// for discount behavior.
@@ -1110,7 +1122,7 @@
11101122
hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
11111123
heading: /^ {0,3}(#{1,6}) +([^\n]*?)(?: +#+)? *(?:\n+|$)/,
11121124
blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1113-
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
1125+
list: /^( {0,3})(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?! {0,3}bull )\n*|\s*$)/,
11141126
html: '^ {0,3}(?:' // optional indentation
11151127
+ '<(script|pre|style)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
11161128
+ '|comment[^\\n]*(\\n+|$)' // (2)
@@ -1134,8 +1146,9 @@
11341146
block._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
11351147
block.def = edit$1(block.def).replace('label', block._label).replace('title', block._title).getRegex();
11361148
block.bullet = /(?:[*+-]|\d{1,9}[.)])/;
1137-
block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
1149+
block.item = /^( *)(bull) ?[^\n]*(?:\n(?! *bull ?)[^\n]*)*/;
11381150
block.item = edit$1(block.item, 'gm').replace(/bull/g, block.bullet).getRegex();
1151+
block.listItemStart = edit$1(/^( *)(bull)/).replace('bull', block.bullet).getRegex();
11391152
block.list = edit$1(block.list).replace(/bull/g, block.bullet).replace('hr', '\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))').replace('def', '\\n+(?=' + block.def.source + ')').getRegex();
11401153
block._tag = 'address|article|aside|base|basefont|blockquote|body|caption' + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption' + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe' + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option' + '|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr' + '|track|ul';
11411154
block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;

0 commit comments

Comments
 (0)