Commit fdcdb8c1 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch...

Merge branch '353774-markdown-typing-followed-by-enter-incorrectly-adds-a-new-list-item' into 'master'

[markdown] Typing `- - -` followed by Enter incorrectly adds a new list item

See merge request gitlab-org/gitlab!84012
parents c2d400a0 367b0ecc
...@@ -11,6 +11,9 @@ const LINK_TAG_PATTERN = '[{text}](url)'; ...@@ -11,6 +11,9 @@ const LINK_TAG_PATTERN = '[{text}](url)';
// followed by one or more whitespace characters // followed by one or more whitespace characters
const LIST_LINE_HEAD_PATTERN = /^(?<indent>\s*)(?<leader>((?<isUl>[*+-])|(?<isOl>\d+\.))( \[([xX ])\])?\s)(?<content>.)?/; 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) { function selectedText(text, textarea) {
return text.substring(textarea.selectionStart, textarea.selectionEnd); return text.substring(textarea.selectionStart, textarea.selectionEnd);
} }
...@@ -381,13 +384,15 @@ function handleContinueList(e, textArea) { ...@@ -381,13 +384,15 @@ function handleContinueList(e, textArea) {
let itemToInsert; let itemToInsert;
// Behaviors specific to either `ol` or `ul`
if (isOl) { if (isOl) {
const nextLine = lineAfter(textArea.value, textArea, false); const nextLine = lineAfter(textArea.value, textArea, false);
const nextLineResult = nextLine.match(LIST_LINE_HEAD_PATTERN); const nextLineResult = nextLine.match(LIST_LINE_HEAD_PATTERN);
itemToInsert = continueOlText(result, nextLineResult); itemToInsert = continueOlText(result, nextLineResult);
} else { } else {
// isUl if (currentLine.match(HR_PATTERN)) return;
itemToInsert = `${indent}${leader}`; itemToInsert = `${indent}${leader}`;
} }
......
...@@ -178,10 +178,18 @@ describe('init markdown', () => { ...@@ -178,10 +178,18 @@ describe('init markdown', () => {
it.each` it.each`
text | expected text | expected
${'- item'} | ${'- item\n- '} ${'- item'} | ${'- item\n- '}
${'* item'} | ${'* item\n* '}
${'+ item'} | ${'+ item\n+ '}
${'- [ ] item'} | ${'- [ ] item\n- [ ] '} ${'- [ ] item'} | ${'- [ ] item\n- [ ] '}
${'- [x] item'} | ${'- [x] item\n- [ ] '} ${'- [x] item'} | ${'- [x] item\n- [ ] '}
${'- [X] item'} | ${'- [X] item\n- [ ] '} ${'- [X] item'} | ${'- [X] item\n- [ ] '}
${'- item\n - second'} | ${'- item\n - second\n - '} ${'- item\n - second'} | ${'- item\n - second\n - '}
${'- - -'} | ${'- - -'}
${'- --'} | ${'- --'}
${'* **'} | ${'* **'}
${' ** * ** * ** * **'} | ${' ** * ** * ** * **'}
${'- - -x'} | ${'- - -x\n- '}
${'+ ++'} | ${'+ ++\n+ '}
${'1. item'} | ${'1. item\n2. '} ${'1. item'} | ${'1. item\n2. '}
${'1. [ ] item'} | ${'1. [ ] item\n2. [ ] '} ${'1. [ ] item'} | ${'1. [ ] item\n2. [ ] '}
${'1. [x] item'} | ${'1. [x] 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