diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filters/table_sticky_headings.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/filters/table_sticky_headings.rb b/lib/filters/table_sticky_headings.rb new file mode 100644 index 00000000..13c0f63f --- /dev/null +++ b/lib/filters/table_sticky_headings.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +# +# Wrap tables inside a div so we can apply CSS styles to them +# https://gitlab.com/gitlab-org/gitlab-docs/-/issues/1076 +# +class TableStickyHeadings < Nanoc::Filter + identifier :table_sticky_headings + + def run(content, params = {}) + # `#dup` is necessary because `.fragment` modifies the incoming string. Ew! + # See https://github.com/sparklemotion/nokogiri/issues/1077 + doc = Nokogiri::HTML.fragment(content.dup) + doc.css('table').each do |table| + content = table.to_html + new_content = generate(content) + table.replace(new_content) + end + doc.to_s + end + + def generate(content) + %(<div class="table-sticky-headings">#{content}</div>) + end +end |