From 380a3b0345b236db9f9bc05bd27b193be89d11cc Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sat, 22 Jan 2022 09:24:43 +0000 Subject: [PATCH] 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 --- Gemfile | 1 + .../wiki_formatting/common_mark/formatter.rb | 2 ++ public/images/bt_tl.png | Bin 0 -> 479 bytes public/javascripts/jstoolbar/common_mark.js | 14 ++++++++++++ public/stylesheets/application.css | 7 ++++++ public/stylesheets/jstoolbar.css | 3 +++ .../common_mark/formatter_test.rb | 21 ++++++++++++++++++ 7 files changed, 48 insertions(+) create mode 100644 public/images/bt_tl.png 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 0000000000000000000000000000000000000000..4bf58d1deefd4bb3a061e6d4d3ddde3d531a876f GIT binary patch literal 479 zcmV<50U-W~P)op+Qcsz#fb_@M}AA%s@ImdBeHk%bUSglroVDtGLXdT8^PcRydN}8rI;y#-o(*aF@ zcAoz1G3O5~5arcswJFQ;g;)r~aDl>lrGAJH!4u*PQp&^`Ldh5uF2p$`g6H@YU;y%^ V<0YG5kQ@L2002ovPDHLkV1iLr*2n+= literal 0 HcmV?d00001 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:

+
    +
  • + Task 1 +
  • +
  • + Task 2
  • +
+ 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) -- 2.39.5