Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add table and code support #42

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions app/helpers/markdown_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def codespan(quote)
end

def block_code(code, _language)
%(<code class="block bg-stone-800 text-white font-light p-5">#{escape_html(code)}</code>)
%(<code class="block bg-stone-800 text-white font-light p-5 rounded whitespace-pre-line mb-3">#{escape_html(code)}</code>)
end

def header(title, level)
Expand All @@ -47,6 +47,23 @@ def list_item(content, _list_type)
%(<li class="py-2 ">#{content}</li>)
end

def table(header, body)
content = <<-HTML
<thead class="p-2 text-xl">
#{header}
</thead>
<tbody class="p-2">
#{body}
</tbody>
HTML

%(<table class="text-stone-700 text-left border-separate ml-3">#{content}</table>)
end

def table_row(content)
%(<tr class="text-stone-700 text-left p-2">#{content}</tr>)
end

def list(content, list_type)
case list_type
when :ordered
Expand All @@ -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
Loading