Commit 2374a4e7 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'task-list-with-nbsp' into 'master'

Check task with no-break space

See merge request gitlab-org/gitlab!80674
parents a610e5cf c1e52059
......@@ -9,7 +9,7 @@ const LINK_TAG_PATTERN = '[{text}](url)';
// a bullet point character (*+-) and an optional checkbox ([ ] [x])
// OR a number with a . after it and an optional checkbox ([ ] [x])
// 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])\])?\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*]*))$/;
......
......@@ -11,14 +11,16 @@ require 'task_list/filter'
module Taskable
COMPLETED = 'completed'
INCOMPLETE = 'incomplete'
COMPLETE_PATTERN = /(\[[xX]\])/.freeze
INCOMPLETE_PATTERN = /(\[\s\])/.freeze
COMPLETE_PATTERN = /\[[xX]\]/.freeze
INCOMPLETE_PATTERN = /\[[[:space:]]\]/.freeze
ITEM_PATTERN = %r{
^
(?:(?:>\s{0,4})*) # optional blockquote characters
((?:\s*(?:[-+*]|(?:\d+\.)))+) # list prefix (one or more) required - task item has to be always in a list
\s+ # whitespace prefix has to be always presented for a list item
(\[\s\]|\[[xX]\]) # checkbox
( # checkbox
#{COMPLETE_PATTERN}|#{INCOMPLETE_PATTERN}
)
(\s.+) # followed by whitespace and some text.
}x.freeze
......
......@@ -183,6 +183,7 @@ describe('init markdown', () => {
${'- [ ] item'} | ${'- [ ] item\n- [ ] '}
${'- [x] item'} | ${'- [x] item\n- [ ] '}
${'- [X] item'} | ${'- [X] item\n- [ ] '}
${'- [ ] nbsp (U+00A0)'} | ${'- [ ] nbsp (U+00A0)\n- [ ] '}
${'- item\n - second'} | ${'- item\n - second\n - '}
${'- - -'} | ${'- - -'}
${'- --'} | ${'- --'}
......
......@@ -13,6 +13,10 @@ RSpec.describe Taskable do
- [x] Second item
* [x] First item
* [ ] Second item
+ [ ] No-break space (U+00A0)
+ [ ] Figure space (U+2007)
+ [ ] Narrow no-break space (U+202F)
+ [ ] Thin space (U+2009)
MARKDOWN
end
......@@ -21,7 +25,11 @@ RSpec.describe Taskable do
TaskList::Item.new('- [ ]', 'First item'),
TaskList::Item.new('- [x]', 'Second item'),
TaskList::Item.new('* [x]', 'First item'),
TaskList::Item.new('* [ ]', 'Second item')
TaskList::Item.new('* [ ]', 'Second item'),
TaskList::Item.new('+ [ ]', 'No-break space (U+00A0)'),
TaskList::Item.new('+ [ ]', 'Figure space (U+2007)'),
TaskList::Item.new('+ [ ]', 'Narrow no-break space (U+202F)'),
TaskList::Item.new('+ [ ]', 'Thin space (U+2009)')
]
end
......
......@@ -16,6 +16,8 @@ RSpec.describe TaskListToggleService do
- [ ] loose list
with an embedded paragraph
+ [ ] No-break space (U+00A0)
EOT
end
......@@ -40,12 +42,17 @@ RSpec.describe TaskListToggleService do
</ul>
</li>
</ol>
<ul data-sourcepos="9:1-11:28" class="task-list" dir="auto">
<li data-sourcepos="9:1-11:28" class="task-list-item">
<ul data-sourcepos="9:1-12:0" class="task-list" dir="auto">
<li data-sourcepos="9:1-12:0" class="task-list-item">
<p data-sourcepos="9:3-9:16"><input type="checkbox" class="task-list-item-checkbox" disabled=""> loose list</p>
<p data-sourcepos="11:3-11:28">with an embedded paragraph</p>
</li>
</ul>
<ul data-sourcepos="13:1-13:21" class="task-list" dir="auto">
<li data-sourcepos="13:1-13:21" class="task-list-item">
<input type="checkbox" class="task-list-item-checkbox" disabled=""> No-break space (U+00A0)
</li>
</ul>
EOT
end
......@@ -79,6 +86,16 @@ RSpec.describe TaskListToggleService do
expect(toggler.updated_markdown_html).to include('disabled checked> loose list')
end
it 'checks task with no-break space' do
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: true,
line_source: '+ [ ] No-break space (U+00A0)', line_number: 13)
expect(toggler.execute).to be_truthy
expect(toggler.updated_markdown.lines[12]).to eq "+ [x] No-break space (U+00A0)"
expect(toggler.updated_markdown_html).to include('disabled checked> No-break space (U+00A0)')
end
it 'returns false if line_source does not match the text' do
toggler = described_class.new(markdown, markdown_html,
toggle_as_checked: false,
......
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