Add kramdown renderer for markdown files

This commit is contained in:
James Smith committed 2026-10-15 15:06:44 +01:00
1 parent 81b3fe14c4
commit 6f985ffc94
2 files changed
+41

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
module Components::Renderers
class Kramdown < Components::Renderers::Base
include Phlex::Rails::Helpers::Sanitize
def self.supports?(file)
FileHandlers::Kramdown.can_load? file&.mime_type
end
def before_template
@content = @file.attachment.read.force_encoding(Encoding::UTF_8).encode("UTF-8", invalid: :replace)
end
def view_template
div class: "card" do
article class: "card-body" do
sanitize(
::Kramdown::Document.new(
@content,
header_offset: 2,
input: "GFM"
).to_html
)
end
end
end
end
end
+14
View File
@@ -0,0 +1,14 @@
class FileHandlers::Kramdown < FileHandlers::Base
# i18n-tasks-use t("file_handlers.handlers.kramdown")
ENVIRONMENTS = [:browser].freeze
INPUT_TYPES = Mime::EXTENSION_LOOKUP.slice("md").values.freeze
def self.priority
200
end
def self.component
Components::Renderers::Kramdown
end
end