mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-01 23:16:16 +00:00
Add colorize_without_wrapper
This commit is contained in:
@@ -137,5 +137,10 @@ module Linguist
|
|||||||
return if !text? || large?
|
return if !text? || large?
|
||||||
lexer.colorize(data)
|
lexer.colorize(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def colorize_without_wrapper
|
||||||
|
return if !text? || large?
|
||||||
|
lexer.colorize_without_wrapper(data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ module Linguist
|
|||||||
lexer.colorize(text)
|
lexer.colorize(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def colorize_without_wrapper(text)
|
||||||
|
lexer.colorize_without_wrapper(text)
|
||||||
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
eql?(other)
|
eql?(other)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,7 +23,15 @@ module Linguist
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colorize(text)
|
def colorize(text)
|
||||||
Albino.colorize(text, to_s)
|
Albino.colorize(text, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
def colorize_without_wrapper(text)
|
||||||
|
if text = colorize(text)
|
||||||
|
text[%r{<div class="highlight"><pre>(.*?)</pre>\s*</div>}m, 1]
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
|
|||||||
@@ -179,4 +179,11 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_colorize_without_wrapper
|
||||||
|
assert_equal <<-HTML, blob("foo.rb").colorize_without_wrapper
|
||||||
|
<span class="k">module</span> <span class="nn">Foo</span>
|
||||||
|
<span class="k">end</span>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -111,4 +111,16 @@ class TestLanguage < Test::Unit::TestCase
|
|||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_colorize_without_wrapper
|
||||||
|
assert_equal <<-HTML, Language['Text'].colorize_without_wrapper("Hello")
|
||||||
|
Hello
|
||||||
|
HTML
|
||||||
|
|
||||||
|
assert_equal <<-HTML, Language['Ruby'].colorize_without_wrapper("def foo\n 'foo'\nend\n")
|
||||||
|
<span class="k">def</span> <span class="nf">foo</span>
|
||||||
|
<span class="s1">'foo'</span>
|
||||||
|
<span class="k">end</span>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,4 +50,16 @@ class TestLexer < Test::Unit::TestCase
|
|||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_colorize_without_wrapper
|
||||||
|
assert_equal <<-HTML, Lexer['Text only'].colorize_without_wrapper("Hello")
|
||||||
|
Hello
|
||||||
|
HTML
|
||||||
|
|
||||||
|
assert_equal <<-HTML, Lexer['Ruby'].colorize_without_wrapper("def foo\n 'foo'\nend\n")
|
||||||
|
<span class="k">def</span> <span class="nf">foo</span>
|
||||||
|
<span class="s1">'foo'</span>
|
||||||
|
<span class="k">end</span>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user