text-to-html 0.0.3
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 +7 -0
- data/lib/text-to-html.rb +45 -0
- data/lib/text-to-html/html_list.rb +57 -0
- data/lib/text-to-html/html_paragraph.rb +49 -0
- data/lib/text-to-html/html_table.rb +19 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2beba453a09b2ec533a0180b0a784b5923fce4a
|
4
|
+
data.tar.gz: f30e6c4df525d8a1afcec584ec32dfacfdc3f2c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d089c2421f87d0d80be705c9a274c83e70692e4d1af8f4c8075bdffb53c6eb482629abdba3b23d6daff26fd59fc7f0e8f455031d3ffa83178960968d149d21ea
|
7
|
+
data.tar.gz: 8c82624a4626a97ae678f3cb3e7e1f01fe2e0ba996326fe525abdd8accd2682b442a3694fb451d3bc0ce2e8e365bb4001a587d370180723edd88cc9e1bc2e31a
|
data/lib/text-to-html.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'text-to-html/html_list'
|
2
|
+
require 'text-to-html/html_paragraph'
|
3
|
+
require 'text-to-html/html_table'
|
4
|
+
|
5
|
+
class TextToHtml
|
6
|
+
|
7
|
+
def self.to_list(input, use_class = false, h_class = "", verbose = false)
|
8
|
+
r_list = HtmlList.new(input, h_class)
|
9
|
+
|
10
|
+
# config
|
11
|
+
r_list.verbose if verbose
|
12
|
+
|
13
|
+
# return
|
14
|
+
return r_list.to_list
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.to_ol(input, use_class=false, h_class="")
|
18
|
+
r_list = HtmlList.new(input, h_class)
|
19
|
+
|
20
|
+
# config
|
21
|
+
r_list.ol
|
22
|
+
r_list.use_class if use_class
|
23
|
+
|
24
|
+
return r_list.to_list
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.to_ul(input, use_class = false, h_class = "", verbose = false)
|
28
|
+
r_list = HtmlList.new(input, h_class)
|
29
|
+
|
30
|
+
# config
|
31
|
+
r_list.ul
|
32
|
+
r_list.use_class if use_class
|
33
|
+
|
34
|
+
return r_list.to_list
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.to_paragraph(input, use_class = false, h_class = "", verbose = false)
|
38
|
+
r_paragraph = HtmlParagraph.new(input, h_class)
|
39
|
+
|
40
|
+
#config
|
41
|
+
r_paragraph.verbose if verbose
|
42
|
+
|
43
|
+
return r_paragraph.to_paragraph
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# function: pulls list of text w/line breaks from clipboard, adds <li></li> to line, and puts back on clipboard
|
2
|
+
|
3
|
+
class HtmlList
|
4
|
+
|
5
|
+
def initialize(input, h_class)
|
6
|
+
# String to be parsed
|
7
|
+
@input = input
|
8
|
+
@hclass = h_class
|
9
|
+
|
10
|
+
# Options
|
11
|
+
@verbose = false
|
12
|
+
@ul = false
|
13
|
+
@ol = false
|
14
|
+
@use_class = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_list
|
18
|
+
raw_in = @input.gsub("\t", '').gsub("\r", '').gsub("\"", '').split("\n")
|
19
|
+
puts raw_in.inspect if @verbose
|
20
|
+
|
21
|
+
p_string = ""
|
22
|
+
|
23
|
+
p_string = "<ul#{(" class=\"" + @hclass + "\"") if @use_class}>\n" if @ul
|
24
|
+
p_string = "<ol#{(" class=\"" + @hclass + "\"") if @use_class}>\n" if @ol
|
25
|
+
|
26
|
+
raw_in.each do | line |
|
27
|
+
if @ul || @ol || @ul_f
|
28
|
+
p_string << "\t<li>\n\t\t#{line}\n\t</li>\n"
|
29
|
+
else
|
30
|
+
p_string << "<li>\n\t#{line}\n</li>\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
p_string << "</ul>\n" if @ul || @ul_f
|
35
|
+
p_string << "</ol>\n" if @ol
|
36
|
+
p_string.chomp!
|
37
|
+
puts p_string if @verbose
|
38
|
+
|
39
|
+
return p_string
|
40
|
+
end
|
41
|
+
|
42
|
+
def verbose
|
43
|
+
@verbose = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def ul
|
47
|
+
@ul = true
|
48
|
+
end
|
49
|
+
|
50
|
+
def ol
|
51
|
+
@ol = true
|
52
|
+
end
|
53
|
+
|
54
|
+
def use_class
|
55
|
+
@use_class = true
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# function: pulls text w/line breaks from clipboard, adds <p></p> to line breaks, and puts back on clipboard
|
2
|
+
# TODO: Enable classes
|
3
|
+
|
4
|
+
class HtmlParagraph
|
5
|
+
|
6
|
+
def initialize(input, h_class)
|
7
|
+
# String to be parsed
|
8
|
+
@input = input
|
9
|
+
@hclass = h_class
|
10
|
+
|
11
|
+
# Options
|
12
|
+
@verbose = false
|
13
|
+
@em = false
|
14
|
+
@strong = false
|
15
|
+
@use_class = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_paragraph
|
19
|
+
raw_in = @input.gsub("\t", '').gsub("\r", '').gsub("\"", '').split("\n")
|
20
|
+
puts raw_in.inspect if @verbose
|
21
|
+
|
22
|
+
p_string = ""
|
23
|
+
raw_in.each do | line |
|
24
|
+
if line.length > 0
|
25
|
+
p_string << "<p>\n\t#{"<em>" if @em}#{"<strong>" if @strong}#{line}#{"</em>" if @em}#{"</strong>" if @strong}\n</p>\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
p_string.chomp!
|
29
|
+
puts p_string if @verbose
|
30
|
+
|
31
|
+
return p_string
|
32
|
+
end
|
33
|
+
|
34
|
+
def em
|
35
|
+
@em = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def strong
|
39
|
+
@strong = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def verbose
|
43
|
+
@verbose = true
|
44
|
+
end
|
45
|
+
|
46
|
+
def use_class
|
47
|
+
@use_class = true
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# function: pulls text w/line breaks from clipboard, adds <p></p> to line breaks, and puts back on clipboard
|
2
|
+
verbose = ARGV.include?("-v")
|
3
|
+
|
4
|
+
raw_in = `pbpaste`.gsub("\r", '').gsub("\"", '').split("\n")
|
5
|
+
puts raw_in.inspect if verbose
|
6
|
+
|
7
|
+
p_string = ""
|
8
|
+
raw_in.each do | line |
|
9
|
+
#p_string << "<p>\n\t#{line}\n</p>\n" if line.length > 0
|
10
|
+
p_string << "<tr>\n\t"
|
11
|
+
line.split("\t").each_with_index do |data, i|
|
12
|
+
p_string << "<td#{" scope=\"row\"" if i == 0}>\n\t\t" + data + "\n\t</td>\n"
|
13
|
+
end
|
14
|
+
p_string << "</tr>\n"
|
15
|
+
end
|
16
|
+
p_string.chomp!
|
17
|
+
puts p_string if verbose
|
18
|
+
|
19
|
+
IO.popen('pbcopy', 'w') { |f| f << p_string }
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: text-to-html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Sauve
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: With more and more code growing obsolete, it's handy to have a few tools
|
14
|
+
that could convert plaintext to html elements.
|
15
|
+
email: dengsauve@yahoo.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/text-to-html.rb
|
21
|
+
- lib/text-to-html/html_list.rb
|
22
|
+
- lib/text-to-html/html_paragraph.rb
|
23
|
+
- lib/text-to-html/html_table.rb
|
24
|
+
homepage: https://rubygems.org/gems/text-to-html
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata:
|
28
|
+
source_code_uri: https://github.com/dengsauve/text-to-html
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - "~>"
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.5.2
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: A gem for converting plain text to various html elements.
|
49
|
+
test_files: []
|