Almirah 0.2.6 → 0.2.8
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 +4 -4
- data/lib/almirah/doc_items/markdown_table.rb +39 -3
- data/lib/almirah/doc_parser.rb +6 -2
- 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: 04afed7a81d07d1789a115c7c31e4d09df1c638eaf2eacf390f7ec7611e522ef
|
4
|
+
data.tar.gz: 403f2c7cb9381b4ee12859b27f9fc584ce73274ced9254a7b08b5cda4b316849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3db8f92b780657bc4109b96dc64f19c28249c509ba9a7d8c33b71c37fa6fb821a7a140d32bd955e20a7f49e5401b55d64d8732cccd2c7a5800de494dc05660db
|
7
|
+
data.tar.gz: eeab5aa32a82b0efbe0cc3c3f1e576cd99b9ec1eadd9e5b1e46b7e5616d8c715d8b52640a83e9e14ce47ec443239a477f3cc8488441b356dceda6a88a22e306e
|
@@ -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 && 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
@@ -211,7 +211,9 @@ class DocParser # rubocop:disable Metrics/ClassLength,Style/Documentation
|
|
211
211
|
temp_md_list = item
|
212
212
|
end
|
213
213
|
|
214
|
-
elsif
|
214
|
+
elsif /^[+](-*[+])/.match(s) # try to ignore Grid Table borders
|
215
|
+
|
216
|
+
elsif (s[0] == '|') || (s[0] == '+') # check if table
|
215
217
|
|
216
218
|
if doc.title == ''
|
217
219
|
# dummy section if root is not a Document Title (level 0)
|
@@ -227,11 +229,13 @@ class DocParser # rubocop:disable Metrics/ClassLength,Style/Documentation
|
|
227
229
|
temp_md_list = nil
|
228
230
|
end
|
229
231
|
|
230
|
-
|
232
|
+
# check if it is a separator first
|
233
|
+
if /^[|]\s?(:?)(-{3,})(:?)\s?[|]/.match(s) || /^[+]\s?(:?)(={3,})(:?)\s?[+]/.match(s)
|
231
234
|
|
232
235
|
if temp_md_table
|
233
236
|
# separator is found after heading
|
234
237
|
temp_md_table.is_separator_detected = true
|
238
|
+
temp_md_table.add_separator(s)
|
235
239
|
else
|
236
240
|
# separator out of table scope consider it just as a regular paragraph
|
237
241
|
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.8
|
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-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|