docs/components/markdown.rb in phlex-0.4.0 vs docs/components/markdown.rb in phlex-0.5.0
- old
+ new
@@ -1,40 +1,25 @@
# frozen_string_literal: true
module Components
- class Markdown < Phlex::View
- class Render < Redcarpet::Render::HTML
- include Redcarpet::Render::SmartyPants
+ class Markdown < Phlex::Markdown
+ def code(&content)
+ render CodeSpan.new, &content
+ end
- def header(text, level)
- case level
- when 1
- Title.new.call { CGI.unescapeHTML(text) }
- else
- Heading.new.call { CGI.unescapeHTML(text) }
- end
- end
+ def code_block(code, language:)
+ render CodeBlock.new(code.gsub(/(?:^|\G) {4}/m, " "), syntax: language)
+ end
- def codespan(code)
- CodeSpan.new.call { code }
- end
-
- def block_code(code, language)
- CodeBlock.new(code.gsub(/(?:^|\G) {4}/m, " "), syntax: language).call
- end
-
- def html_escape(input)
- input
- end
+ def h1(&content)
+ render Title.new, &content
end
- MARKDOWN = Redcarpet::Markdown.new(Render.new, filter_html: false, autolink: true, fenced_code_blocks: true, tables: true, highlight: true, escape_html: false)
-
- def initialize(content)
- @content = content
+ def h2(&content)
+ render Heading.new, &content
end
- def template
- raw MARKDOWN.render(@content)
+ def a(**attributes, &content)
+ super(class: "font-bold text-red-600 underline underline-offset-4", **attributes, &content)
end
end
end