54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/asciidoctor-pdf-table-break.rb', line 54
def convert_table node
body_rows = node.rows[:body]
orig_body = node.rows[:body]
= node.rows[:foot]
orig_id = node.id
orig_title = node.title if node.title?
orig_attrs = node.attributes.dup
break_idxs = body_rows.each_index.select do |i|
body_rows[i].all? { |c| c.source.strip == '<<<' }
end
return super if break_idxs.empty?
ranges = []
prev = 0
break_idxs.each { |i| ranges << (prev...i); prev = i + 1 }
ranges << (prev...body_rows.size)
last_idx = ranges.size - 1
frame_widths = expand_rect_values @theme.table_border_width, 0 grid_raw = @theme.table_grid_width || [frame_widths[0], frame_widths[3]]
grid_rows_w = (expand_grid_values grid_raw, 0)[0]
orig_tbl_bw = @theme.table_border_width
ranges.each_with_index do |range, seg_idx|
is_first = seg_idx == 0
is_last = seg_idx == last_idx
advance_page unless is_first
node.rows.body = orig_body[range]
node.rows. = is_last ? : []
node.instance_variable_set :@attributes, orig_attrs.dup
node.set_attr 'rowcount', node.rows[:head].size + node.rows[:body].size + node.rows[:foot].size
node.remove_attr 'unbreakable-option'
node.remove_attr 'breakable-option'
node.instance_variable_set :@id, nil unless is_first
node.instance_variable_set :@title, nil unless is_first
unless is_first && is_last
patched = frame_widths.dup
patched[0] = grid_rows_w unless is_first
patched[2] = grid_rows_w unless is_last
@theme.table_border_width = patched
end
begin
super
ensure
@theme.table_border_width = orig_tbl_bw
end
end
ensure
node.rows.body = orig_body
node.rows. =
node.instance_variable_set :@id, orig_id
node.instance_variable_set :@title, orig_title if defined?(orig_title) && orig_title
node.instance_variable_set :@attributes, orig_attrs if orig_attrs
end
|