From 5699253da6330447f7a7d3b4cf8a238f9d4608cf Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 15 Aug 2021 20:59:04 +0000 Subject: Add "data-language" attribute to code block with the user-supplied language for CommonMark formater (#35104, #32424). Patch by Martin Cizek. git-svn-id: http://svn.redmine.org/redmine/trunk@21182 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../wiki_formatting/common_mark/formatter_test.rb | 29 ++++++++++++++-------- .../common_mark/syntax_highlight_filter_test.rb | 22 +++++++++++++--- 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb index d121d5425..cd5e89931 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb @@ -94,24 +94,31 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase end def test_should_support_syntax_highlight - text = <<-STR - ~~~ruby - def foo - end - ~~~ + text = <<~STR + ~~~ruby + def foo + end + ~~~ STR assert_select_in format(text), 'pre code.ruby.syntaxhl' do assert_select 'span.k', :text => 'def' + assert_select "[data-language='ruby']" end end - def test_should_not_allow_invalid_language_for_code_blocks - text = <<-STR - ~~~foo - test - ~~~ + def test_should_support_syntax_highlight_for_language_with_special_chars + text = <<~STR + ~~~c++ + int main() { + } + ~~~ STR - assert_equal "
test\n
", format(text) + + assert_select_in format(text), 'pre' do + assert_select 'code[class=?]', "c++ syntaxhl" + assert_select 'span.kt', :text => 'int' + assert_select "[data-language=?]", "c++" + end end def test_external_links_should_have_external_css_class diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb index e7e782d53..586dbbe1e 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb @@ -38,7 +38,7 @@ if Object.const_defined?(:CommonMarker) HTML expected = <<~HTML -

+        

         def foo
         end
         
@@ -46,7 +46,21 @@ if Object.const_defined?(:CommonMarker) assert_equal expected, filter(input) end - def test_should_strip_code_for_unknown_lang + def test_should_highlight_supported_language_with_special_chars + input = <<~HTML +

+        int i;
+        
+ HTML + expected = <<~HTML +

+        int i;
+        
+ HTML + assert_equal expected, filter(input) + end + + def test_should_strip_code_class_and_preserve_data_language_attr_for_unknown_language input = <<~HTML

         def foo
@@ -54,10 +68,10 @@ if Object.const_defined?(:CommonMarker)
         
HTML expected = <<~HTML -
+        

         def foo
         end
-        
+
HTML assert_equal expected, filter(input) end -- cgit v1.2.3