mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +08:00
there are always now atleast 5 rows, like in edit table in repository, so it adds empty rows if there are not atleast 5 originally
This commit is contained in:
parent
f67f633562
commit
a37d4f3cde
1 changed files with 17 additions and 1 deletions
|
|
@ -45,10 +45,15 @@ module ProtocolsIoHelper
|
||||||
tr_regex = %r{<tr\b[^>]*>(.*?)<\/tr>}m
|
tr_regex = %r{<tr\b[^>]*>(.*?)<\/tr>}m
|
||||||
td_regex = %r{<td\b[^>]*>(.*?)<\/td>}m
|
td_regex = %r{<td\b[^>]*>(.*?)<\/td>}m
|
||||||
tables = {}
|
tables = {}
|
||||||
|
description_string.gsub! '<th>', '<td>'
|
||||||
|
description_string.gsub! '</th>', '</td>'
|
||||||
table_strings = description_string.scan(table_regex)
|
table_strings = description_string.scan(table_regex)
|
||||||
table_strings.each_with_index do |table, table_counter|
|
table_strings.each_with_index do |table, table_counter|
|
||||||
tables[table_counter.to_s] = {}
|
tables[table_counter.to_s] = {}
|
||||||
tr_strings = table[0].scan(tr_regex)
|
tr_number = table[0].scan(tr_regex).count
|
||||||
|
diff = 5 - tr_number # always tables have atleast 5 rows
|
||||||
|
table_fixed_string = tr_number > 4 ? table[0] : table[0] + empty_tr_gen(diff)
|
||||||
|
tr_strings = table_fixed_string.scan(tr_regex)
|
||||||
contents = {}
|
contents = {}
|
||||||
contents['data'] = []
|
contents['data'] = []
|
||||||
tr_strings.each_with_index do |tr, tr_counter|
|
tr_strings.each_with_index do |tr, tr_counter|
|
||||||
|
|
@ -68,6 +73,15 @@ module ProtocolsIoHelper
|
||||||
return tables, string_without_tables
|
return tables, string_without_tables
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def empty_tr_gen(number)
|
||||||
|
result = ''
|
||||||
|
while number > 0
|
||||||
|
result += '<tr></tr>'
|
||||||
|
number -= 1
|
||||||
|
end
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
def string_html_table_remove(description_string)
|
def string_html_table_remove(description_string)
|
||||||
description_string.remove!("\n", "\t", "\r", "\f")
|
description_string.remove!("\n", "\t", "\r", "\f")
|
||||||
table_whole_regex = %r{(<table\b[^>]*>.*?<\/table>)}m
|
table_whole_regex = %r{(<table\b[^>]*>.*?<\/table>)}m
|
||||||
|
|
@ -395,6 +409,8 @@ module ProtocolsIoHelper
|
||||||
newj[i.to_s]['tables'], table_str = protocolsio_string_to_table_element(
|
newj[i.to_s]['tables'], table_str = protocolsio_string_to_table_element(
|
||||||
newj[i.to_s]['description']
|
newj[i.to_s]['description']
|
||||||
)
|
)
|
||||||
|
# Base64.decode64(newj[i.to_s]['tables'][0]['contents'])
|
||||||
|
# byebug
|
||||||
newj[i.to_s]['description'] = table_str
|
newj[i.to_s]['description'] = table_str
|
||||||
end # steps
|
end # steps
|
||||||
newj
|
newj
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue