diff --git a/app/models/revision.rb b/app/models/revision.rb index 05745b1b337..c085cfb519a 100644 --- a/app/models/revision.rb +++ b/app/models/revision.rb @@ -97,6 +97,7 @@ def render_body body = body.gsub(Callouts.const_get(:FINDER), Callouts.const_get(:PRETTYLINKHTML)) body = body.gsub(Callouts.const_get(:HASHTAGNUMBER), Callouts.const_get(:NODELINKHTML)) body = body.gsub(Callouts.const_get(:HASHTAG), Callouts.const_get(:HASHLINKHTML)) + body = body.gsub(/(\d+\. |\* )\K\[(x|X)\]/, %()).gsub(/(\d+\. |\* )\K\[ \]/, %()) ApplicationController.helpers.emojify(body_extras(body)).to_s end @@ -107,6 +108,7 @@ def render_body_raw body = body.gsub(Callouts.const_get(:FINDER), Callouts.const_get(:PRETTYLINKHTML)) body = body.gsub(Callouts.const_get(:HASHTAGNUMBER), Callouts.const_get(:NODELINKHTML)) body = body.gsub(Callouts.const_get(:HASHTAG), Callouts.const_get(:HASHLINKHTML)) + body = body.gsub(/(\d+\. |\* )\K\[(x|X)\]/, %()).gsub(/(\d+\. |\* )\K\[ \]/, %()) insert_extras(body_extras(body)) end diff --git a/test/fixtures/revisions.yml b/test/fixtures/revisions.yml index c9e35f66e43..4a44a5044ed 100644 --- a/test/fixtures/revisions.yml +++ b/test/fixtures/revisions.yml @@ -142,7 +142,7 @@ hashtag_in_header: uid: 1 title: grabs hashtags in headers body: |+ - # Heading 1 is about #hashtags + # Heading 1 is about #hashtags Here is the message subheader: @@ -251,4 +251,22 @@ draft: nid: 21 uid: 2 title: "Draft note" - body: This is draft note. \ No newline at end of file + body: This is draft note. + +checkbox_one: + nid: 1 + uid: 1 + title: Should render an unchecked checkbox + body: |+ + # Heading 1 + List of things + * [ ] + +checkbox_two: + nid: 1 + uid: 1 + title: Should render a checked checkbox + body: |+ + # Heading 1 + List of things + * [x] diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 51a47814284..f1e37f92b73 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -313,7 +313,7 @@ def teardown assert_response :success selector = css_select 'div.note' - assert_equal selector.size, 15 + assert_equal selector.size, 17 assert_select "div p", 'Pending approval by community moderators. Please be patient!' end @@ -342,7 +342,7 @@ def teardown assert_response :success selector = css_select 'div.note' - assert_equal selector.size, 15 + assert_equal selector.size, 17 assert_select "p", "Moderate first-time post: \n Approve\n Spam" end @@ -450,7 +450,7 @@ def teardown test 'should display an icon for users with streak longer than 7 days' do node = nodes(:one) User.any_instance.stubs(:note_streak).returns([8, 10]) - User.any_instance.stubs(:wiki_edit_streak).returns([9, 15]) + User.any_instance.stubs(:wiki_edit_streak).returns([9, 17]) User.any_instance.stubs(:comment_streak).returns([10, 30]) get :show, params: { diff --git a/test/unit/constants_test.rb b/test/unit/constants_test.rb index 184e1118888..a744c773e3e 100644 --- a/test/unit/constants_test.rb +++ b/test/unit/constants_test.rb @@ -28,10 +28,11 @@ class ConstantsTest < ActiveSupport::TestCase assert string.scan(Callouts.const_get(:HASHTAG)).length == 3 end - test 'hashtagnumber regex should match non-initial hash' do + test 'hashtagnumber regex should match non-initial hash' do string = "hello #123 #hello " ; assert string.scan(Callouts.const_get(:HASHTAGNUMBER)).length == 1 expect = "hello REPLACE #hello " ; assert_equal expect, string.gsub(Callouts.const_get(:HASHTAGNUMBER), ' REPLACE') ; end + end diff --git a/test/unit/revision_test.rb b/test/unit/revision_test.rb index d015727b8c9..335defb64a2 100644 --- a/test/unit/revision_test.rb +++ b/test/unit/revision_test.rb @@ -202,4 +202,16 @@ class RevisionsTest < ActiveSupport::TestCase tag_names = associated_tags.map(&:name) assert_not tag_names.include?('1234') end + + test 'should recognize unmarked markdown style checkboxes and convert them into unchecked checkbox' do + revision = revisions(:checkbox_one) + assert_includes revision.render_body, %(* ) + end + + test 'should recognize marked markdown style checkboxes and convert them into checked checkbox' do + revision = revisions(:checkbox_two) + assert_includes revision.render_body, %(* ) + end + + end