@@ -610,3 +610,50 @@ def test_doc_dlist
610610 RD
611611 end
612612end
613+
614+ # lang 指定付きコードブロックのハイライト(ruby は Ripper ベースの
615+ # SyntaxHighlighter、その他の言語は Rouge、未知の言語はエスケープのみ)
616+ class TestMDCompilerRougeHighlight < Test ::Unit ::TestCase
617+ def setup
618+ @dummy = 'dummy'
619+ @u = BitClust ::URLMapper . new ( Hash . new { @dummy } )
620+ @db = BitClust ::MethodDatabase . dummy ( "version" => "2.0.0" )
621+ @md = BitClust ::MDCompiler . new ( @u , 1 , { :database => @db , :gfm => true } )
622+ @rd = BitClust ::RDCompiler . new ( @u , 1 , { :database => @db } )
623+ end
624+
625+ def test_c_fence_is_highlighted_with_rouge
626+ html = @md . compile ( "```c\n int x = 1; /* comment */\n ```\n " )
627+ assert_match ( /<pre class="highlight c">/ , html )
628+ assert_match ( %r{<span class="kt">int</span>} , html )
629+ assert_match ( %r{<span class="cm">/\* comment \* /</span>} , html )
630+ end
631+
632+ def test_ruby_alias_rb_uses_bitclust_highlighter
633+ ruby_html = @md . compile ( "```ruby\n puts 1\n ```\n " )
634+ rb_html = @md . compile ( "```rb\n puts 1\n ```\n " )
635+ assert_equal ( ruby_html . sub ( 'highlight ruby' , 'highlight rb' ) , rb_html )
636+ # bitclust の SyntaxHighlighter 由来のマークアップ(Rouge の Ruby lexer ではなく)
637+ assert_match ( %r{<span class="nb">puts</span>} , rb_html )
638+ end
639+
640+ def test_unknown_lang_fence_is_escaped
641+ html = @md . compile ( "```nosuchlang\n <b>&raw</b>\n ```\n " )
642+ assert_match ( /<pre class="highlight nosuchlang">/ , html )
643+ assert_match ( /<b>&raw<\/ b>/ , html )
644+ assert_not_match ( /<b>/ , html )
645+ end
646+
647+ def test_text_fence_is_escaped_without_highlight
648+ html = @md . compile ( "```text\n <b>plain</b>\n ```\n " )
649+ assert_match ( /<b>plain<\/ b>/ , html )
650+ assert_not_match ( /<b>plain/ , html )
651+ end
652+
653+ def test_rd_emlist_with_c_lang_is_equivalent
654+ rd_src = "//emlist[キャプション][c]{\n int x = 1;\n //}\n "
655+ md_src = BitClust ::RRDToMarkdown . convert ( rd_src )
656+ assert_equal ( @rd . compile ( rd_src ) , @md . compile ( md_src ) , "md source:\n #{ md_src } " )
657+ assert_match ( %r{<span class="kt">int</span>} , @rd . compile ( rd_src ) )
658+ end
659+ end
0 commit comments