diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-24 20:57:35 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-03-24 20:57:35 +0000 |
commit | b8ad3647ad99a64ffc6296883aa8135d462dd17b (patch) | |
tree | 52b01f122b014724783ce7f31761296e9d0f76c2 | |
parent | c3c9703437a552700c2a6ca010b05cc56aa6d73a (diff) | |
parent | b7ed7d05a0b2aab9123c101a1a0558ae0f9bf7cc (diff) | |
download | gitlab-ce-b8ad3647ad99a64ffc6296883aa8135d462dd17b.tar.gz |
Merge branch 'fix-nested-tasks' into 'master'
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.
cc @sytse
See merge request !413
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/concerns/taskable.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/markdown.rb | 5 | ||||
-rw-r--r-- | spec/helpers/gitlab_markdown_helper_spec.rb | 11 |
4 files changed, 16 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG index 3ecc45cde07..ccc71737e43 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ v 7.10.0 (unreleased) - Add changelog, license and contribution guide links to project sidebar. - Improve diff UI - Fix alignment of navbar toggle button (Cody Mize) + - Fix checkbox rendering for nested task lists - Identical look of selectboxes in UI - Move "Import existing repository by URL" option to button. - Improve error message when save profile has error. diff --git a/app/models/concerns/taskable.rb b/app/models/concerns/taskable.rb index 410e8dc820b..bbb3b301a9f 100644 --- a/app/models/concerns/taskable.rb +++ b/app/models/concerns/taskable.rb @@ -5,7 +5,7 @@ # Used by MergeRequest and Issue module Taskable 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 # description by finding the nth task item and changing its checkbox diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index e02e5b9fc3d..f5e8267031c 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -352,11 +352,12 @@ module Gitlab # ActiveSupport::SafeBuffer, hence the `String.new` String.new(text).gsub(Taskable::TASK_PATTERN_HTML) do checked = $LAST_MATCH_INFO[:checked].downcase == 'x' + p_tag = $LAST_MATCH_INFO[:p_tag] if checked - "#{li_tag}#{checked_box}" + "#{li_tag}#{p_tag}#{checked_box}" else - "#{li_tag}#{unchecked_box}" + "#{li_tag}#{p_tag}#{unchecked_box}" end end end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 6ba27b536e4..ddbb4467f10 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -817,6 +817,17 @@ EOT ) 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 rendered_text_asterisk = markdown(@source_text_asterisk, parse_tasks: true) |