console_renderer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/console_renderer +6 -0
- data/lib/console_renderer.rb +137 -0
- metadata +68 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'rainbow'
|
3
|
+
require 'syntax/convertors/html'
|
4
|
+
|
5
|
+
class ConsoleRenderer < Redcarpet::Render::Base
|
6
|
+
|
7
|
+
def self.syntax_highlight(code, inline=true)
|
8
|
+
tokenizer = Syntax.load "ruby"
|
9
|
+
|
10
|
+
c_line = ""
|
11
|
+
|
12
|
+
code.split("\n").each do |line|
|
13
|
+
c_line += " " unless inline
|
14
|
+
begin
|
15
|
+
bkp = c_line
|
16
|
+
tokenizer.tokenize( line ) do |token|
|
17
|
+
case token.group.to_s
|
18
|
+
when "comment" then c_line = c_line + token.color("#6EE18F")
|
19
|
+
when "constant" then c_line = c_line + token.color("#3D3D79")
|
20
|
+
when "expr" then c_line = c_line + token.color(:white)
|
21
|
+
when "ident" then c_line = c_line + token.color("#AAAAAA")
|
22
|
+
when "keyword" then c_line = c_line + token.color("#FF73EC")
|
23
|
+
when "normal" then c_line = c_line + token.color(:cyan)
|
24
|
+
when "number" then c_line = c_line + token.color("#FF6300")
|
25
|
+
when "punct" then c_line = c_line + token.color(:white)
|
26
|
+
when "string" then c_line = c_line + token.color(:red)
|
27
|
+
when "symbol" then c_line = c_line + token.color(:green)
|
28
|
+
else c_line += token
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
c_line = bkp + line
|
33
|
+
end
|
34
|
+
c_line += "\n" unless inline
|
35
|
+
end
|
36
|
+
c_line
|
37
|
+
end
|
38
|
+
|
39
|
+
def block_code(code, language)
|
40
|
+
"\n" + (ConsoleRenderer.syntax_highlight(code, false)) + "\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def block_quote(quote)
|
44
|
+
ret = ""
|
45
|
+
quote.split("\n").each do |line|
|
46
|
+
ret += "|".color(:cyan) + line
|
47
|
+
end
|
48
|
+
ret
|
49
|
+
end
|
50
|
+
|
51
|
+
def block_html(raw_html)
|
52
|
+
raw_html
|
53
|
+
end
|
54
|
+
|
55
|
+
def header(text, header_level)
|
56
|
+
text = "\n" + text + "\n"
|
57
|
+
if header_level == 1
|
58
|
+
text.bright.underline
|
59
|
+
else
|
60
|
+
text.underline
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def hrule()
|
65
|
+
"___________________________".color(:yellow)
|
66
|
+
end
|
67
|
+
|
68
|
+
def list(contents, list_type)
|
69
|
+
contents
|
70
|
+
end
|
71
|
+
|
72
|
+
def list_item(text, list_type)
|
73
|
+
" " + "-".color(:cyan) + " " + text
|
74
|
+
end
|
75
|
+
|
76
|
+
def paragraph(text)
|
77
|
+
text + "\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
def table(header, body)
|
81
|
+
body
|
82
|
+
end
|
83
|
+
|
84
|
+
def table_row(content)
|
85
|
+
content
|
86
|
+
end
|
87
|
+
|
88
|
+
def table_cell(content, alignment)
|
89
|
+
content
|
90
|
+
end
|
91
|
+
|
92
|
+
def autolink(link, link_type)
|
93
|
+
link.color(:cyan)
|
94
|
+
end
|
95
|
+
|
96
|
+
def codespan(code)
|
97
|
+
ConsoleRenderer.syntax_highlight(code)
|
98
|
+
end
|
99
|
+
|
100
|
+
def double_emphasis(text)
|
101
|
+
text.underline.italic
|
102
|
+
end
|
103
|
+
|
104
|
+
def emphasis(text)
|
105
|
+
text.italic
|
106
|
+
end
|
107
|
+
|
108
|
+
def image(link, title, alt_text)
|
109
|
+
("<" + alt_text + ">").color(:green) + ("(image at: " + link + ")").color(:cyan)
|
110
|
+
end
|
111
|
+
|
112
|
+
def linebreak()
|
113
|
+
"\n\n"
|
114
|
+
end
|
115
|
+
|
116
|
+
def link(link, title, content)
|
117
|
+
(title || "") + " " + ("<" + link + ">").color(:cyan)
|
118
|
+
end
|
119
|
+
|
120
|
+
def raw_html(raw_html)
|
121
|
+
raw_html
|
122
|
+
end
|
123
|
+
|
124
|
+
def triple_emphasis(text)
|
125
|
+
text.bright.italic.underline
|
126
|
+
end
|
127
|
+
|
128
|
+
def strikethrough(text)
|
129
|
+
text
|
130
|
+
end
|
131
|
+
|
132
|
+
def superscript(text)
|
133
|
+
("^" + text).color(:red)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: console_renderer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Aditya Bhargava
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-02-01 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: bluemangroupie@gmail.com
|
24
|
+
executables:
|
25
|
+
- console_renderer
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/console_renderer.rb
|
32
|
+
- bin/console_renderer
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: https://github.com/egonSchiele/console_renderer
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
hash: 3
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.7
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A renderer for Redcarpet. Render Markdown to the command line!
|
67
|
+
test_files: []
|
68
|
+
|