coradoc-docx 0.1.0 → 0.1.2
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/Rakefile +8 -0
- data/lib/coradoc/docx/transform/from_core_model.rb +13 -44
- data/lib/coradoc/docx/transform/numbering_resolver.rb +3 -3
- data/lib/coradoc/docx/transform/ordered_content.rb +15 -3
- data/lib/coradoc/docx/transform/rules/break_rule.rb +1 -1
- data/lib/coradoc/docx/transform/rules/heading_rule.rb +1 -2
- data/lib/coradoc/docx/transform/rules/math_rule.rb +1 -2
- data/lib/coradoc/docx/transform/rules/paragraph_rule.rb +1 -1
- data/lib/coradoc/docx/transform/to_core_model.rb +2 -3
- data/lib/coradoc/docx/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e46f27d58495c1034b6fcb7e18a4b3f7361399bae351f07feecc70bf96998c00
|
|
4
|
+
data.tar.gz: e635bc232ec683c7ac69d29ca3051cb7ff79858fb6726d97cf57abeef736405a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f59bc132f05dbc709ed0c7b31e6c633e94efde7a95e4bbf1661c18e3a737ad0ca8e592257a1029c9935e57ce679f771705cef1bbdeea0b4d00c11e4e112e4d9
|
|
7
|
+
data.tar.gz: 926131183805ae1163e544f464417c21fe38dfb5705cb363427c83e053d7f60c8a71f65cfd0189f9003cc6498f1ec0fa54215ef3d21d87fd721619c844de7b3a
|
data/Rakefile
ADDED
|
@@ -82,14 +82,7 @@ module Coradoc
|
|
|
82
82
|
private
|
|
83
83
|
|
|
84
84
|
def transform_structural_element(element)
|
|
85
|
-
|
|
86
|
-
when 'document'
|
|
87
|
-
transform_document(element)
|
|
88
|
-
when 'section'
|
|
89
|
-
transform_section(element)
|
|
90
|
-
else
|
|
91
|
-
transform_section(element)
|
|
92
|
-
end
|
|
85
|
+
transform_document(element)
|
|
93
86
|
end
|
|
94
87
|
|
|
95
88
|
def transform_document(element)
|
|
@@ -101,38 +94,12 @@ module Coradoc
|
|
|
101
94
|
doc.build
|
|
102
95
|
end
|
|
103
96
|
|
|
104
|
-
def transform_section(element)
|
|
105
|
-
paragraphs = []
|
|
106
|
-
|
|
107
|
-
paragraphs << build_heading(element.title, level: element.heading_level) if element.title
|
|
108
|
-
|
|
109
|
-
element.children&.each do |child|
|
|
110
|
-
case child
|
|
111
|
-
when Coradoc::CoreModel::StructuralElement
|
|
112
|
-
paragraphs << transform_section(child)
|
|
113
|
-
when Coradoc::CoreModel::AnnotationBlock
|
|
114
|
-
paragraphs << transform_annotation_block(child)
|
|
115
|
-
when Coradoc::CoreModel::Block
|
|
116
|
-
paragraphs << build_ooxml_paragraph(child)
|
|
117
|
-
when Coradoc::CoreModel::ListBlock
|
|
118
|
-
paragraphs.concat(build_ooxml_list(child))
|
|
119
|
-
when Coradoc::CoreModel::Table
|
|
120
|
-
paragraphs << build_ooxml_table(child)
|
|
121
|
-
when Coradoc::CoreModel::Image
|
|
122
|
-
paragraphs << build_ooxml_image(child)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
paragraphs
|
|
127
|
-
end
|
|
128
|
-
|
|
129
97
|
def transform_block(block)
|
|
130
|
-
|
|
131
|
-
|
|
98
|
+
semantic = block.resolve_semantic_type
|
|
99
|
+
case semantic
|
|
100
|
+
when :page_break
|
|
132
101
|
build_page_break
|
|
133
|
-
when
|
|
134
|
-
build_ooxml_paragraph(block)
|
|
135
|
-
when 'comment'
|
|
102
|
+
when :comment
|
|
136
103
|
nil
|
|
137
104
|
else
|
|
138
105
|
build_ooxml_paragraph(block)
|
|
@@ -206,8 +173,8 @@ module Coradoc
|
|
|
206
173
|
end
|
|
207
174
|
|
|
208
175
|
def add_block_to_builder(block, builder)
|
|
209
|
-
case block.
|
|
210
|
-
when
|
|
176
|
+
case block.resolve_semantic_type
|
|
177
|
+
when :page_break
|
|
211
178
|
builder.page_break
|
|
212
179
|
else
|
|
213
180
|
add_paragraph_to_builder(block, builder)
|
|
@@ -224,10 +191,12 @@ module Coradoc
|
|
|
224
191
|
def add_paragraph_to_builder(block, builder)
|
|
225
192
|
content = block.renderable_content
|
|
226
193
|
|
|
227
|
-
if content.is_a?(Array) && content.any? { |c| !c.is_a?(
|
|
194
|
+
if content.is_a?(Array) && content.any? { |c| !c.is_a?(Coradoc::CoreModel::TextContent) }
|
|
228
195
|
builder.paragraph do |p|
|
|
229
196
|
content.each do |child|
|
|
230
197
|
case child
|
|
198
|
+
when Coradoc::CoreModel::TextContent
|
|
199
|
+
p << child.text
|
|
231
200
|
when String
|
|
232
201
|
p << child
|
|
233
202
|
when Coradoc::CoreModel::InlineElement
|
|
@@ -242,7 +211,7 @@ module Coradoc
|
|
|
242
211
|
end
|
|
243
212
|
|
|
244
213
|
def add_list_to_builder(list_block, builder)
|
|
245
|
-
list_method = list_block.marker_type == '
|
|
214
|
+
list_method = list_block.marker_type == 'ordered' ? :numbered_list : :bullet_list
|
|
246
215
|
|
|
247
216
|
if list_method == :numbered_list
|
|
248
217
|
builder.numbered_list do |list|
|
|
@@ -300,9 +269,9 @@ module Coradoc
|
|
|
300
269
|
if content.is_a?(Array)
|
|
301
270
|
content.each do |child|
|
|
302
271
|
case child
|
|
303
|
-
when
|
|
272
|
+
when Coradoc::CoreModel::TextContent
|
|
304
273
|
run = Uniword::Wordprocessingml::Run.new
|
|
305
|
-
run.text = Uniword::Wordprocessingml::Text.new(content: child)
|
|
274
|
+
run.text = Uniword::Wordprocessingml::Text.new(content: child.text)
|
|
306
275
|
para.runs << run
|
|
307
276
|
when Coradoc::CoreModel::InlineElement
|
|
308
277
|
para.runs << build_ooxml_run(child)
|
|
@@ -112,13 +112,13 @@ module Coradoc
|
|
|
112
112
|
|
|
113
113
|
def marker_type_for(fmt)
|
|
114
114
|
case fmt
|
|
115
|
-
when 'decimal' then '
|
|
115
|
+
when 'decimal' then 'ordered'
|
|
116
116
|
when 'lowerLetter' then 'lower_alpha'
|
|
117
117
|
when 'upperLetter' then 'upper_alpha'
|
|
118
118
|
when 'lowerRoman' then 'lower_roman'
|
|
119
119
|
when 'upperRoman' then 'upper_roman'
|
|
120
|
-
when 'bullet' then '
|
|
121
|
-
else '
|
|
120
|
+
when 'bullet' then 'unordered'
|
|
121
|
+
else 'ordered'
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
end
|
|
@@ -21,12 +21,24 @@ module Coradoc
|
|
|
21
21
|
order = paragraph.is_a?(Uniword::Wordprocessingml::Paragraph) ? paragraph.element_order : nil
|
|
22
22
|
|
|
23
23
|
if order && !order.empty?
|
|
24
|
-
transform_ordered(paragraph, order, context)
|
|
24
|
+
wrap_text_children(transform_ordered(paragraph, order, context))
|
|
25
25
|
else
|
|
26
|
-
transform_sequential(paragraph, context)
|
|
26
|
+
wrap_text_children(transform_sequential(paragraph, context))
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# Wrap raw strings in TextContent so all children are Base instances.
|
|
31
|
+
#
|
|
32
|
+
# @param items [Array] mixed Strings and CoreModel::Base
|
|
33
|
+
# @return [Array<CoreModel::Base>]
|
|
34
|
+
def wrap_text_children(items)
|
|
35
|
+
items.map do |item|
|
|
36
|
+
next nil if item.nil?
|
|
37
|
+
|
|
38
|
+
item.is_a?(String) ? CoreModel::TextContent.new(text: item) : item
|
|
39
|
+
end.compact
|
|
40
|
+
end
|
|
41
|
+
|
|
30
42
|
# Flatten children array to plain text string.
|
|
31
43
|
#
|
|
32
44
|
# @param children [Array] mixed content (Strings, InlineElements, Blocks)
|
|
@@ -34,7 +46,7 @@ module Coradoc
|
|
|
34
46
|
def extract_plain_text(children)
|
|
35
47
|
children.map do |c|
|
|
36
48
|
case c
|
|
37
|
-
when
|
|
49
|
+
when CoreModel::TextContent then c.text
|
|
38
50
|
when CoreModel::InlineElement then c.content.to_s
|
|
39
51
|
when CoreModel::Block then c.content.to_s
|
|
40
52
|
else c.to_s
|
|
@@ -16,7 +16,7 @@ module Coradoc
|
|
|
16
16
|
|
|
17
17
|
def apply(brk, _context)
|
|
18
18
|
if brk.type == 'page'
|
|
19
|
-
Coradoc::CoreModel::Block.new(
|
|
19
|
+
Coradoc::CoreModel::Block.new(block_semantic_type: 'page_break')
|
|
20
20
|
else
|
|
21
21
|
Coradoc::CoreModel::InlineElement.new(
|
|
22
22
|
format_type: 'hard_line_break'
|
|
@@ -56,8 +56,7 @@ module Coradoc
|
|
|
56
56
|
children.shift
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
doc = Coradoc::CoreModel::
|
|
60
|
-
element_type: 'document',
|
|
59
|
+
doc = Coradoc::CoreModel::DocumentElement.new(
|
|
61
60
|
title: doc_title,
|
|
62
61
|
children: children
|
|
63
62
|
)
|
|
@@ -147,7 +146,7 @@ module Coradoc
|
|
|
147
146
|
else
|
|
148
147
|
# Standalone section break → thematic break
|
|
149
148
|
Coradoc::CoreModel::Block.new(
|
|
150
|
-
|
|
149
|
+
block_semantic_type: 'thematic_break'
|
|
151
150
|
)
|
|
152
151
|
end
|
|
153
152
|
end
|
data/lib/coradoc/docx/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: coradoc-docx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -103,6 +103,7 @@ extensions: []
|
|
|
103
103
|
extra_rdoc_files: []
|
|
104
104
|
files:
|
|
105
105
|
- README.adoc
|
|
106
|
+
- Rakefile
|
|
106
107
|
- lib/coradoc/docx.rb
|
|
107
108
|
- lib/coradoc/docx/transform.rb
|
|
108
109
|
- lib/coradoc/docx/transform/context.rb
|
|
@@ -142,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
142
143
|
requirements:
|
|
143
144
|
- - ">="
|
|
144
145
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: 3.
|
|
146
|
+
version: 3.3.0
|
|
146
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
requirements:
|
|
148
149
|
- - ">="
|