mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-25 15:35:13 +00:00
quoteのネスト制限を追加 (#91)
* refactor quote * add nesting limit test for quote * nesting limit for quote
This commit is contained in:
parent
8cc0ca9400
commit
d9b8b8db5f
2 changed files with 41 additions and 4 deletions
|
@ -77,7 +77,7 @@
|
|||
|
||||
// nesting control
|
||||
|
||||
const nestLimit = options.nestLimit || 20;
|
||||
const nestLimit = (options.nestLimit != null ? options.nestLimit : 20);
|
||||
let depth = 0;
|
||||
function enterNest() {
|
||||
if (depth + 1 > nestLimit) {
|
||||
|
@ -166,25 +166,32 @@ plain
|
|||
// block: quote
|
||||
|
||||
quote
|
||||
= &(BEGIN ">") q:quoteInner LF? { return q; }
|
||||
= &(BEGIN ">") &{ return (depth + 1 <= nestLimit); } @quoteInner LF?
|
||||
|
||||
quoteInner
|
||||
= head:(quoteLine / quoteEmptyLine) tails:(quoteLine / quoteEmptyLine)+
|
||||
{
|
||||
depth++;
|
||||
const children = applyParser([head, ...tails].join('\n'), 'fullParser');
|
||||
depth--;
|
||||
return QUOTE(children);
|
||||
}
|
||||
/ line:quoteLine
|
||||
{
|
||||
depth++;
|
||||
const children = applyParser(line, 'fullParser');
|
||||
depth--;
|
||||
return QUOTE(children);
|
||||
}
|
||||
|
||||
quoteLine
|
||||
= BEGIN ">" _? text:$CHAR+ END { return text; }
|
||||
= BEGIN ">" _? @$CHAR+ END
|
||||
|
||||
quoteEmptyLine
|
||||
= BEGIN ">" _? END { return ''; }
|
||||
= BEGIN ">" _? END
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// block: search
|
||||
|
||||
|
|
|
@ -1128,6 +1128,36 @@ hoge`;
|
|||
});
|
||||
|
||||
describe('nesting limit', () => {
|
||||
describe('quote', () => {
|
||||
it('basic', () => {
|
||||
const input = '>>> abc';
|
||||
const output = [
|
||||
QUOTE([
|
||||
QUOTE([
|
||||
TEXT('> abc'),
|
||||
]),
|
||||
]),
|
||||
];
|
||||
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
|
||||
});
|
||||
|
||||
it('basic 2', () => {
|
||||
const input = '>> **abc**';
|
||||
const output = [
|
||||
QUOTE([
|
||||
QUOTE([
|
||||
TEXT('*'),
|
||||
ITALIC([
|
||||
TEXT('abc'),
|
||||
]),
|
||||
TEXT('*'),
|
||||
]),
|
||||
]),
|
||||
];
|
||||
assert.deepStrictEqual(mfm.parse(input, { nestLimit: 2 }), output);
|
||||
});
|
||||
});
|
||||
|
||||
it('big', () => {
|
||||
const input = '<b><b>***abc***</b></b>';
|
||||
const output = [
|
||||
|
|
Loading…
Reference in a new issue