diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2019-06-07 18:09:07 +0300 |
---|---|---|
committer | Marcia Ramos <marcia@gitlab.com> | 2019-06-07 18:09:07 +0300 |
commit | b016a6d847f551ef3e16eb7a0ab4ac8e4b38ec58 (patch) | |
tree | 9317620b7d8614111a93ea3f0da6ac645edf8573 /lib | |
parent | f5b25bfe79f10931082ba081a890aab60c98c1c8 (diff) |
Add special styling to "Introduced in" notes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/filters/introduced_in.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/filters/introduced_in.rb b/lib/filters/introduced_in.rb new file mode 100644 index 00000000..ac3ed9c6 --- /dev/null +++ b/lib/filters/introduced_in.rb @@ -0,0 +1,27 @@ +# encoding: utf-8 + +# Adapted from the admonition code on http://nanoc.ws/ +class IntroducedInFilter < Nanoc::Filter + + identifier :introduced_in + + 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('blockquote').each do |blockquote| + content = blockquote.inner_html + next if content !~ /(<a href="[^"]+">)?Introduced(<\/a>)? in (<a href="[^"]+">)?GitLab/mi + new_content = generate(content) + blockquote.replace(new_content) + end + doc.to_s + end + + def generate(content) + %[<div class="introduced-in">] + + content + + %[</div>] + end + +end |