require "html/pipeline" class AdditionalMarkdownFilter < HTML::Pipeline::MarkdownFilter def initialize(text, context = nil, result = nil) # do preprocessing, then call HTML::Pipeline::Markdown format_command_line! text format_helper! text super text, context, result end def call # initialize HTML::Pipeline::Markdown, then do post-processing html = super format_intro! html format_os_blocks! html format_admonition! html html end def format_command_line!(text) text.gsub! /\n?``` command-line(.+?)```/m do |block| block.gsub! /^``` command-line/, '
' block.gsub! /^```$/, "\n" block.gsub!(/^\$ (.+)$/) { %Q|#{$1.rstrip}| } block.gsub!(/^(\# .+)$/) { %Q|#{$1.rstrip}| } block.gsub!(/^> (.+)$/) { %Q|# #{$1.rstrip}| } block end end def format_helper!(text) text.gsub! /\n?``` helper(.+?)```/m do |block| block.gsub! /^``` helper\s*/, '' block.gsub! /^```$/, '' header = '' block.gsub! /^#### (.+?)$/ do header = $1.strip '' end content = block.strip content = "
#{content}
" unless content =~ /^{{#intro}}<\/p>/, '
{{\/intro}}<\/p>/, '
{{#mac}}<\/p>/, '
{{#windows}}<\/p>/, '
{{#linux}}<\/p>/, '
{{#all}}<\/p>/, '
{{\/(mac|windows|linux|all)}}<\/p>/, '
{{#(tip|warning|error)}}<\/p>/, '
{{\/(tip|warning|error)}}<\/p>/, '