lib/lookbook/services/markdown_renderer.rb in lookbook-1.5.5 vs lib/lookbook/services/markdown_renderer.rb in lookbook-2.0.0.beta.0
- old
+ new
@@ -4,11 +4,11 @@
class MarkdownRenderer < Service
attr_reader :text, :opts
def initialize(text, opts = {})
@text = text
- @opts = opts.to_h
+ @opts = Lookbook.config.markdown_options.merge(opts.to_h)
end
def call
clean_text = ActionViewAnnotationsStripper.call(text)
md = Redcarpet::Markdown.new(LookbookMarkdownRenderer, opts)
@@ -16,10 +16,20 @@
end
class LookbookMarkdownRenderer < Redcarpet::Render::HTML
def block_code(code, language = "ruby")
line_numbers = language.to_s.end_with? "-numbered"
- ApplicationController.render(Lookbook::Code::Component.new(source: code, language: language.to_s.chomp("-numbered"), line_numbers: line_numbers), layout: nil)
+ ApplicationController.render(Lookbook::Code::Component.new(**{
+ source: code,
+ language: language.to_s.chomp("-numbered"),
+ line_numbers: line_numbers
+ }), layout: nil)
+ end
+
+ def postprocess(full_document)
+ full_document&.gsub!("<p><lookbook", "<lookbook")
+ full_document&.gsub!("</lookbook-embed></p>", "</lookbook-embed>")
+ full_document
end
end
end
end