diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-05-18 15:44:45 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-05-20 12:08:33 -0400 |
commit | 8ee382087d06c50d2f8c7f60ce79294af0b89201 (patch) | |
tree | 065ac0d87837f878eeeebed2045a5bf5010c991e /lib | |
parent | 76a758234ac29ba2c859cb50fec6e6374e4a8742 (diff) | |
download | gitlab-ce-8ee382087d06c50d2f8c7f60ce79294af0b89201.tar.gz |
Subclass TaskList::Filter to fix a bugrs-issue-1645
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/markdown/task_list_filter.rb | 23 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 133010adcaf..c0fb22e7f36 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -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 diff --git a/lib/gitlab/markdown/task_list_filter.rb b/lib/gitlab/markdown/task_list_filter.rb new file mode 100644 index 00000000000..c6eb2e2bf6d --- /dev/null +++ b/lib/gitlab/markdown/task_list_filter.rb @@ -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 |