From: Marius Balteanu Date: Sat, 22 Jan 2022 09:24:43 +0000 (+0000) Subject: Enable task list items for Common Mark text formatting (#35742). X-Git-Tag: 5.0.0~92 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=380a3b0345b236db9f9bc05bd27b193be89d11cc;p=redmine.git Enable task list items for Common Mark text formatting (#35742). git-svn-id: http://svn.redmine.org/redmine/trunk@21383 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/Gemfile b/Gemfile index 04f8ddc01..2e2182caa 100644 --- a/Gemfile +++ b/Gemfile @@ -49,6 +49,7 @@ group :common_mark do gem "html-pipeline", "~> 2.13.2" gem "commonmarker", (Gem.ruby_version < Gem::Version.new('2.6.0') ? '0.21.0' : '0.23.1') gem "sanitize", "~> 6.0" + gem 'deckar01-task_list', '2.3.2' end # Include database gems for the adapters found in the database diff --git a/lib/redmine/wiki_formatting/common_mark/formatter.rb b/lib/redmine/wiki_formatting/common_mark/formatter.rb index 8510baf14..bffad6c92 100644 --- a/lib/redmine/wiki_formatting/common_mark/formatter.rb +++ b/lib/redmine/wiki_formatting/common_mark/formatter.rb @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'html/pipeline' +require 'task_list/filter' module Redmine module WikiFormatting @@ -57,6 +58,7 @@ module Redmine SyntaxHighlightFilter, FixupAutoLinksFilter, ExternalLinksFilter, + TaskList::Filter ], PIPELINE_CONFIG class Formatter < Redmine::WikiFormatting::Markdown::Formatter diff --git a/public/images/bt_tl.png b/public/images/bt_tl.png new file mode 100644 index 000000000..4bf58d1de Binary files /dev/null and b/public/images/bt_tl.png differ diff --git a/public/javascripts/jstoolbar/common_mark.js b/public/javascripts/jstoolbar/common_mark.js index a1b1fd599..8dae000df 100644 --- a/public/javascripts/jstoolbar/common_mark.js +++ b/public/javascripts/jstoolbar/common_mark.js @@ -132,6 +132,20 @@ jsToolBar.prototype.elements.ol = { } } +// tl +jsToolBar.prototype.elements.tl = { + type: 'button', + title: 'Task list', + fn: { + wiki: function() { + this.encloseLineSelection('','',function(str) { + str = str.replace(/\r/g,''); + return str.replace(/(\n|^)[*-]?\s*/g,"$1* [ ] "); + }); + } + } +} + // spacer jsToolBar.prototype.elements.space3 = {type: 'space'} diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index eddbd4b31..0ca4f48db 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1314,6 +1314,13 @@ a.wiki-anchor:hover { color: #aaa !important; text-decoration: none; } h1:hover a.wiki-anchor, h2:hover a.wiki-anchor, h3:hover a.wiki-anchor, h4:hover a.wiki-anchor, h5:hover a.wiki-anchor, h6:hover a.wiki-anchor { display: inline; color: #ddd; } div.wiki img {vertical-align:middle; max-width:100%;} +div.wiki .task-list { + list-style-type: none; + padding-left: 0px; +} +div.wiki .task-list input.task-list-item-checkbox { + height: initial; +} /***** My page layout *****/ .block-receiver { diff --git a/public/stylesheets/jstoolbar.css b/public/stylesheets/jstoolbar.css index 5672e694c..911ae6678 100644 --- a/public/stylesheets/jstoolbar.css +++ b/public/stylesheets/jstoolbar.css @@ -128,6 +128,9 @@ .jstb_ol { background-image: url(../images/jstoolbar/bt_ol.png); } +.jstb_tl { + background-image: url(../images/jstoolbar/bt_tl.png); +} .jstb_bq { background-image: url(../images/jstoolbar/bt_bq.png); } diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb index c05b8a0a0..ee46e5d8e 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb @@ -263,6 +263,27 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase end end + def test_should_support_task_list + text = <<~STR + Task list: + * [ ] Task 1 + * [x] Task 2 + STR + + expected = <<~EXPECTED +

Task list:

+ + EXPECTED + + assert_equal expected.gsub(%r{[\r\n\t]}, ''), format(text).gsub(%r{[\r\n\t]}, '').rstrip + end + private def assert_section_with_hash(expected, text, index)