Almirah 0.2.2 → 0.2.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.
@@ -1,59 +1,63 @@
1
- require_relative "doc_item"
1
+ # frozen_string_literal: true
2
2
 
3
- class MarkdownTable < DocItem
4
-
5
- attr_accessor :column_names
6
- attr_accessor :rows
3
+ require_relative 'doc_item'
7
4
 
8
- def initialize(heading_row)
9
- @column_names = heading_row.split('|')
10
- @rows = Array.new
5
+ class MarkdownTable < DocItem
6
+ attr_accessor :column_names, :rows, :heading_row, :is_separator_detected
7
+
8
+ def initialize(doc, heading_row)
9
+ super()
10
+ @parent_doc = doc
11
+ @parent_heading = doc.headings[-1]
12
+ @heading_row = heading_row
13
+
14
+ res = /^[|](.*[|])/.match(heading_row)
15
+ @column_names = if res
16
+ res[1].split('|')
17
+ else
18
+ ['# ERROR# ']
19
+ end
20
+ @rows = []
21
+ @is_separator_detected = false
22
+ end
23
+
24
+ def addRow(row)
25
+ columns = row.split('|')
26
+ @rows.append(columns.map!(&:strip))
27
+ true
28
+ end
29
+
30
+ def to_html
31
+ s = ''
32
+ if @@html_table_render_in_progress
33
+ s += "</table>\n"
34
+ @@html_table_render_in_progress = false
11
35
  end
12
36
 
13
- def addRow(row)
14
- #check if row contains a link
15
- if tmp = /(.*)\s+>\[(\S*)\]/.match(row)
16
- return false # this is not a regular Markdown table.
17
- # so the table type shall be changed and this row shall be passed one more time
18
- end
37
+ s += "<table class=\"markdown_table\">\n"
38
+ s += "\t<thead>"
19
39
 
20
- columns = row.split('|')
21
- @rows.append(columns.map!{ |x| x.strip })
22
- return true
40
+ @column_names.each do |h|
41
+ s += " <th>#{h}</th>"
23
42
  end
24
43
 
25
- def to_html
26
- s = ''
27
- if @@htmlTableRenderInProgress
28
- s += "</table>\n"
29
- @@htmlTableRenderInProgress = false
30
- end
31
-
32
- s += "<table class=\"markdown_table\">\n"
33
- s += "\t<thead>"
34
-
35
- @column_names.each do |h|
36
- s += " <th>#{h}</th>"
37
- end
44
+ s += " </thead>\n"
38
45
 
39
- s += " </thead>\n"
40
-
41
- @rows.each do |row|
42
- s += "\t<tr>\n"
43
- row.each do |col|
44
- if col.to_i > 0 && col.to_i.to_s == col # autoalign cells with numbers
45
- s += "\t\t<td style=\"text-align: center;\">#{col}</td>\n"
46
- else
47
- f_text = format_string(col)
48
- s += "\t\t<td>#{f_text}</td>\n"
49
- end
50
- end
51
- s += "\t</tr>\n"
46
+ @rows.each do |row|
47
+ s += "\t<tr>\n"
48
+ row.each do |col|
49
+ if col.to_i.positive? && col.to_i.to_s == col # autoalign cells with numbers
50
+ s += "\t\t<td style=\"text-align: center;\">#{col}</td>\n"
51
+ else
52
+ f_text = format_string(col)
53
+ s += "\t\t<td>#{f_text}</td>\n"
52
54
  end
53
-
54
- s += "</table>\n"
55
-
56
- return s
55
+ end
56
+ s += "\t</tr>\n"
57
57
  end
58
58
 
59
- end
59
+ s += "</table>\n"
60
+
61
+ s
62
+ end
63
+ end
@@ -4,7 +4,9 @@ class Paragraph < DocItem
4
4
 
5
5
  attr_accessor :text
6
6
 
7
- def initialize(text)
7
+ def initialize(doc, text)
8
+ @parent_doc = doc
9
+ @parent_heading = doc.headings[-1]
8
10
  @text = text
9
11
  end
10
12
 
@@ -14,9 +16,9 @@ class Paragraph < DocItem
14
16
 
15
17
  def to_html
16
18
  s = ''
17
- if @@htmlTableRenderInProgress
19
+ if @@html_table_render_in_progress
18
20
  s += "</table>"
19
- @@htmlTableRenderInProgress = false
21
+ @@html_table_render_in_progress = false
20
22
  end
21
23
 
22
24
  s += "<p>" + format_string(@text)