diff --git a/Gemfile b/Gemfile index 3acef3a..156ae5c 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,8 @@ gem "stimulus-rails" # Build JSON APIs with ease [https://github.com/rails/jbuilder] gem "jbuilder" +gem "redcarpet" + # Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] # gem "bcrypt", "~> 3.1.7" diff --git a/Gemfile.lock b/Gemfile.lock index 66d6c35..62b9f0f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -381,6 +381,7 @@ GEM rdoc (6.14.1) erb psych (>= 4.0.0) + redcarpet (3.6.1) redis-client (0.24.0) connection_pool regexp_parser (2.10.0) @@ -590,6 +591,7 @@ DEPENDENCIES propshaft puma (>= 5.0) rails (~> 8.0.2) + redcarpet rubocop-rails-omakase selenium-webdriver sentry-rails diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..3acfde9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,7 @@ module ApplicationHelper + def markdown(text) + renderer = Redcarpet::Render::HTML.new(escape_html: true) + markdown = Redcarpet::Markdown.new(renderer, fenced_code_blocks: true) + markdown.render(text.to_s).html_safe + end end diff --git a/app/views/puzzles/_puzzles_table.html.erb b/app/views/puzzles/_puzzles_table.html.erb index a880c95..eeca005 100644 --- a/app/views/puzzles/_puzzles_table.html.erb +++ b/app/views/puzzles/_puzzles_table.html.erb @@ -15,9 +15,9 @@ <% puzzles.each do |puzzle| %> - <%= simple_format(puzzle.question) %> + <%= markdown(puzzle.question) %> <%= puzzle.answer %> - <%= puzzle.explanation %> + <%= markdown(puzzle.explanation) %> <% if puzzle.link.present? %> <%= link_to 'View', puzzle.link, target: '_blank' %> diff --git a/app/views/puzzles/update.turbo_stream.erb b/app/views/puzzles/update.turbo_stream.erb index 8f26218..e9dd213 100644 --- a/app/views/puzzles/update.turbo_stream.erb +++ b/app/views/puzzles/update.turbo_stream.erb @@ -1,9 +1,9 @@