Created
June 25, 2025 19:36
-
-
Save ryenski/88a2378839ae9b7b74825bd692e9d00c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redcarpet' | |
module MarkdownHandler | |
def self.erb | |
@erb ||= ActionView::Template.registered_template_handler(:erb) | |
end | |
def self.call(template, source) | |
_frontmatter, markdown = Page.parse_frontmatter(source, raw: true) | |
compiled_source = ActionView::OutputBuffer.new(erb.call(template, markdown)).to_s | |
# Stringify the output until RedCarpet can accept OutputBuffer. | |
# https://github.com/vmg/redcarpet/issues/783 | |
# https://gist.github.com/KeithP/5f959ca70f0b09a1ce5b5cf4831829f6 | |
compiled_source << '.to_s' | |
"Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, fenced_code_blocks: true).render(begin;#{compiled_source};end).html_safe" | |
end | |
end | |
ActionView::Template.register_template_handler :md, MarkdownHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment