-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchisel.rb
More file actions
55 lines (49 loc) · 1.21 KB
/
chisel.rb
File metadata and controls
55 lines (49 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Chisel
attr_reader :document, :lines, :line_changes
def initialize(document)
@document = document
end
#break it up line by line
def line_break
@lines = document.split("\n")
end
#look at beginning of each string
def line_change
@line_changes = lines.map do |line|
if line.start_with?("#####")
line.gsub("#####", "<h5>")
elsif line.start_with?("####")
line.gsub("####", "<h4>")
elsif line.start_with?("###")
line.gsub("###", "<h3>")
elsif line.start_with?("##")
line.gsub("##", "<h2>")
elsif line.start_with?("#")
line.gsub("#", "<h1>")
else
line = "<p>#{line}"
end
end
end
def end_tags
@lines = line_changes.map do |line|
if line.include?("<h5>")
line = "#{line}</h5>"
elsif line.include?("<h4>")
line = "#{line}</h4>"
elsif line.include?("<h3>")
line = "#{line}</h3>"
elsif line.include?("<h2>")
line = "#{line}</h2>"
elsif line.include?("<h1>")
line = "#{line}</h1>"
elsif line.include?("<p>")
line = "#{line}</p>"
end
end
end
def rejoin_doc
document = lines.join("\n")
return document
end
end