class Content::Pipeline::Filters::Markdown
Private Instance Methods
backtick(str)
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 102 def backtick(str) str.gsub(/^`{3}(\s?[a-zA-Z0-9]+)?$/, "~~~\\1") end
default()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 14 def default jruby? ? :kramdown : :redcarpet end
markdown()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 19 def markdown @type = @opts.fetch(:type, default) @str = backtick(@str) @str = case when @type =~ /\Akramdown\Z/ then parse_kramdown when @type =~ /\Agithub|gfm\Z/ then parse_github when @type =~ /\Aredcarpet\Z/ then parse_redcarpet when @type =~ /\Amarkdown|md\Z/ begin parse_redcarpet; rescue LoadError begin parse_kramdown; rescue LoadError parse_github end end else # Actually needed now days. raise UnknownParserError, @type end end
normalize_kramdown(str)
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 107 def normalize_kramdown(str) str.gsub( /<pre><code class="language-([A-Za-z0-9]+)">/, '<pre lang="\\1"><code>' ) end
parse_github()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 52 def parse_github require "github/markdown" type = @type == :github ? :gfm : @type GitHub::Markdown.to_html(@str, type).strip end
parse_kramdown()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 59 def parse_kramdown (@opts[:parser_opts] ||= {}).merge!({ :enable_coderay => false }) require "kramdown" str = Kramdown::Document.new(@str, @opts[:parser_opts]) normalize_kramdown(str.to_html).strip end
parse_redcarpet()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 39 def parse_redcarpet require "redcarpet" with = Redcarpet::Render::HTML (@opts[:parser_opts] ||= {}).merge!({ :fenced_code_blocks => true }) Redcarpet::Markdown.new(with, @opts[:parser_opts]).render( @str ) end
strip_html()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 70 def strip_html if @opts[:safe] @str = @str.to_nokogiri_fragment private_methods(false).keep_if { |m| m =~ /\Astrip_/ }.each do |m| unless m == :strip_html then send(m) end end end end
strip_image()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 93 def strip_image @str.xpath(".//img").each do |n| if n.parent.children.count == 1 then n.parent.remove else n.remove end end end
strip_links()
click to toggle source
# File lib/content/pipeline/filters/markdown.rb, line 82 def strip_links @str.xpath(".//a").each do |n| n.replace( n[ :href ] ) end end