# frozen_string_literal: true # # 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 @incremental_id = 0 doc = Nokogiri::HTML.fragment(content.dup) doc.css('blockquote').each do |blockquote| content = blockquote.inner_html # Searches for a blockquote with either: # - "deprecated in" # - "introduced in" # - "moved to" # - "recommended in" # - "removed in" # - "renamed in" # - "changed in" # - "enabled in" # ...followed by "GitLab" next unless content.match?(%r{()?( introduced| enabled| (re)?moved| changed| deprecated| renamed| recommended )()?(.*)? (in|to).*GitLab}xmi) new_content = generate(content) blockquote.replace(new_content) end doc.to_s end def generate(content) @incremental_id += 1 # If the content is a list of items, collapse the content. if content.match?(%r{
    }i) %(
    Version history) + %() + %(
    #{content}
    ) else %(
    #{content}
    ) end end end