diff options
author | Evan Read <eread@gitlab.com> | 2021-08-26 02:28:30 +0300 |
---|---|---|
committer | Evan Read <eread@gitlab.com> | 2021-08-26 02:28:30 +0300 |
commit | c2c62c2a813c412d8d2dd8bf00bae140c789cd53 (patch) | |
tree | cfa3edeea46c7408b2b197e1d9b0a8c3ed708bdb | |
parent | d3e3c51ddff3ea85c1c3b18d691681ef408bde15 (diff) | |
parent | 8089a93904d137b8cfc3c8b9bfe7e439cbaa9d10 (diff) |
Merge branch 'axil-filter-sticky-headings' into 'main'
Add a table sticky headings filter
See merge request gitlab-org/gitlab-docs!2076
-rw-r--r-- | Rules | 1 | ||||
-rw-r--r-- | lib/filters/table_sticky_headings.rb | 25 |
2 files changed, 26 insertions, 0 deletions
@@ -95,6 +95,7 @@ compile '/**/*.md' do filter :admonition filter :icons filter :introduced_in + filter :table_sticky_headings if item[:layout].nil? layout '/default.*' 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 |