html2ansi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemspec +1 -1
- data/VERSION +1 -1
- data/bin/html2ansi +2 -182
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e8ab4ee7076d454d787e65824c4aa0b2633a87174b683a4497caa6df938bb63
|
4
|
+
data.tar.gz: c20c48613e974012ab48dcf29df870ff48aa317d551274cd83a6cf38611447a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75ef456ea75b33eaad75575d84253ce45294a66cc29e070ba3d3a476e2f30fb368a2a0e4d4d85ea7c88700f0e55feb909062718ef5d084a4708edde7affc5d49
|
7
|
+
data.tar.gz: a2cf630a3fe98ef0e7a53b92209a0d5017e6b7837829bd39eaf3ee61cf550112a5192f3e9821e3531c86d1827b15700fac50da415c344e4e181106311a80ee04
|
data/.gemspec
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/html2ansi
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#######################################################################################
|
3
3
|
require 'html-renderer'
|
4
|
-
require 'terminal-table'
|
5
|
-
require 'term/ansicolor'
|
6
|
-
require 'coderay'
|
7
|
-
#######################################################################################
|
8
|
-
|
9
|
-
class String
|
10
|
-
# include ANSI::Mixin
|
11
|
-
include Term::ANSIColor
|
12
|
-
|
13
|
-
def grey; self.black.bold; end
|
14
|
-
end
|
15
|
-
|
16
4
|
#######################################################################################
|
17
5
|
|
18
6
|
def lesspipe(*args)
|
@@ -47,177 +35,9 @@ end
|
|
47
35
|
|
48
36
|
#######################################################################################
|
49
37
|
|
50
|
-
class ANSIRenderer < HTMLRenderer::Base
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
def indented?(text)
|
55
|
-
indent_sizes = text.lines.map{ |line| if line =~ /^(\s+)/ then $1 else '' end }.map(&:size)
|
56
|
-
indent_sizes.all? {|dent| dent > 0 }
|
57
|
-
end
|
58
|
-
|
59
|
-
def unwrap(text)
|
60
|
-
return text unless indented? text
|
61
|
-
text.lines.to_a.map(&:strip).join ' '
|
62
|
-
end
|
63
|
-
|
64
|
-
def indent(text,amount=2)
|
65
|
-
text.lines.map{|line| " "*amount + line }.join
|
66
|
-
end
|
67
|
-
|
68
|
-
def smash(s)
|
69
|
-
s&.downcase&.scan(/\w+/)&.join
|
70
|
-
end
|
71
|
-
|
72
|
-
def subscript(s)
|
73
|
-
"[#{s}]"
|
74
|
-
end
|
75
|
-
|
76
|
-
public
|
77
|
-
|
78
|
-
def normal_text(text)
|
79
|
-
text
|
80
|
-
end
|
81
|
-
|
82
|
-
def underline(content)
|
83
|
-
content.magenta.bold
|
84
|
-
end
|
85
|
-
|
86
|
-
def superscript(content)
|
87
|
-
"^(#{content})"
|
88
|
-
end
|
89
|
-
|
90
|
-
def link(link, title, content)
|
91
|
-
unless content&.[] /^Back /
|
92
|
-
str = ""
|
93
|
-
# str += "<15>#{content}</15>" if content
|
94
|
-
str += content.white.bold if content
|
95
|
-
if smash(link) != smash(content)
|
96
|
-
# str += " <8>(</8><11>#{link}</11><8>)</8>"
|
97
|
-
str += " #{"(".grey}#{link&.cyan&.bold}#{")".grey}"
|
98
|
-
end
|
99
|
-
|
100
|
-
str
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def anchor(name, title=nil, content=nil)
|
105
|
-
result = "Anchor: ##{name}"
|
106
|
-
result << " (#{title})" if title
|
107
|
-
result << "\n"
|
108
|
-
result << "#{content}\n" if content
|
109
|
-
result
|
110
|
-
end
|
111
|
-
|
112
|
-
def image(link, title, content)
|
113
|
-
link(link, nil, title)
|
114
|
-
end
|
115
|
-
|
116
|
-
def italic(text)
|
117
|
-
text.yellow.bold
|
118
|
-
end
|
119
|
-
|
120
|
-
def block_code(code, language)
|
121
|
-
language ||= :ruby
|
122
|
-
|
123
|
-
language = language[1..-1] if language[0] == "." # strip leading "."
|
124
|
-
language = :cpp if language == "C++"
|
125
|
-
|
126
|
-
require 'coderay'
|
127
|
-
"#{indent CodeRay.scan(code, language).term, 4}\n"
|
128
|
-
end
|
129
|
-
|
130
|
-
def block_quote(text)
|
131
|
-
indent paragraph(text)
|
132
|
-
end
|
133
|
-
|
134
|
-
def codespan(code)
|
135
|
-
code.cyan
|
136
|
-
end
|
137
|
-
|
138
|
-
def header(title, level, anchor=nil)
|
139
|
-
bar = ("-"*(title.size+4)).grey
|
140
|
-
|
141
|
-
title = case level
|
142
|
-
when 1 then title.bold.yellow
|
143
|
-
when 2 then title.bold.cyan
|
144
|
-
when 3 then title.bold.blue
|
145
|
-
else title.magenta
|
146
|
-
end
|
147
|
-
|
148
|
-
"#{bar}\n #{title}\n#{bar}\n\n"
|
149
|
-
end
|
150
|
-
|
151
|
-
def double_emphasis(text)
|
152
|
-
text.bold.green
|
153
|
-
end
|
154
|
-
|
155
|
-
def emphasis(text)
|
156
|
-
text.green
|
157
|
-
end
|
158
|
-
|
159
|
-
def linebreak
|
160
|
-
"\n"
|
161
|
-
end
|
162
|
-
|
163
|
-
def paragraph(text)
|
164
|
-
div(text) + "\n"
|
165
|
-
end
|
166
|
-
|
167
|
-
def div(text)
|
168
|
-
"#{indented?(text) ? text : unwrap(text)}\n"
|
169
|
-
end
|
170
|
-
|
171
|
-
def list(content, list_type)
|
172
|
-
case list_type
|
173
|
-
when :ordered
|
174
|
-
@counter = 0
|
175
|
-
"#{content}\n"
|
176
|
-
when :unordered
|
177
|
-
"#{content}\n"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def list_item(content, list_type)
|
182
|
-
case list_type
|
183
|
-
when :ordered
|
184
|
-
@counter ||= 0
|
185
|
-
@counter += 1
|
186
|
-
# " <8>#{@counter}.</8> #{content.strip}\n".colorize
|
187
|
-
" #{@counter.to_s.grey}. #{content.strip}\n"
|
188
|
-
when :unordered
|
189
|
-
# " <8>*</8> #{content.strip}\n".colorize
|
190
|
-
" #{"*".grey} #{content.strip}\n"
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def definition_list(defs)
|
195
|
-
defs.each do |dt, dd|
|
196
|
-
puts "<15>#{dt}<7>:".colorize
|
197
|
-
puts " #{dd}"
|
198
|
-
puts
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def table(header, rows)
|
203
|
-
if header
|
204
|
-
table = Terminal::Table.new(headings: header, rows: rows)
|
205
|
-
else
|
206
|
-
table = Terminal::Table.new(rows: rows)
|
207
|
-
end
|
208
|
-
"#{table}\n\n"
|
209
|
-
end
|
210
|
-
|
211
|
-
def separator
|
212
|
-
"_____________________________\n\n"
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
|
-
#######################################################################################
|
218
|
-
|
219
38
|
def render(stream, paged=false)
|
220
|
-
output =
|
39
|
+
output = HTMLRenderer::ANSI.render(stream)
|
40
|
+
|
221
41
|
if paged
|
222
42
|
lesspipe { |less| less.puts output }
|
223
43
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html2ansi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: html-renderer
|
@@ -16,15 +16,15 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
27
|
-
description:
|
26
|
+
version: 0.1.1
|
27
|
+
description:
|
28
28
|
email: chris@ill-logic.com
|
29
29
|
executables:
|
30
30
|
- html2ansi
|
@@ -45,7 +45,7 @@ homepage: http://github.com/epitron/html2ansi/
|
|
45
45
|
licenses:
|
46
46
|
- WTFPL
|
47
47
|
metadata: {}
|
48
|
-
post_install_message:
|
48
|
+
post_install_message:
|
49
49
|
rdoc_options: []
|
50
50
|
require_paths:
|
51
51
|
- lib
|
@@ -60,8 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
|
-
rubygems_version: 3.1.
|
64
|
-
signing_key:
|
63
|
+
rubygems_version: 3.1.3
|
64
|
+
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: html2ansi is readability for the terminal (renders html documents to text,
|
67
67
|
with terminal colors)
|