Commit 367b0ecc authored by Brett Walker's avatar Brett Walker

Don’t create list item for valid horizontal rules

Valid horizontal rules can look like a list item, such as
`- —`.  We should not create a new list item for these
parent 841df21e
......@@ -11,6 +11,9 @@ const LINK_TAG_PATTERN = '[{text}](url)';
// followed by one or more whitespace characters
const LIST_LINE_HEAD_PATTERN = /^(?<indent>\s*)(?<leader>((?<isUl>[*+-])|(?<isOl>\d+\.))( \[([xX ])\])?\s)(?<content>.)?/;
// detect a horizontal rule that might be mistaken for a list item (not full pattern for an <hr>)
const HR_PATTERN = /^((\s{0,3}-+\s*-+\s*-+\s*[\s-]*)|(\s{0,3}\*+\s*\*+\s*\*+\s*[\s*]*))$/;
function selectedText(text, textarea) {
return text.substring(textarea.selectionStart, textarea.selectionEnd);
}
......@@ -381,13 +384,15 @@ function handleContinueList(e, textArea) {
let itemToInsert;
// Behaviors specific to either `ol` or `ul`
if (isOl) {
const nextLine = lineAfter(textArea.value, textArea, false);
const nextLineResult = nextLine.match(LIST_LINE_HEAD_PATTERN);
itemToInsert = continueOlText(result, nextLineResult);
} else {
// isUl
if (currentLine.match(HR_PATTERN)) return;
itemToInsert = `${indent}${leader}`;
}
......
......@@ -178,10 +178,18 @@ describe('init markdown', () => {
it.each`
text | expected
${'- item'} | ${'- item\n- '}
${'* item'} | ${'* item\n* '}
${'+ item'} | ${'+ item\n+ '}
${'- [ ] item'} | ${'- [ ] item\n- [ ] '}
${'- [x] item'} | ${'- [x] item\n- [ ] '}
${'- [X] item'} | ${'- [X] item\n- [ ] '}
${'- item\n - second'} | ${'- item\n - second\n - '}
${'- - -'} | ${'- - -'}
${'- --'} | ${'- --'}
${'* **'} | ${'* **'}
${' ** * ** * ** * **'} | ${' ** * ** * ** * **'}
${'- - -x'} | ${'- - -x\n- '}
${'+ ++'} | ${'+ ++\n+ '}
${'1. item'} | ${'1. item\n2. '}
${'1. [ ] item'} | ${'1. [ ] item\n2. [ ] '}
${'1. [x] item'} | ${'1. [x] item\n2. [ ] '}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment