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:
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