diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2021-08-15 20:59:04 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2021-08-15 20:59:04 +0000 |
commit | 5699253da6330447f7a7d3b4cf8a238f9d4608cf (patch) | |
tree | 471817131b61f2ababb1c0924748784f6603d605 /test | |
parent | 12b2dd309896d7ebecbba8677de6bc049c21a26c (diff) | |
download | redmine-5699253da6330447f7a7d3b4cf8a238f9d4608cf.tar.gz redmine-5699253da6330447f7a7d3b4cf8a238f9d4608cf.zip |
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
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb | 29 | ||||
-rw-r--r-- | test/unit/lib/redmine/wiki_formatting/common_mark/syntax_highlight_filter_test.rb | 22 |
2 files changed, 36 insertions, 15 deletions
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 "<pre>test\n</pre>", 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) </code></pre> HTML expected = <<~HTML - <pre><code class="ruby syntaxhl"> + <pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">def</span> <span class="nf">foo</span> <span class="k">end</span> </code></pre> @@ -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 + <pre><code class="language-c-k&r"> + int i; + </code></pre> + HTML + expected = <<~HTML + <pre><code data-language="c-k&r"> + int i; + </code></pre> + HTML + assert_equal expected, filter(input) + end + + def test_should_strip_code_class_and_preserve_data_language_attr_for_unknown_language input = <<~HTML <pre><code class="language-foobar"> def foo @@ -54,10 +68,10 @@ if Object.const_defined?(:CommonMarker) </code></pre> HTML expected = <<~HTML - <pre> + <pre><code data-language="foobar"> def foo end - </pre> + </code></pre> HTML assert_equal expected, filter(input) end |