Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2021-08-25 11:35:21 +0300
committerAchilleas Pipinellis <axil@gitlab.com>2021-08-25 11:35:21 +0300
commit8089a93904d137b8cfc3c8b9bfe7e439cbaa9d10 (patch)
tree9419b6375a2447edec293bd7ce52f6cddf125416 /lib
parent82ffd7ac8b036b8ed7ce7a516c4b5717a061fa71 (diff)
Add a table sticky headings filter
This wraps all tables inside a div with a class of table-sticky-headings, so that we can style them. See https://gitlab.com/gitlab-org/gitlab-docs/-/issues/1076
Diffstat (limited to 'lib')
-rw-r--r--lib/filters/table_sticky_headings.rb25
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