Subclass TaskList::Filter to fix a bug

Instead of using a fork, we subclass the filter and only apply the
`task-list` class to list items that actually are task lists.

Closes #1645

See https://github.com/github/task_list/pull/60
This commit is contained in:
Robert Speicher 2015-05-18 15:44:45 -04:00
parent 76a758234a
commit 8ee382087d
6 changed files with 45 additions and 8 deletions

View file

@ -94,7 +94,7 @@ gem "seed-fu"
# Markdown and HTML processing
gem 'html-pipeline', '~> 1.11.0'
gem 'task_list', '~> 1.0.0', require: 'task_list/railtie'
gem 'task_list', '1.0.2', require: 'task_list/railtie'
gem 'github-markup'
gem 'redcarpet', '~> 3.2.3'
gem 'RedCloth'

View file

@ -338,7 +338,7 @@ GEM
method_source (0.8.2)
mime-types (1.25.1)
mimemagic (0.3.0)
mini_portile (0.6.1)
mini_portile (0.6.2)
minitest (5.3.5)
mousetrap-rails (1.4.6)
multi_json (1.10.1)
@ -350,7 +350,7 @@ GEM
net-ssh (>= 2.6.5)
net-ssh (2.8.0)
newrelic_rpm (3.9.4.245)
nokogiri (1.6.5)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nprogress-rails (0.1.2.3)
oauth (0.4.7)
@ -802,7 +802,7 @@ DEPENDENCIES
spring-commands-spinach (= 1.0.0)
stamp
state_machine
task_list (~> 1.0.0)
task_list (= 1.0.2)
test_after_commit
thin
tinder (~> 1.9.2)

View file

@ -79,11 +79,11 @@ ul.notes {
word-wrap: break-word;
@include md-typography;
// Reduce left padding of first ul element
// Reduce left padding of first task list ul element
ul.task-list:first-child {
padding-left: 10px;
// sub-lists should be padded normally
// sub-tasks should be padded normally
ul {
padding-left: 20px;
}

View file

@ -1,5 +1,4 @@
require 'html/pipeline'
require 'task_list/filter'
module Gitlab
# Custom parser for GitLab-flavored Markdown
@ -19,6 +18,7 @@ module Gitlab
autoload :SanitizationFilter, 'gitlab/markdown/sanitization_filter'
autoload :SnippetReferenceFilter, 'gitlab/markdown/snippet_reference_filter'
autoload :TableOfContentsFilter, 'gitlab/markdown/table_of_contents_filter'
autoload :TaskListFilter, 'gitlab/markdown/task_list_filter'
autoload :UserReferenceFilter, 'gitlab/markdown/user_reference_filter'
# Public: Parse the provided text with GitLab-Flavored Markdown
@ -113,7 +113,7 @@ module Gitlab
Gitlab::Markdown::CommitReferenceFilter,
Gitlab::Markdown::LabelReferenceFilter,
TaskList::Filter
Gitlab::Markdown::TaskListFilter
]
end
end

View file

@ -0,0 +1,23 @@
require 'task_list/filter'
module Gitlab
module Markdown
# Work around a bug in the default TaskList::Filter that adds a `task-list`
# class to every list element, regardless of whether or not it contains a
# task list.
#
# This is a (hopefully) temporary fix, pending a new release of the
# task_list gem.
#
# See https://github.com/github/task_list/pull/60
class TaskListFilter < TaskList::Filter
def add_css_class(node, *new_class_names)
if new_class_names.include?('task-list')
super if node.children.any? { |c| c['class'] == 'task-list-item' }
else
super
end
end
end
end
end

View file

@ -0,0 +1,14 @@
require 'spec_helper'
module Gitlab::Markdown
describe TaskListFilter do
def filter(html, options = {})
described_class.call(html, options)
end
it 'does not apply `task-list` class to non-task lists' do
exp = act = %(<ul><li>Item</li></ul>)
expect(filter(act).to_html).to eq exp
end
end
end