console_renderer 0.0.3 → 0.0.4
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.
- data/bin/console_renderer +1 -0
- data/lib/console_renderer.rb +22 -14
- metadata +4 -4
data/bin/console_renderer
CHANGED
data/lib/console_renderer.rb
CHANGED
@@ -4,6 +4,7 @@ require 'syntax/convertors/html'
|
|
4
4
|
|
5
5
|
class ConsoleRenderer < Redcarpet::Render::Base
|
6
6
|
|
7
|
+
@@listitemid = 0
|
7
8
|
def self.syntax_highlight(code, inline=true)
|
8
9
|
tokenizer = Syntax.load "ruby"
|
9
10
|
|
@@ -15,13 +16,13 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
15
16
|
bkp = c_line
|
16
17
|
tokenizer.tokenize( line ) do |token|
|
17
18
|
case token.group.to_s
|
18
|
-
when "comment" then c_line = c_line + token.color(
|
19
|
-
when "constant" then c_line = c_line + token.color(
|
20
|
-
when "expr" then c_line = c_line + token.color(:
|
21
|
-
when "ident" then c_line = c_line + token.color(
|
22
|
-
when "keyword" then c_line = c_line + token.color(
|
19
|
+
when "comment" then c_line = c_line + token.color(:green)
|
20
|
+
when "constant" then c_line = c_line + token.color(:blue)
|
21
|
+
when "expr" then c_line = c_line + token.color(:red)
|
22
|
+
when "ident" then c_line = c_line + token.color(:white)
|
23
|
+
when "keyword" then c_line = c_line + token.color(:yellow)
|
23
24
|
when "normal" then c_line = c_line + token.color(:cyan)
|
24
|
-
when "number" then c_line = c_line + token.color(
|
25
|
+
when "number" then c_line = c_line + token.color(:red)
|
25
26
|
when "punct" then c_line = c_line + token.color(:white)
|
26
27
|
when "string" then c_line = c_line + token.color(:red)
|
27
28
|
when "symbol" then c_line = c_line + token.color(:green)
|
@@ -41,11 +42,11 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def block_quote(quote)
|
44
|
-
ret = ""
|
45
|
+
ret = "\n"
|
45
46
|
quote.split("\n").each do |line|
|
46
47
|
ret += "|".color(:cyan) + line
|
47
48
|
end
|
48
|
-
ret
|
49
|
+
ret + "\n"
|
49
50
|
end
|
50
51
|
|
51
52
|
def block_html(raw_html)
|
@@ -62,15 +63,22 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def hrule()
|
65
|
-
"___________________________".color(:yellow)
|
66
|
+
"___________________________\n".color(:yellow)
|
66
67
|
end
|
67
68
|
|
68
69
|
def list(contents, list_type)
|
70
|
+
@@listitemid = 0
|
69
71
|
contents
|
70
72
|
end
|
71
73
|
|
72
74
|
def list_item(text, list_type)
|
73
|
-
|
75
|
+
case list_type
|
76
|
+
when :unordered
|
77
|
+
" " + "-".color(:cyan) + " " + text
|
78
|
+
when :ordered
|
79
|
+
@@listitemid += 1
|
80
|
+
" " + (@@listitemid.to_s + ".").color(:cyan) + " " + text
|
81
|
+
end
|
74
82
|
end
|
75
83
|
|
76
84
|
def paragraph(text)
|
@@ -98,11 +106,11 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
98
106
|
end
|
99
107
|
|
100
108
|
def double_emphasis(text)
|
101
|
-
text.
|
109
|
+
text.bright
|
102
110
|
end
|
103
111
|
|
104
112
|
def emphasis(text)
|
105
|
-
text.
|
113
|
+
text.underline
|
106
114
|
end
|
107
115
|
|
108
116
|
def image(link, title, alt_text)
|
@@ -114,7 +122,7 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
114
122
|
end
|
115
123
|
|
116
124
|
def link(link, title, content)
|
117
|
-
(
|
125
|
+
(content || "") + " " + ("<#{link}#{title ? " :" + title : ''}>").color(:cyan)
|
118
126
|
end
|
119
127
|
|
120
128
|
def raw_html(raw_html)
|
@@ -122,7 +130,7 @@ class ConsoleRenderer < Redcarpet::Render::Base
|
|
122
130
|
end
|
123
131
|
|
124
132
|
def triple_emphasis(text)
|
125
|
-
text.bright.
|
133
|
+
text.bright.underline
|
126
134
|
end
|
127
135
|
|
128
136
|
def strikethrough(text)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_renderer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aditya Bhargava
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-03-09 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|