Class: SatanicPages::MarkdownTemplateHandler

Inherits:
MarkdownRails::Renderer::Rails
  • Object
show all
Includes:
Redcarpet::Render::SmartyPants
Defined in:
lib/satanic_pages/markdown_template_handler.rb

Constant Summary collapse

TEMPLATE_ANNOTATION_REGEX =
/<!\p{Pd}{1,2}\s*(BEGIN|END)\s+.*?\s*\p{Pd}{1,2}>/m

Instance Method Summary collapse

Instance Method Details

#preprocess(source) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/satanic_pages/markdown_template_handler.rb', line 9

def preprocess(source)
  frontmatter, rest = Frontmatter.parse(source)

  render(inline: rest, handler: :erb, locals: {data: frontmatter})
    # Remove template comments (including SmartyPants converted dashes)
    .gsub(TEMPLATE_ANNOTATION_REGEX, "")
    # Force HTML tags to be inline
    .gsub(/<[^>]*?>/) { |tag| tag.gsub(/\n\s*/, " ") }
end