Changed markdown lexer to ignore lists containing only one item
Этот коммит содержится в:
@@ -289,74 +289,78 @@ class MattermostLexer extends marked.Lexer {
|
|||||||
// list
|
// list
|
||||||
cap = this.rules.list.exec(src);
|
cap = this.rules.list.exec(src);
|
||||||
if (cap) {
|
if (cap) {
|
||||||
src = src.substring(cap[0].length);
|
|
||||||
const bull = cap[2];
|
const bull = cap[2];
|
||||||
|
let l = cap[0].length;
|
||||||
this.tokens.push({
|
|
||||||
type: 'list_start',
|
|
||||||
ordered: bull.length > 1
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get each top-level item.
|
// Get each top-level item.
|
||||||
cap = cap[0].match(this.rules.item);
|
cap = cap[0].match(this.rules.item);
|
||||||
|
|
||||||
let next = false;
|
if (cap.length > 1) {
|
||||||
const l = cap.length;
|
src = src.substring(l);
|
||||||
|
|
||||||
for (let i = 0; i < l; i++) {
|
this.tokens.push({
|
||||||
let item = cap[i];
|
type: 'list_start',
|
||||||
|
ordered: bull.length > 1
|
||||||
|
});
|
||||||
|
|
||||||
// Remove the list item's bullet
|
let next = false;
|
||||||
// so it is seen as the next token.
|
l = cap.length;
|
||||||
let space = item.length;
|
|
||||||
item = item.replace(/^ *([*+-]|\d+\.) +/, '');
|
|
||||||
|
|
||||||
// Outdent whatever the
|
for (let i = 0; i < l; i++) {
|
||||||
// list item contains. Hacky.
|
let item = cap[i];
|
||||||
if (~item.indexOf('\n ')) {
|
|
||||||
space -= item.length;
|
|
||||||
item = this.options.pedantic ? item.replace(/^ {1,4}/gm, '') : item.replace(new RegExp('^ \{1,' + space + '\}', 'gm'), '');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine whether the next list item belongs here.
|
// Remove the list item's bullet
|
||||||
// Backpedal if it does not belong in this list.
|
// so it is seen as the next token.
|
||||||
if (this.options.smartLists && i !== l - 1) {
|
let space = item.length;
|
||||||
const bullet = /(?:[*+-]|\d+\.)/;
|
item = item.replace(/^ *([*+-]|\d+\.) +/, '');
|
||||||
const b = bullet.exec(cap[i + 1])[0];
|
|
||||||
if (bull !== b && !(bull.length > 1 && b.length > 1)) {
|
// Outdent whatever the
|
||||||
src = cap.slice(i + 1).join('\n') + src;
|
// list item contains. Hacky.
|
||||||
i = l - 1;
|
if (~item.indexOf('\n ')) {
|
||||||
|
space -= item.length;
|
||||||
|
item = this.options.pedantic ? item.replace(/^ {1,4}/gm, '') : item.replace(new RegExp('^ \{1,' + space + '\}', 'gm'), '');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Determine whether item is loose or not.
|
// Determine whether the next list item belongs here.
|
||||||
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
// Backpedal if it does not belong in this list.
|
||||||
// for discount behavior.
|
if (this.options.smartLists && i !== l - 1) {
|
||||||
let loose = next || (/\n\n(?!\s*$)/).test(item);
|
const bullet = /(?:[*+-]|\d+\.)/;
|
||||||
if (i !== l - 1) {
|
const b = bullet.exec(cap[i + 1])[0];
|
||||||
next = item.charAt(item.length - 1) === '\n';
|
if (bull !== b && !(bull.length > 1 && b.length > 1)) {
|
||||||
if (!loose) {
|
src = cap.slice(i + 1).join('\n') + src;
|
||||||
loose = next;
|
i = l - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine whether item is loose or not.
|
||||||
|
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
||||||
|
// for discount behavior.
|
||||||
|
let loose = next || (/\n\n(?!\s*$)/).test(item);
|
||||||
|
if (i !== l - 1) {
|
||||||
|
next = item.charAt(item.length - 1) === '\n';
|
||||||
|
if (!loose) {
|
||||||
|
loose = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tokens.push({
|
||||||
|
type: loose ? 'loose_item_start' : 'list_item_start'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Recurse.
|
||||||
|
this.token(item, false, bq);
|
||||||
|
|
||||||
|
this.tokens.push({
|
||||||
|
type: 'list_item_end'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tokens.push({
|
this.tokens.push({
|
||||||
type: loose ? 'loose_item_start' : 'list_item_start'
|
type: 'list_end'
|
||||||
});
|
});
|
||||||
|
|
||||||
// Recurse.
|
continue;
|
||||||
this.token(item, false, bq);
|
|
||||||
|
|
||||||
this.tokens.push({
|
|
||||||
type: 'list_item_end'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tokens.push({
|
|
||||||
type: 'list_end'
|
|
||||||
});
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// html
|
// html
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user