# 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
next if content !~ /()?((introduced(<\/a>)? in)|(moved(<\/a>)? to))()?.*GitLab/mi
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 =~ //i
%(Version history) +
%(
) +
%(
#{content}
)
else
%(#{content}
)
end
end
end