Almirah 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/almirah/doc_items/markdown_table.rb +39 -3
- data/lib/almirah/doc_parser.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 295ea4bad4cbe143c6a83632c8b745baa893ad40de1f310f1b42d25108d1e09e
|
4
|
+
data.tar.gz: a0251ebf5f4626f764fe588a09a1f1b865941945850064ae46cdde02f8f694db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52a8f6612cd84debb4d47069a0412446b8cff83411931890ed7e60c00dbb4f1dfe0b56ccf1a439683f612879b50f57aca28ee253789d824127f7b00c4b050f58
|
7
|
+
data.tar.gz: 5eec4d032bca113e06f6fe3a4cdbc4fbffe508bcf09c23b6ac67ff9dfeed61eeab5a9568b307caa5fac8c8dac61823151d426d5843d357cf0b58ba590c2ad5ef
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require_relative 'doc_item'
|
4
4
|
|
5
5
|
class MarkdownTable < DocItem
|
6
|
-
attr_accessor :column_names, :rows, :heading_row, :is_separator_detected
|
6
|
+
attr_accessor :column_names, :rows, :heading_row, :is_separator_detected, :column_aligns
|
7
7
|
|
8
8
|
def initialize(doc, heading_row)
|
9
9
|
super(doc)
|
@@ -17,6 +17,33 @@ class MarkdownTable < DocItem
|
|
17
17
|
end
|
18
18
|
@rows = []
|
19
19
|
@is_separator_detected = false
|
20
|
+
@column_aligns = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_separator(line)
|
24
|
+
res = /^[|](.*[|])/.match(line)
|
25
|
+
columns = if res
|
26
|
+
res[1].split('|')
|
27
|
+
else
|
28
|
+
['# ERROR# ']
|
29
|
+
end
|
30
|
+
|
31
|
+
columns.each do |c|
|
32
|
+
res = /(:?)(-{3,})(:?)/.match(c)
|
33
|
+
@column_aligns << if res.length == 4
|
34
|
+
if (res[1] != '') && (res[2] != '') && (res[3] != '')
|
35
|
+
'center'
|
36
|
+
elsif (res[1] != '') && (res[2] != '') && (res[3] == '')
|
37
|
+
'left'
|
38
|
+
elsif (res[1] == '') && (res[2] != '') && (res[3] != '')
|
39
|
+
'right'
|
40
|
+
else
|
41
|
+
'default'
|
42
|
+
end
|
43
|
+
else
|
44
|
+
'default'
|
45
|
+
end
|
46
|
+
end
|
20
47
|
end
|
21
48
|
|
22
49
|
def add_row(row)
|
@@ -43,12 +70,21 @@ class MarkdownTable < DocItem
|
|
43
70
|
|
44
71
|
@rows.each do |row|
|
45
72
|
s += "\t<tr>\n"
|
46
|
-
row.
|
73
|
+
row.each_with_index do |col, index|
|
47
74
|
if col.to_i.positive? && col.to_i.to_s == col # autoalign cells with numbers
|
48
75
|
s += "\t\t<td style=\"text-align: center;\">#{col}</td>\n"
|
49
76
|
else
|
77
|
+
align = ''
|
78
|
+
case @column_aligns[index]
|
79
|
+
when 'left'
|
80
|
+
align = 'style="text-align: left;"'
|
81
|
+
when 'right'
|
82
|
+
align = 'style="text-align: right;"'
|
83
|
+
when 'center'
|
84
|
+
align = 'style="text-align: center;"'
|
85
|
+
end
|
50
86
|
f_text = format_string(col)
|
51
|
-
s += "\t\t<td>#{f_text}</td>\n"
|
87
|
+
s += "\t\t<td #{align}>#{f_text}</td>\n"
|
52
88
|
end
|
53
89
|
end
|
54
90
|
s += "\t</tr>\n"
|
data/lib/almirah/doc_parser.rb
CHANGED
@@ -227,11 +227,12 @@ class DocParser # rubocop:disable Metrics/ClassLength,Style/Documentation
|
|
227
227
|
temp_md_list = nil
|
228
228
|
end
|
229
229
|
|
230
|
-
if res = /^[|](-{3,})[|]/.match(s) # check if it is a separator first
|
230
|
+
if res = /^[|]\s?(:?)(-{3,})(:?)\s?[|]/.match(s) # check if it is a separator first
|
231
231
|
|
232
232
|
if temp_md_table
|
233
233
|
# separator is found after heading
|
234
234
|
temp_md_table.is_separator_detected = true
|
235
|
+
temp_md_table.add_separator(s)
|
235
236
|
else
|
236
237
|
# separator out of table scope consider it just as a regular paragraph
|
237
238
|
item = Paragraph.new(doc, s)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Almirah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Ivanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|