diff options
Diffstat (limited to 'lib/banzai/filter/markdown_filter.rb')
-rw-r--r-- | lib/banzai/filter/markdown_filter.rb | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/banzai/filter/markdown_filter.rb b/lib/banzai/filter/markdown_filter.rb index e6a0cdfe020..5f442ed12d4 100644 --- a/lib/banzai/filter/markdown_filter.rb +++ b/lib/banzai/filter/markdown_filter.rb @@ -3,12 +3,13 @@ module Banzai module Filter class MarkdownFilter < HTML::Pipeline::TextFilter - DEFAULT_ENGINE = :common_mark + RUST_ENGINE = :glfm_markdown # glfm_markdown/comrak + RUBY_ENGINE = :common_mark # original commonmarker/cmark-gfm def initialize(text, context = nil, result = nil) super(text, context, result) - @renderer = self.class.render_engine(context[:markdown_engine]).new(context) + @renderer = render_engine.new(@context) @text = @text.delete("\r") end @@ -16,13 +17,27 @@ module Banzai @renderer.render(@text).rstrip end - class << self - def render_engine(engine_from_context) - "Banzai::Filter::MarkdownEngines::#{engine(engine_from_context)}".constantize - rescue NameError - raise NameError, "`#{engine_from_context}` is unknown markdown engine" - end + def render_engine + "Banzai::Filter::MarkdownEngines::#{engine}".constantize + rescue NameError + raise NameError, "`#{engine_class}` is unknown markdown engine" + end + + private + + def engine + engine = context[:markdown_engine] || default_engine + + engine.to_s.classify + end + + def default_engine + return RUST_ENGINE if Feature.enabled?(:markdown_rust, context[:project]) + RUBY_ENGINE + end + + class << self # Parses string representing a sourcepos in format # "start_row:start_column-end_row:end_column" into 0-based # attributes. For example, "1:10-14:1" becomes @@ -42,14 +57,6 @@ module Banzai end: { row: [1, end_row.to_i].max - 1, col: [1, end_col.to_i].max - 1 } } end - - private - - def engine(engine_from_context) - engine_from_context ||= DEFAULT_ENGINE - - engine_from_context.to_s.classify - end end end end |