summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/task_list_filter.rb
blob: 66608c9859c1087d2008baf4eb2f6660ad2b98b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'task_list/filter'

module Banzai
  module Filter
    # 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_with_fix(node, *new_class_names)
        if new_class_names.include?('task-list')
          # Don't add class to all lists
          return
        elsif new_class_names.include?('task-list-item')
          add_css_class_without_fix(node.parent, 'task-list')
        end

        add_css_class_without_fix(node, *new_class_names)
      end

      alias_method_chain :add_css_class, :fix
    end
  end
end