-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
There's currently no way to configure default HTML processors globally. If you want a processor to run on every markdownify call, you have to either:
- Pass
process: [MyProcessor]to everymarkdownifycall in every view - Prepend
Perron::MarkdownHelperto inject defaults — which works, but feels like it should be a first-class config option
For example, I have a processor that fixes an accessibility issue with CommonMarker's anchor links (adding tabindex="-1" to aria-hidden="true" anchors). This needs to run on all rendered markdown, so I'm currently doing:
Rails.application.config.to_prepare do
Perron::MarkdownHelper.prepend(Module.new do
def markdownify(content = nil, process: [], &block)
super(content, process: process + [AnchorTabindexProcessor], &block)
end
end)
endProposal
Add a default_processors configuration option:
Perron.configure do |config|
config.default_processors = [AnchorTabindexProcessor, "target_blank"]
endThese would be prepended to whatever is passed via process: in individual markdownify calls, so per-call processors still work as expected:
<%# Runs AnchorTabindexProcessor, target_blank (from defaults), plus lazy_load_images %>
<%= markdownify @resource.content, process: %w[lazy_load_images] %>Implementation
This could be as simple as:
- Adding
default_processorstoPerron::Configuration(defaulting to[]) - Merging them in
MarkdownHelper#markdownify:
def markdownify(content = nil, process: [], &block)
text = block_given? ? capture(&block).strip_heredoc : content
all_processors = Perron.configuration.default_processors + Array(process)
Perron::Markdown.render(text, processors: all_processors)
endReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels