From 1eecacc86a5899fb08f9d8e3aacf08a809aed3cf Mon Sep 17 00:00:00 2001 From: Vijay Swamidass Date: Thu, 22 Aug 2024 15:21:28 -0700 Subject: [PATCH] add table and code support --- app/helpers/markdown_helper.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/helpers/markdown_helper.rb b/app/helpers/markdown_helper.rb index 654c8b6..3c06919 100644 --- a/app/helpers/markdown_helper.rb +++ b/app/helpers/markdown_helper.rb @@ -29,7 +29,7 @@ def codespan(quote) end def block_code(code, _language) - %(#{escape_html(code)}) + %(#{escape_html(code)}) end def header(title, level) @@ -47,6 +47,23 @@ def list_item(content, _list_type) %(
  • #{content}
  • ) end + def table(header, body) + content = <<-HTML + + #{header} + + + #{body} + + HTML + + %(#{content}
    ) + end + + def table_row(content) + %(#{content}) + end + def list(content, list_type) case list_type when :ordered @@ -62,7 +79,7 @@ def render_markdown(text) renderer = CustomRender.new(escape_html: true) # renderer = Redcarpet::Render::HTML.new(hard_wrap: true) - markdown = Redcarpet::Markdown.new(renderer, {}) + markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true, tables: true) markdown.render(text).html_safe end end