summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/set_direction_filter.rb
blob: c2976aeb7c6dff663fa95e389722b2ed2a7cdc4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module Banzai
  module Filter
    # HTML filter that sets dir="auto" for RTL languages support
    class SetDirectionFilter < HTML::Pipeline::Filter
      def call
        # select these elements just on top level of the document
        doc.xpath('p|h1|h2|h3|h4|h5|h6|ol|ul[not(@class="section-nav")]|blockquote|table').each do |el|
          el['dir'] = 'auto'
        end

        doc
      end
    end
  end
end