From 72620ea1b725f8776087e516cdc3dd13f5f8e075 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 17 Jan 2017 13:06:12 -0500 Subject: [PATCH] Fix SyntaxHighlightFilter spec --- app/assets/javascripts/copy_as_gfm.js.es6 | 2 +- lib/banzai/filter/syntax_highlight_filter.rb | 1 + spec/lib/banzai/filter/syntax_highlight_filter_spec.rb | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/copy_as_gfm.js.es6 b/app/assets/javascripts/copy_as_gfm.js.es6 index 38ec6e4732a..0d1e9b0a952 100644 --- a/app/assets/javascripts/copy_as_gfm.js.es6 +++ b/app/assets/javascripts/copy_as_gfm.js.es6 @@ -89,7 +89,7 @@ SyntaxHighlightFilter: { 'pre.code.highlight'(el, text) { let lang = el.getAttribute('lang'); - if (lang === 'text') { + if (lang === 'plaintext') { lang = ''; } return '```' + lang + '\n' + text.trim() + '\n```'; diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 933103abb92..a447e2b8bff 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -27,6 +27,7 @@ module Banzai css_classes << " js-syntax-highlight #{lang}" rescue + lang = nil # Gracefully handle syntax highlighter bugs/errors to ensure # users can still access an issue/comment/etc. end diff --git a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index d265d29ee86..69e3c52b35a 100644 --- a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -6,21 +6,21 @@ describe Banzai::Filter::SyntaxHighlightFilter, lib: true do context "when no language is specified" do it "highlights as plaintext" do result = filter('
def fun end
') - expect(result.to_html).to eq('
def fun end
') + expect(result.to_html).to eq('
def fun end
') end end context "when a valid language is specified" do it "highlights as that language" do result = filter('
def fun end
') - expect(result.to_html).to eq('
def fun end
') + expect(result.to_html).to eq('
def fun end
') end end context "when an invalid language is specified" do it "highlights as plaintext" do result = filter('
This is a test
') - expect(result.to_html).to eq('
This is a test
') + expect(result.to_html).to eq('
This is a test
') end end @@ -31,7 +31,7 @@ describe Banzai::Filter::SyntaxHighlightFilter, lib: true do it "highlights as plaintext" do result = filter('
This is a test
') - expect(result.to_html).to eq('
This is a test
') + expect(result.to_html).to eq('
This is a test
') end end end