console_renderer 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/console_renderer.rb +2 -35
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5063c6b2c041be1ee569ccdc2ef00937f554dd9e
|
4
|
+
data.tar.gz: 41b7ce6af930a0f0a7f53a7b2273796847a965c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4839fb3a3c4d4a1292d26522dca0ff2dec7540ab25eac466c52426ae17361e857ae4f8c38cc586c345a5d6d79f80fb77f9fca3473751fbea3de26f39198f23ee
|
7
|
+
data.tar.gz: e95a1aede230f46096b521ad4c283bb43229e899867b3d7a88b922ca7fc5688efe2f4baea66c9a7b2ca58d8a3eb257695b474a068cbf63a5132b4e0aeed24024
|
data/lib/console_renderer.rb
CHANGED
@@ -1,44 +1,11 @@
|
|
1
1
|
require 'redcarpet'
|
2
2
|
require 'rainbow'
|
3
|
-
require 'syntax/convertors/html'
|
4
3
|
|
5
4
|
class ConsoleRenderer < Redcarpet::Render::Base
|
6
5
|
|
7
6
|
@@listitemid = 0
|
8
|
-
def self.syntax_highlight(code, inline=true)
|
9
|
-
tokenizer = Syntax.load "ruby"
|
10
|
-
|
11
|
-
c_line = ""
|
12
|
-
|
13
|
-
code.split("\n").each do |line|
|
14
|
-
c_line += " " unless inline
|
15
|
-
begin
|
16
|
-
bkp = c_line
|
17
|
-
tokenizer.tokenize( line ) do |token|
|
18
|
-
case token.group.to_s
|
19
|
-
when "comment" then c_line = c_line + Rainbow(token).color(:green)
|
20
|
-
when "constant" then c_line = c_line + Rainbow(token).color(:blue)
|
21
|
-
when "expr" then c_line = c_line + Rainbow(token).color(:red)
|
22
|
-
when "ident" then c_line = c_line + Rainbow(token).color(:white)
|
23
|
-
when "keyword" then c_line = c_line + Rainbow(token).color(:yellow)
|
24
|
-
when "normal" then c_line = c_line + Rainbow(token).color(:cyan)
|
25
|
-
when "number" then c_line = c_line + Rainbow(token).color(:red)
|
26
|
-
when "punct" then c_line = c_line + Rainbow(token).color(:white)
|
27
|
-
when "string" then c_line = c_line + Rainbow(token).color(:red)
|
28
|
-
when "symbol" then c_line = c_line + Rainbow(token).color(:green)
|
29
|
-
else c_line += token
|
30
|
-
end
|
31
|
-
end
|
32
|
-
rescue
|
33
|
-
c_line = bkp + line
|
34
|
-
end
|
35
|
-
c_line += "\n" unless inline
|
36
|
-
end
|
37
|
-
c_line
|
38
|
-
end
|
39
|
-
|
40
7
|
def block_code(code, language)
|
41
|
-
"\n" +
|
8
|
+
"\n" + code + "\n"
|
42
9
|
end
|
43
10
|
|
44
11
|
def block_quote(quote)
|
@@ -102,7 +69,7 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
102
69
|
end
|
103
70
|
|
104
71
|
def codespan(code)
|
105
|
-
|
72
|
+
code
|
106
73
|
end
|
107
74
|
|
108
75
|
def double_emphasis(text)
|