Fix nested task lists
When nesting task list items, the parent item is wrapped in a `<p>` tag. Update the task list parser to handle these paragraph wrappers.
This commit is contained in:
parent
c6dd117c71
commit
1dc90fc455
|
@ -5,7 +5,7 @@
|
||||||
# Used by MergeRequest and Issue
|
# Used by MergeRequest and Issue
|
||||||
module Taskable
|
module Taskable
|
||||||
TASK_PATTERN_MD = /^(?<bullet> *[*-] *)\[(?<checked>[ xX])\]/.freeze
|
TASK_PATTERN_MD = /^(?<bullet> *[*-] *)\[(?<checked>[ xX])\]/.freeze
|
||||||
TASK_PATTERN_HTML = /^<li>\[(?<checked>[ xX])\]/.freeze
|
TASK_PATTERN_HTML = /^<li>(?<p_tag>\s*<p>)?\[(?<checked>[ xX])\]/.freeze
|
||||||
|
|
||||||
# Change the state of a task list item for this Taskable. Edit the object's
|
# Change the state of a task list item for this Taskable. Edit the object's
|
||||||
# description by finding the nth task item and changing its checkbox
|
# description by finding the nth task item and changing its checkbox
|
||||||
|
|
|
@ -352,11 +352,12 @@ module Gitlab
|
||||||
# ActiveSupport::SafeBuffer, hence the `String.new`
|
# ActiveSupport::SafeBuffer, hence the `String.new`
|
||||||
String.new(text).gsub(Taskable::TASK_PATTERN_HTML) do
|
String.new(text).gsub(Taskable::TASK_PATTERN_HTML) do
|
||||||
checked = $LAST_MATCH_INFO[:checked].downcase == 'x'
|
checked = $LAST_MATCH_INFO[:checked].downcase == 'x'
|
||||||
|
p_tag = $LAST_MATCH_INFO[:p_tag]
|
||||||
|
|
||||||
if checked
|
if checked
|
||||||
"#{li_tag}#{checked_box}"
|
"#{li_tag}#{p_tag}#{checked_box}"
|
||||||
else
|
else
|
||||||
"#{li_tag}#{unchecked_box}"
|
"#{li_tag}#{p_tag}#{unchecked_box}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -817,6 +817,17 @@ EOT
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should render checkboxes for nested tasks' do
|
||||||
|
rendered_text = markdown(@source_text_asterisk, parse_tasks: true)
|
||||||
|
|
||||||
|
expect(rendered_text).to match(
|
||||||
|
/<input.*checkbox.*valid unchecked nested task/
|
||||||
|
)
|
||||||
|
expect(rendered_text).to match(
|
||||||
|
/<input.*checkbox.*valid checked nested task/
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should not be confused by whitespace before bullets' do
|
it 'should not be confused by whitespace before bullets' do
|
||||||
rendered_text_asterisk = markdown(@source_text_asterisk,
|
rendered_text_asterisk = markdown(@source_text_asterisk,
|
||||||
parse_tasks: true)
|
parse_tasks: true)
|
||||||
|
|
Loading…
Reference in New Issue