From ce2e4c010c68527f10e0c7b3df59f1c2f22ddc6f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 11 Oct 2023 14:29:21 -0400 Subject: Syntax highlighting --- app/assets/stylesheets/main/rouge.css.erb | 11 +++++++++++ app/helpers/application_helper.rb | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/assets/stylesheets/main/rouge.css.erb (limited to 'app') diff --git a/app/assets/stylesheets/main/rouge.css.erb b/app/assets/stylesheets/main/rouge.css.erb new file mode 100644 index 0000000..120dc02 --- /dev/null +++ b/app/assets/stylesheets/main/rouge.css.erb @@ -0,0 +1,11 @@ +<%= Rouge::Themes::Pastie.render(:scope => '.highlight') %> + +.highlight { + background-color: white; + padding: 1em; +} + +.highlight .err { + color: #a61717; + background-color: #f5f7f9; +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f12cdd4..861dd11 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,13 @@ +require 'redcarpet' +require 'rouge' +require 'rouge/plugins/redcarpet' + module ApplicationHelper + class HTML < Redcarpet::Render::HTML + include Rouge::Plugins::Redcarpet # yep, that's it. + end + def title(text) content_for :title, text end @@ -12,8 +20,8 @@ module ApplicationHelper end def markdown(text) - options = %i[] - Markdown.new(text, *options).to_html.html_safe + options = { fenced_code_blocks: true, highlight: true } + Redcarpet::Markdown.new(HTML.new(), options).render(text).html_safe end end -- cgit 1.4.1