]> source.dussan.org Git - redmine.git/commitdiff
Enable task list items for Common Mark text formatting (#35742).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sat, 22 Jan 2022 09:24:43 +0000 (09:24 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sat, 22 Jan 2022 09:24:43 +0000 (09:24 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@21383 e93f8b46-1217-0410-a6f0-8f06a7374b81

Gemfile
lib/redmine/wiki_formatting/common_mark/formatter.rb
public/images/bt_tl.png [new file with mode: 0644]
public/javascripts/jstoolbar/common_mark.js
public/stylesheets/application.css
public/stylesheets/jstoolbar.css
test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb

diff --git a/Gemfile b/Gemfile
index 04f8ddc0193391f006cb0640e76cc0132d18586f..2e2182caae413617c4823fede946c15688daa717 100644 (file)
--- 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
index 8510baf14a67c8c7a7ca32d471db2f480aa505ef..bffad6c92e2b802b4b2f3e62cdf0027066c6bede 100644 (file)
@@ -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 (file)
index 0000000..4bf58d1
Binary files /dev/null and b/public/images/bt_tl.png differ
index a1b1fd599ec34d15ac55d23d2cc86afae16d1ea7..8dae000df7e9dc9da48d5f49e9325b8bbae2aa9a 100644 (file)
@@ -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'}
 
index eddbd4b31cd49728bb41623fe54f854cc559f460..0ca4f48db82b9b6feaa5676329e91ce058596a30 100644 (file)
@@ -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 {
index 5672e694c998cdad740f62fd6fd12ad0d99d11c7..911ae66788962459b2920fd7970b06c05e7001c5 100644 (file)
 .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);
 }
index c05b8a0a03d4784436769ed372cc0ebf1ffab932..ee46e5d8e16d9e5fbc4aa39eefeb18ea62f3b44f 100644 (file)
@@ -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
+        <p>Task list:</p>
+        <ul class="task-list">
+        <li class="task-list-item">
+        <input type="checkbox" class="task-list-item-checkbox" disabled> Task 1
+        </li>
+        <li class="task-list-item">
+        <input type="checkbox" class="task-list-item-checkbox" checked disabled> Task 2</li>
+        </ul>
+      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)