summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/set_direction_filter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/banzai/filter/set_direction_filter.rb')
-rw-r--r--lib/banzai/filter/set_direction_filter.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/banzai/filter/set_direction_filter.rb b/lib/banzai/filter/set_direction_filter.rb
new file mode 100644
index 00000000000..c2976aeb7c6
--- /dev/null
+++ b/lib/banzai/filter/set_direction_filter.rb
@@ -0,0 +1,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