From ce2e4c010c68527f10e0c7b3df59f1c2f22ddc6f Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 11 Oct 2023 14:29:21 -0400 Subject: Syntax highlighting --- Gemfile | 1 + Gemfile.lock | 2 ++ app/assets/stylesheets/main/rouge.css.erb | 11 +++++++++++ app/helpers/application_helper.rb | 12 ++++++++++-- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 app/assets/stylesheets/main/rouge.css.erb diff --git a/Gemfile b/Gemfile index 1230941..e467375 100644 --- a/Gemfile +++ b/Gemfile @@ -78,3 +78,4 @@ gem 'sprockets', '3.7.2' gem 'lingo', git: "https://git.fourisland.com/lingo", glob: "rails/*.gemspec", branch: "main" gem 'will_paginate', '~> 4.0' gem 'redcarpet' +gem 'rouge' diff --git a/Gemfile.lock b/Gemfile.lock index ac1e851..3ad7e17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -270,6 +270,7 @@ GEM actionpack (>= 5.2) railties (>= 5.2) rexml (3.2.6) + rouge (4.1.3) rubyzip (2.3.2) sassc (2.4.0) ffi (~> 1.9) @@ -364,6 +365,7 @@ DEPENDENCIES pokeviewer! rails (~> 7.0.3) redcarpet + rouge sassc-rails selenium-webdriver spring 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