module LadyJosephine
module Redcarpet
class CustomMarkdownFormatter < ::Redcarpet::Render::SmartyHTML
def block_code(code, language)
"
" << code << "
"
end
def paragraph(text)
text
end
def block_quote(text)
text
end
def list(contents, list_type)
contents
end
def codespan(code)
code
end
def postprocess(full_document)
full_document.gsub(/<br>/, "
\n")
end
def preprocess(full_document)
sanitized_document = full_document.gsub(/\"(.*?)\"/) do
"„#{$1}“"
end
sanitized_document.gsub!(/\./, "\\.")
sanitized_document.gsub!(/\n/, "
\n")
sanitized_document
end
def link(link, title, context)
if is_internal_link?(link)
"#{context}"
else
"#{context}"
end
end
private
def is_internal_link?(link)
host = Addressable::URI.parse(link).host
host.nil? || host.casecmp(host_from_config) == 0
end
def host_from_config
config_host = Krautmag.config.action_mailer.default_url_options[:host]
unless config_host =~ /^http(s)?:\/\//i
config_host = "http://" + config_host
end
URI(config_host).host
end
end
end
end