metanorma-iso 3.5.30 → 3.5.31
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/data/iso-dis/style_mapping.yml +5 -0
- data/data/iso-dis/styles.yml +2 -2
- data/data/iso-dis/template.docx +0 -0
- data/data/iso-simple/style_mapping.yml +15 -0
- data/data/iso-simple/styles.yml +8 -21
- data/data/iso-simple/template.dotx +0 -0
- data/lib/html2doc/lists.rb +20 -0
- data/lib/isodoc/iso/docx/adapter.rb +77 -20
- data/lib/isodoc/iso/docx/box_wrapper.rb +19 -9
- data/lib/isodoc/iso/docx/context.rb +1 -1
- data/lib/isodoc/iso/docx/formula_renderer.rb +6 -5
- data/lib/isodoc/iso/docx/header_footer_renderer.rb +99 -39
- data/lib/isodoc/iso/docx/inline.rb +148 -52
- data/lib/isodoc/iso/docx/inline_renderers/bookmark_renderer.rb +2 -0
- data/lib/isodoc/iso/docx/inline_renderers/fmt_xref_renderer.rb +3 -1
- data/lib/isodoc/iso/docx/inline_renderers/footnote_renderer.rb +29 -13
- data/lib/isodoc/iso/docx/inline_renderers/link_renderer.rb +13 -2
- data/lib/isodoc/iso/docx/inline_renderers/monospace_renderer.rb +19 -0
- data/lib/isodoc/iso/docx/middle_title_renderer.rb +39 -25
- data/lib/isodoc/iso/docx/renderers/admonition_renderer.rb +2 -0
- data/lib/isodoc/iso/docx/renderers/annex_renderer.rb +8 -71
- data/lib/isodoc/iso/docx/renderers/base.rb +24 -0
- data/lib/isodoc/iso/docx/renderers/definition_list_renderer.rb +161 -8
- data/lib/isodoc/iso/docx/renderers/figure_renderer.rb +21 -1
- data/lib/isodoc/iso/docx/renderers/image_renderer.rb +2 -2
- data/lib/isodoc/iso/docx/renderers/list_item_content.rb +23 -0
- data/lib/isodoc/iso/docx/renderers/note_content.rb +50 -0
- data/lib/isodoc/iso/docx/renderers/note_renderer.rb +1 -0
- data/lib/isodoc/iso/docx/renderers/paragraph_renderer.rb +9 -3
- data/lib/isodoc/iso/docx/renderers/quote_renderer.rb +2 -0
- data/lib/isodoc/iso/docx/renderers/references_renderer.rb +6 -3
- data/lib/isodoc/iso/docx/renderers/table_cell_element/cell_target.rb +4 -0
- data/lib/isodoc/iso/docx/renderers/table_cell_element/definition_list_handler.rb +13 -2
- data/lib/isodoc/iso/docx/renderers/table_cell_element/example_handler.rb +63 -0
- data/lib/isodoc/iso/docx/renderers/table_cell_element/figure_handler.rb +35 -0
- data/lib/isodoc/iso/docx/renderers/table_cell_element/list_handler.rb +95 -7
- data/lib/isodoc/iso/docx/renderers/table_cell_element/note_handler.rb +66 -2
- data/lib/isodoc/iso/docx/renderers/table_cell_element/registry.rb +32 -0
- data/lib/isodoc/iso/docx/renderers/table_cell_element/sourcecode_handler.rb +29 -0
- data/lib/isodoc/iso/docx/renderers/table_cell_element.rb +3 -0
- data/lib/isodoc/iso/docx/renderers/table_renderer.rb +65 -20
- data/lib/isodoc/iso/docx/renderers/term_renderer.rb +187 -57
- data/lib/isodoc/iso/docx/renderers/terms_section_renderer.rb +3 -7
- data/lib/isodoc/iso/docx/renderers/walker.rb +10 -1
- data/lib/isodoc/iso/docx/renderers.rb +6 -5
- data/lib/isodoc/iso/docx/section_manager.rb +77 -48
- data/lib/isodoc/iso/docx/style_resolver.rb +5 -0
- data/lib/isodoc/iso/docx/toc_builder.rb +59 -57
- data/lib/isodoc/iso/docx_style_mapping.rb +7 -1
- data/lib/isodoc/iso/html/header-dis.html +3 -183
- data/lib/isodoc/iso/html/isodoc.css +3 -0
- data/lib/isodoc/iso/html/isodoc.scss +3 -0
- data/lib/isodoc/iso/iso.amendment.xsl +256 -204
- data/lib/isodoc/iso/iso.international-standard.xsl +256 -204
- data/lib/isodoc/iso/presentation_xml_convert.rb +10 -0
- data/lib/isodoc/iso/word_cleanup.rb +65 -0
- data/lib/metanorma/iso/document/blocks/formula_block.rb +17 -0
- data/lib/metanorma/iso/document/blocks/note_block.rb +32 -0
- data/lib/metanorma/iso/document/blocks.rb +2 -0
- data/lib/metanorma/iso/document/dd_element.rb +17 -0
- data/lib/metanorma/iso/document/definition_section.rb +17 -0
- data/lib/metanorma/iso/document/literal_block.rb +18 -0
- data/lib/metanorma/iso/document/models.rb +4 -0
- data/lib/metanorma/iso/document/paragraph_block.rb +14 -0
- data/lib/metanorma/iso/document/semx_element.rb +39 -0
- data/lib/metanorma/iso/document/terms/iso_term.rb +7 -0
- data/lib/metanorma/iso/document/terms/term_example.rb +47 -2
- data/lib/metanorma/iso/document/terms/term_note.rb +34 -2
- data/lib/metanorma/iso/registers.rb +35 -0
- data/lib/metanorma/iso/schematron/iso-sts.sch +5 -3
- data/lib/metanorma/iso/sts/cli.rb +2 -2
- data/lib/metanorma/iso/sts/validation_report.rb +30 -14
- data/lib/metanorma/iso/sts/validator.rb +68 -43
- data/lib/metanorma/iso/sts.rb +2 -2
- data/lib/metanorma/iso/validation/rules/tree_traversal.rb +9 -1
- data/lib/metanorma/iso/validation/rules/unique_id_rule.rb +9 -0
- data/lib/metanorma/iso/version.rb +1 -1
- metadata +13 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c02ac9f963b874679334c7bc6cccd3f686c8f835570b4e214d8ecfdd67b245c3
|
|
4
|
+
data.tar.gz: 1ed11c5077b27d9787ef1230354f83fdcc6925aa7c5631a367ff987403bbdea7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c62bef0620baddba7e8759dd5526d4b6aa8eebadec901f1f3d66e2335ecb434383d147197b0b33510784460a06594c3063d7cd81b6d300412af2e0abf91d6534
|
|
7
|
+
data.tar.gz: 3895573687b2ca03d112774a3e00de4e84a8d3f5515fccf4993c69258d9c412c921ccb59687c06b1e6fbb770683873eae13c7cb542486c874e133f8ed3c172d5
|
|
@@ -173,6 +173,11 @@ paragraph_styles:
|
|
|
173
173
|
amend_newcontent: a3
|
|
174
174
|
amend_heading: a2
|
|
175
175
|
|
|
176
|
+
# Extra paragraph spacing, in twips, that the DOC chain sets on a style.
|
|
177
|
+
# definition_after: gap after a Definition paragraph (DOC: 12pt).
|
|
178
|
+
spacing:
|
|
179
|
+
definition_after: 240
|
|
180
|
+
|
|
176
181
|
character_styles:
|
|
177
182
|
hyperlink: Hyperlink
|
|
178
183
|
footnote_reference: FootnoteReference
|
data/data/iso-dis/styles.yml
CHANGED
|
@@ -2298,7 +2298,6 @@ style_library:
|
|
|
2298
2298
|
spacing:
|
|
2299
2299
|
line: '240'
|
|
2300
2300
|
line_rule: 'auto'
|
|
2301
|
-
outline_level: '1'
|
|
2302
2301
|
keep_next: false
|
|
2303
2302
|
keep_lines: false
|
|
2304
2303
|
page_break_before: false
|
|
@@ -2320,7 +2319,6 @@ style_library:
|
|
|
2320
2319
|
spacing:
|
|
2321
2320
|
line: '240'
|
|
2322
2321
|
line_rule: 'auto'
|
|
2323
|
-
outline_level: '2'
|
|
2324
2322
|
keep_next: false
|
|
2325
2323
|
keep_lines: false
|
|
2326
2324
|
page_break_before: false
|
|
@@ -2700,10 +2698,12 @@ style_library:
|
|
|
2700
2698
|
spacing:
|
|
2701
2699
|
line: '240'
|
|
2702
2700
|
line_rule: 'auto'
|
|
2701
|
+
alignment: left
|
|
2703
2702
|
keep_next: false
|
|
2704
2703
|
keep_lines: false
|
|
2705
2704
|
page_break_before: false
|
|
2706
2705
|
run_properties:
|
|
2706
|
+
color: 0000FF
|
|
2707
2707
|
font_size: '20'
|
|
2708
2708
|
bold: false
|
|
2709
2709
|
italic: false
|
data/data/iso-dis/template.docx
CHANGED
|
Binary file
|
|
@@ -34,8 +34,15 @@ paragraph_styles:
|
|
|
34
34
|
bibliography: BiblioTitle
|
|
35
35
|
|
|
36
36
|
# Content blocks
|
|
37
|
+
# Simple has no continuation or indent variants of Note and Example;
|
|
38
|
+
# every paragraph of a note or example, nested or not, uses the base style.
|
|
37
39
|
note: Note
|
|
40
|
+
note_continued: Note
|
|
41
|
+
note_indent: Note
|
|
42
|
+
note_indent_continued: Note
|
|
38
43
|
example: Example
|
|
44
|
+
example_indent: Example
|
|
45
|
+
example_indent_continued: Example
|
|
39
46
|
sourcecode: Code
|
|
40
47
|
formula: Formula
|
|
41
48
|
figure_title: FigureTitle
|
|
@@ -73,6 +80,9 @@ paragraph_styles:
|
|
|
73
80
|
|
|
74
81
|
# Colophon
|
|
75
82
|
colophon: zzCopyright
|
|
83
|
+
copyright: zzCopyright
|
|
84
|
+
copyright_hdr: zzCopyright
|
|
85
|
+
copyright_address: zzCopyright
|
|
76
86
|
std_title: zzSTDTitle
|
|
77
87
|
|
|
78
88
|
# Body text
|
|
@@ -82,6 +92,11 @@ paragraph_styles:
|
|
|
82
92
|
# Simple defines ListParagraph and has no BiblioEntry.
|
|
83
93
|
biblio_entry: ListParagraph
|
|
84
94
|
|
|
95
|
+
# Extra paragraph spacing, in twips, that the DOC chain sets on a style.
|
|
96
|
+
# definition_after: gap after a Definition paragraph (DOC: 6pt).
|
|
97
|
+
spacing:
|
|
98
|
+
definition_after: 120
|
|
99
|
+
|
|
85
100
|
character_styles:
|
|
86
101
|
hyperlink: Hyperlink
|
|
87
102
|
|
data/data/iso-simple/styles.yml
CHANGED
|
@@ -440,6 +440,9 @@ style_library:
|
|
|
440
440
|
paragraph_properties:
|
|
441
441
|
spacing:
|
|
442
442
|
before: '0.0'
|
|
443
|
+
indent:
|
|
444
|
+
left: '1.905'
|
|
445
|
+
hanging: '0.635'
|
|
443
446
|
TOC3:
|
|
444
447
|
id: TOC3
|
|
445
448
|
type: paragraph
|
|
@@ -447,6 +450,10 @@ style_library:
|
|
|
447
450
|
based_on: TOC2
|
|
448
451
|
next_style: Normal
|
|
449
452
|
ui_priority: '39'
|
|
453
|
+
paragraph_properties:
|
|
454
|
+
indent:
|
|
455
|
+
left: '2.54'
|
|
456
|
+
hanging: '0.635'
|
|
450
457
|
zzContents:
|
|
451
458
|
id: zzContents
|
|
452
459
|
type: paragraph
|
|
@@ -474,27 +481,6 @@ style_library:
|
|
|
474
481
|
next_style: Normal
|
|
475
482
|
semi_hidden: true
|
|
476
483
|
paragraph_properties:
|
|
477
|
-
borders:
|
|
478
|
-
- type: top
|
|
479
|
-
val: single
|
|
480
|
-
sz: '4'
|
|
481
|
-
space: '1'
|
|
482
|
-
color: 0000FF
|
|
483
|
-
- type: bottom
|
|
484
|
-
val: single
|
|
485
|
-
sz: '4'
|
|
486
|
-
space: '1'
|
|
487
|
-
color: 0000FF
|
|
488
|
-
- type: left
|
|
489
|
-
val: single
|
|
490
|
-
sz: '4'
|
|
491
|
-
space: '4'
|
|
492
|
-
color: 0000FF
|
|
493
|
-
- type: right
|
|
494
|
-
val: single
|
|
495
|
-
sz: '4'
|
|
496
|
-
space: '4'
|
|
497
|
-
color: 0000FF
|
|
498
484
|
tabs:
|
|
499
485
|
- type: left
|
|
500
486
|
position: '0.91'
|
|
@@ -503,6 +489,7 @@ style_library:
|
|
|
503
489
|
indent:
|
|
504
490
|
left: '0.5'
|
|
505
491
|
right: '0.5'
|
|
492
|
+
alignment: left
|
|
506
493
|
run_properties:
|
|
507
494
|
color: 0000FF
|
|
508
495
|
zzSTDTitle:
|
|
Binary file
|
data/lib/html2doc/lists.rb
CHANGED
|
@@ -166,6 +166,26 @@ class Html2Doc
|
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
168
|
|
|
169
|
+
# The list label sits between the footnote anchor and the note text, so
|
|
170
|
+
# the space that follows the anchor moves ahead of the label.
|
|
171
|
+
def footnote_cleanup(docxml)
|
|
172
|
+
super
|
|
173
|
+
docxml.xpath("//div[@style = 'mso-element:footnote']/p/a" \
|
|
174
|
+
"[following-sibling::node()[2]" \
|
|
175
|
+
"[self::span[@style = 'mso-tab-count:1']]]").each do |anchor|
|
|
176
|
+
footnote_label_space(anchor)
|
|
177
|
+
end
|
|
178
|
+
docxml
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def footnote_label_space(anchor)
|
|
182
|
+
text = anchor.next_sibling.next_sibling.next_sibling
|
|
183
|
+
return unless text&.text? && text.content.start_with?(" ")
|
|
184
|
+
|
|
185
|
+
text.content = text.content.delete_prefix(" ")
|
|
186
|
+
anchor.add_next_sibling(Nokogiri::XML::Text.new(" ", anchor.document))
|
|
187
|
+
end
|
|
188
|
+
|
|
169
189
|
def cleanup(docxml)
|
|
170
190
|
super
|
|
171
191
|
docxml.xpath("//div[@class = 'Quote' or @class = 'Example' or " \
|
|
@@ -173,6 +173,7 @@ module IsoDoc
|
|
|
173
173
|
def build_zone_renderers
|
|
174
174
|
@middle_title_renderer = MiddleTitleRenderer.new(
|
|
175
175
|
resolver: @resolver, inline_renderer: @inline_renderer,
|
|
176
|
+
color: @template == :dis ? MiddleTitleRenderer::DIS_COLOR : nil,
|
|
176
177
|
)
|
|
177
178
|
@preface_renderer = new_renderer(PrefaceRenderer)
|
|
178
179
|
@indexsect_renderer = IndexsectRenderer.new(
|
|
@@ -295,7 +296,8 @@ module IsoDoc
|
|
|
295
296
|
def save_mhtml(model, output_path)
|
|
296
297
|
mhtml_doc = Uniword::Transformation::OoxmlToMhtmlConverter
|
|
297
298
|
.document_to_mht(model, model.core_properties,
|
|
298
|
-
|
|
299
|
+
with_footnote_relationships(model,
|
|
300
|
+
merged_document_relationships(model)))
|
|
299
301
|
Uniword::Infrastructure::MimePackager
|
|
300
302
|
.from_document(mhtml_doc).package(output_path)
|
|
301
303
|
end
|
|
@@ -332,6 +334,36 @@ module IsoDoc
|
|
|
332
334
|
Uniword::Ooxml::Relationships::PackageRelationships.new(relationships: rels)
|
|
333
335
|
end
|
|
334
336
|
|
|
337
|
+
# MHTML resolves every hyperlink against one relationships part,
|
|
338
|
+
# while DOCX keeps footnote links in word/_rels/footnotes.xml.rels,
|
|
339
|
+
# whose ids restart at rId1. Give each footnote hyperlink a fresh id
|
|
340
|
+
# that is unique across both parts and register its relationship.
|
|
341
|
+
def with_footnote_relationships(model, rels)
|
|
342
|
+
fn_rels = model.footnotes_rels&.relationships
|
|
343
|
+
links = footnote_hyperlinks(model)
|
|
344
|
+
return rels if Array(fn_rels).empty? || links.empty?
|
|
345
|
+
|
|
346
|
+
merged = Array(rels&.relationships).dup
|
|
347
|
+
links.each_with_index do |link, index|
|
|
348
|
+
rel = Array(fn_rels).find { |r| r.id == link.id }
|
|
349
|
+
next unless rel
|
|
350
|
+
|
|
351
|
+
link.id = "rIdFn#{index + 1}"
|
|
352
|
+
merged << Uniword::Ooxml::Relationships::PackageRelationship.new(
|
|
353
|
+
id: link.id, type: rel.type, target: rel.target,
|
|
354
|
+
target_mode: rel.target_mode
|
|
355
|
+
)
|
|
356
|
+
end
|
|
357
|
+
Uniword::Ooxml::Relationships::PackageRelationships.new(relationships: merged)
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
def footnote_hyperlinks(model)
|
|
361
|
+
entries = model.footnotes&.footnote_entries
|
|
362
|
+
Array(entries).flat_map do |entry|
|
|
363
|
+
Array(entry.paragraphs).flat_map { |p| Array(p.hyperlinks) }
|
|
364
|
+
end.select(&:id)
|
|
365
|
+
end
|
|
366
|
+
|
|
335
367
|
def mhtml_output?(path)
|
|
336
368
|
MHTML_EXTENSIONS.include?(File.extname(path).downcase)
|
|
337
369
|
end
|
|
@@ -352,6 +384,21 @@ module IsoDoc
|
|
|
352
384
|
flatten_number_stems(xml))
|
|
353
385
|
end
|
|
354
386
|
|
|
387
|
+
# TtElement models only text and semx, so bold, italic, links,
|
|
388
|
+
# footnotes and stems inside <tt> would be dropped. A SemxElement
|
|
389
|
+
# models them, so moving the content into one keeps it, and
|
|
390
|
+
# MonospaceRenderer styles it as InlineCode.
|
|
391
|
+
def wrap_rich_monospace(document)
|
|
392
|
+
document.xpath("//*[local-name()='tt']" \
|
|
393
|
+
"[*[not(local-name()='semx')]]").each do |tt|
|
|
394
|
+
semx = Nokogiri::XML::Node.new("semx", document)
|
|
395
|
+
semx.namespace = tt.namespace
|
|
396
|
+
semx["element"] = "tt"
|
|
397
|
+
semx.children = tt.children
|
|
398
|
+
tt.children = semx
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
|
|
355
402
|
# Numeric table cells need a Stem run, not a tree of MathML models.
|
|
356
403
|
# Keep block formulas intact: their renderer emits OMML, not text.
|
|
357
404
|
def flatten_number_stems(xml)
|
|
@@ -359,6 +406,7 @@ module IsoDoc
|
|
|
359
406
|
return xml if document.errors.any? { |e| e.error? || e.fatal? }
|
|
360
407
|
|
|
361
408
|
prune_stem_twins(document)
|
|
409
|
+
wrap_rich_monospace(document)
|
|
362
410
|
document.xpath("//*[local-name()='stem' or local-name()='fmt-stem']" \
|
|
363
411
|
"[not(ancestor::*[local-name()='formula'])]").each do |stem|
|
|
364
412
|
container = number_stem_container(stem)
|
|
@@ -493,6 +541,7 @@ module IsoDoc
|
|
|
493
541
|
@template_root ||= Uniword.load(@template_path)
|
|
494
542
|
root = @template_root
|
|
495
543
|
@template_margins ||= SectionManager.template_margins(root)
|
|
544
|
+
@template_references ||= SectionManager.template_references(root)
|
|
496
545
|
if root.body
|
|
497
546
|
root.body.paragraphs.clear
|
|
498
547
|
root.body.tables.clear
|
|
@@ -502,6 +551,7 @@ module IsoDoc
|
|
|
502
551
|
root.body.element_order = [] if root.body.element_order
|
|
503
552
|
root.body.section_properties = nil
|
|
504
553
|
end
|
|
554
|
+
reset_footnotes_rels(root)
|
|
505
555
|
clear_user_footnotes(root)
|
|
506
556
|
clear_user_endnotes(root)
|
|
507
557
|
root.custom_properties = nil
|
|
@@ -530,6 +580,20 @@ module IsoDoc
|
|
|
530
580
|
root.allocator = allocator
|
|
531
581
|
end
|
|
532
582
|
|
|
583
|
+
# The loaded template is reused across conversions, so the footnotes
|
|
584
|
+
# relationships (which footnote hyperlinks add to) restart from the
|
|
585
|
+
# template's own on every conversion.
|
|
586
|
+
def reset_footnotes_rels(root)
|
|
587
|
+
@template_footnotes_rels ||= Array(root.footnotes_rels&.relationships).dup
|
|
588
|
+
root.footnotes_rels = if @template_footnotes_rels.empty?
|
|
589
|
+
nil
|
|
590
|
+
else
|
|
591
|
+
Uniword::Ooxml::Relationships::PackageRelationships.new(
|
|
592
|
+
relationships: @template_footnotes_rels.dup,
|
|
593
|
+
)
|
|
594
|
+
end
|
|
595
|
+
end
|
|
596
|
+
|
|
533
597
|
def clear_user_footnotes(root)
|
|
534
598
|
return unless root.footnotes
|
|
535
599
|
|
|
@@ -611,6 +675,13 @@ module IsoDoc
|
|
|
611
675
|
# Index
|
|
612
676
|
# [SECTPR — body section, arabic page numbers]
|
|
613
677
|
|
|
678
|
+
def start_front_matter(doc)
|
|
679
|
+
@section_manager.template_margins = @template_margins || {}
|
|
680
|
+
@section_manager.template_references = @template_references || {}
|
|
681
|
+
@section_manager.insert_cover_section(doc)
|
|
682
|
+
@context.text_width = @section_manager.text_width(:front)
|
|
683
|
+
end
|
|
684
|
+
|
|
614
685
|
def visit_root(model, doc)
|
|
615
686
|
@context.in_amendment = AmendmentDoctype.amendment?(model)
|
|
616
687
|
|
|
@@ -623,8 +694,7 @@ module IsoDoc
|
|
|
623
694
|
# ── Section 1: Cover page ──
|
|
624
695
|
@cover_renderer.render(model.bibdata, doc)
|
|
625
696
|
@boilerplate_renderer.render_license(model.boilerplate, doc)
|
|
626
|
-
|
|
627
|
-
@section_manager.insert_cover_section(doc)
|
|
697
|
+
start_front_matter(doc)
|
|
628
698
|
|
|
629
699
|
# ── Copyright page (still cover section's next page) ──
|
|
630
700
|
@boilerplate_renderer.render_copyright(model.boilerplate, doc)
|
|
@@ -651,6 +721,7 @@ module IsoDoc
|
|
|
651
721
|
# separate page between front matter and body, using the
|
|
652
722
|
# MainTitle1 (intro+main) and MainTitle2 (title-part) paragraph
|
|
653
723
|
# styles. Delegated to MiddleTitleRenderer.
|
|
724
|
+
@context.text_width = @section_manager.text_width(:body)
|
|
654
725
|
@middle_title_renderer.render(model, doc)
|
|
655
726
|
visit_sections(model.sections, doc) if model.sections
|
|
656
727
|
model.annex&.each { |a| dispatch(a, doc) }
|
|
@@ -776,28 +847,14 @@ module IsoDoc
|
|
|
776
847
|
].freeze
|
|
777
848
|
|
|
778
849
|
def render_anchored(renderer, node, doc)
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
first = paragraphs && paragraphs.drop(before).find do |element|
|
|
783
|
-
element.is_a?(Uniword::Wordprocessingml::Paragraph) ||
|
|
784
|
-
element.is_a?(Uniword::Builder::ParagraphBuilder)
|
|
850
|
+
result = nil
|
|
851
|
+
first = Renderers::Anchoring.first_paragraph_added(doc) do
|
|
852
|
+
result = renderer.render(node, doc)
|
|
785
853
|
end
|
|
786
854
|
Renderers::Anchoring.anchor(@context, node, first) if first
|
|
787
855
|
result
|
|
788
856
|
end
|
|
789
857
|
|
|
790
|
-
# The paragraph list of +doc+: document body, table cell, or the
|
|
791
|
-
# table attachment buffer (which holds paragraphs and tables).
|
|
792
|
-
def container_paragraphs(doc)
|
|
793
|
-
return doc.paragraphs if doc.is_a?(Renderers::TableAttachmentBuffer)
|
|
794
|
-
|
|
795
|
-
return unless doc.is_a?(Uniword::Builder::BaseBuilder)
|
|
796
|
-
return doc.model.body&.paragraphs if doc.is_a?(Uniword::Builder::DocumentBuilder)
|
|
797
|
-
|
|
798
|
-
doc.model.paragraphs
|
|
799
|
-
end
|
|
800
|
-
|
|
801
858
|
# ── Tree walking ───────────────────────────────────────────────
|
|
802
859
|
#
|
|
803
860
|
# Delegates to Renderers::Walker so traversal logic lives in one
|
|
@@ -24,12 +24,6 @@ module IsoDoc
|
|
|
24
24
|
module BoxWrapper
|
|
25
25
|
include ModelUtils
|
|
26
26
|
|
|
27
|
-
# Gap between the label and the body. The XSL reserves
|
|
28
|
-
# padding-right on the label inline (6mm for notes, 5mm for
|
|
29
|
-
# examples); a single space keeps the ragged inline flow —
|
|
30
|
-
# wrapped lines return to the left margin, as in the PDF.
|
|
31
|
-
LABEL_GAP = " "
|
|
32
|
-
|
|
33
27
|
# Model classes whose presence anywhere in a block forces the
|
|
34
28
|
# XSL "block" mode for EXAMPLES (.//table or .//dl) and makes a
|
|
35
29
|
# paragraph unsuitable for inline-label merging. Sourcecode as
|
|
@@ -39,6 +33,8 @@ module IsoDoc
|
|
|
39
33
|
Metanorma::Document::Components::Lists::DefinitionList,
|
|
40
34
|
].freeze
|
|
41
35
|
|
|
36
|
+
QUOTE_CLASS = Metanorma::Document::Components::MultiParagraph::QuoteBlock
|
|
37
|
+
|
|
42
38
|
PLAIN_PARAGRAPH_CLASS =
|
|
43
39
|
Metanorma::Document::Components::Paragraphs::ParagraphBlock
|
|
44
40
|
|
|
@@ -70,9 +66,10 @@ module IsoDoc
|
|
|
70
66
|
|
|
71
67
|
if inline_label_paragraph?(children)
|
|
72
68
|
para = build_paragraph(style_key)
|
|
73
|
-
append_label(para, label_text(node))
|
|
69
|
+
append_label(para, label_text(node), inline: true, spaced: term_note?(node))
|
|
74
70
|
@inline_renderer.render(first, para)
|
|
75
71
|
anchor_paragraph(first, para)
|
|
72
|
+
anchor_paragraph(node, para)
|
|
76
73
|
@context.mark_zone_paragraph
|
|
77
74
|
doc << para
|
|
78
75
|
children.drop(1).each { |child| @walker.dispatch(child, doc) }
|
|
@@ -81,6 +78,7 @@ module IsoDoc
|
|
|
81
78
|
# body content follows (indented via the zone body styles).
|
|
82
79
|
label_para = build_paragraph(style_key)
|
|
83
80
|
append_label(label_para, label_text(node))
|
|
81
|
+
anchor_paragraph(node, label_para)
|
|
84
82
|
label_para.keep_next
|
|
85
83
|
doc << label_para
|
|
86
84
|
children.each { |child| @walker.dispatch(child, doc) }
|
|
@@ -109,6 +107,7 @@ module IsoDoc
|
|
|
109
107
|
def inline_label_paragraph?(children)
|
|
110
108
|
first = children.first
|
|
111
109
|
return false unless first.is_a?(PLAIN_PARAGRAPH_CLASS)
|
|
110
|
+
return false if first.is_a?(QUOTE_CLASS)
|
|
112
111
|
return false if embedded_block_child?(first)
|
|
113
112
|
return false if block_forcing_child?(children)
|
|
114
113
|
|
|
@@ -144,10 +143,21 @@ module IsoDoc
|
|
|
144
143
|
text.empty? ? nil : text
|
|
145
144
|
end
|
|
146
145
|
|
|
147
|
-
|
|
146
|
+
# Term notes take a space after "Note 1 to entry:", as DOC and the
|
|
147
|
+
# published ISO documents do; notes and examples take a tab.
|
|
148
|
+
def append_label(para, text, inline: false, spaced: false)
|
|
148
149
|
return unless text
|
|
149
150
|
|
|
150
|
-
para << (text
|
|
151
|
+
para << (spaced ? "#{text} " : text)
|
|
152
|
+
return if spaced || !inline
|
|
153
|
+
|
|
154
|
+
para << Uniword::Wordprocessingml::Run.new(
|
|
155
|
+
tab: Uniword::Wordprocessingml::Tab.new,
|
|
156
|
+
)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def term_note?(node)
|
|
160
|
+
node.is_a?(Metanorma::Iso::Document::Terms::TermNote)
|
|
151
161
|
end
|
|
152
162
|
|
|
153
163
|
# Element children of +node+ in document order (text nodes and
|
|
@@ -16,7 +16,7 @@ module IsoDoc
|
|
|
16
16
|
:in_bibliography, :in_definition_dd, :in_formula,
|
|
17
17
|
:in_figure, :in_definitions, :list_depth,
|
|
18
18
|
:section_depth,
|
|
19
|
-
:term_counter, :section_counter, :body_width,
|
|
19
|
+
:term_counter, :section_counter, :body_width, :text_width,
|
|
20
20
|
:amend_zone, :in_amendment
|
|
21
21
|
def initialize
|
|
22
22
|
@footnote_counter = Counter.new
|
|
@@ -13,11 +13,11 @@ module IsoDoc
|
|
|
13
13
|
# rendering when conversion fails.
|
|
14
14
|
#
|
|
15
15
|
# When +walker+ is supplied, the renderer also dispatches the formula's
|
|
16
|
-
# +:dl+ (symbol key list)
|
|
17
|
-
# through the walker so they render via
|
|
18
|
-
# ParagraphRenderer
|
|
19
|
-
# +Context#with_formula+ so children pick up the formula zone
|
|
20
|
-
# StyleResolver and render symbol keys as formula_dl tables.
|
|
16
|
+
# +:dl+ (symbol key list), +:p+ (accompanying paragraphs) and +:note+
|
|
17
|
+
# children through the walker so they render via
|
|
18
|
+
# DefinitionListRenderer, ParagraphRenderer and NoteRenderer. All dispatch happens
|
|
19
|
+
# inside +Context#with_formula+ so children pick up the formula zone
|
|
20
|
+
# via StyleResolver and render symbol keys as formula_dl tables.
|
|
21
21
|
class FormulaRenderer
|
|
22
22
|
include ModelUtils
|
|
23
23
|
include MathConversion
|
|
@@ -53,6 +53,7 @@ module IsoDoc
|
|
|
53
53
|
@walker.walk_attribute(formula, :dl, doc)
|
|
54
54
|
@walker.walk_attribute(formula, :p, doc)
|
|
55
55
|
walk_key(formula, doc)
|
|
56
|
+
@walker.walk_attribute(formula, :note, doc)
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
# Presentation XML wraps the formula's symbol list in <key>
|
|
@@ -10,14 +10,9 @@ module IsoDoc
|
|
|
10
10
|
# belong to which section; this renderer owns the *content* of each
|
|
11
11
|
# part — the paragraph, style, runs, and page-number field.
|
|
12
12
|
#
|
|
13
|
-
# The layout follows
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
# its own line below. The page-number style follows the section's
|
|
17
|
-
# PageScheme:
|
|
18
|
-
# - Roman scheme → FooterPageRomanNumber
|
|
19
|
-
# - Arabic scheme → FooterPageNumber
|
|
20
|
-
# - Otherwise → FooterCentered (fallback)
|
|
13
|
+
# The DIS layout follows published ISO documents and the DOC output:
|
|
14
|
+
# headers alternate left (even) and right (odd), and each footer is
|
|
15
|
+
# one line with the page number on the outer edge.
|
|
21
16
|
class HeaderFooterRenderer
|
|
22
17
|
# OOXML field instruction for the current page number.
|
|
23
18
|
PAGE_FIELD_INSTRUCTION = " PAGE "
|
|
@@ -26,33 +21,80 @@ module IsoDoc
|
|
|
26
21
|
@resolver = resolver
|
|
27
22
|
end
|
|
28
23
|
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
def render_header(part_content, text)
|
|
24
|
+
# DIS headers sit left on even pages and right on odd and first
|
|
25
|
+
# pages; Simple keeps the template part's own formatting.
|
|
26
|
+
def render_header(part_content, text, parity: :odd)
|
|
27
|
+
unless @resolver.paragraph_style(:header_centered)
|
|
28
|
+
return render_template_header(part_content, text)
|
|
29
|
+
end
|
|
30
|
+
|
|
32
31
|
part_content.paragraphs.clear
|
|
33
|
-
para =
|
|
34
|
-
para
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
para = styled_paragraph(@resolver.paragraph_style(:header_centered))
|
|
33
|
+
align(para, parity == :even ? "left" : "right")
|
|
34
|
+
para.runs << Uniword::Wordprocessingml::Run.new(
|
|
35
|
+
text: text.to_s,
|
|
36
|
+
properties: Uniword::Wordprocessingml::RunProperties.new(
|
|
37
|
+
bold: Uniword::Properties::Bold.new,
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
part_content.paragraphs << para
|
|
39
41
|
end
|
|
40
42
|
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
# DIS footers are one line: page number then copyright on even
|
|
44
|
+
# pages, copyright then page number on odd and first pages. A
|
|
45
|
+
# margin-relative tab keeps the right side correct in any section
|
|
46
|
+
# width. Simple keeps each template part's layout.
|
|
47
|
+
def render_footer(part_content, copyright_text, scheme:, parity: :odd)
|
|
48
|
+
unless @resolver.paragraph_style(:footer_centered)
|
|
49
|
+
return render_template_footer(part_content, copyright_text)
|
|
50
|
+
end
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
part_content.paragraphs.clear
|
|
53
|
+
para = styled_paragraph(@resolver.paragraph_style(:footer_centered))
|
|
54
|
+
align(para, "left")
|
|
55
|
+
copyright = [Uniword::Wordprocessingml::Run.new(text: copyright_text.to_s)]
|
|
56
|
+
page = page_number_runs(scheme)
|
|
57
|
+
first, last = parity == :even ? [page, copyright] : [copyright, page]
|
|
58
|
+
para.runs.concat(first)
|
|
59
|
+
para.runs << right_margin_tab
|
|
60
|
+
para.runs.concat(last)
|
|
61
|
+
part_content.paragraphs << para
|
|
52
62
|
end
|
|
53
63
|
|
|
54
64
|
private
|
|
55
65
|
|
|
66
|
+
# The Simple template uses different direct formatting on each
|
|
67
|
+
# odd/even part, rather than the DIS template's centered styles.
|
|
68
|
+
def render_template_header(content, text)
|
|
69
|
+
content.paragraphs.each do |paragraph|
|
|
70
|
+
field_depth = 0
|
|
71
|
+
run = paragraph.runs.find do |candidate|
|
|
72
|
+
case candidate.field_char&.fldCharType
|
|
73
|
+
when "begin" then field_depth += 1
|
|
74
|
+
when "end" then field_depth -= 1
|
|
75
|
+
end
|
|
76
|
+
field_depth.zero? && !candidate.field_char &&
|
|
77
|
+
!candidate.instr_text && !candidate.tab && !candidate.text.nil?
|
|
78
|
+
end
|
|
79
|
+
run.text = text.to_s if run
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def render_template_footer(content, text)
|
|
84
|
+
content.paragraphs.each do |paragraph|
|
|
85
|
+
in_field = false
|
|
86
|
+
paragraph.runs.each do |run|
|
|
87
|
+
case run.field_char&.fldCharType
|
|
88
|
+
when "begin" then in_field = true
|
|
89
|
+
when "end" then in_field = false
|
|
90
|
+
end
|
|
91
|
+
# Drop the template's cached page value; Word computes PAGE.
|
|
92
|
+
run.text = nil if in_field
|
|
93
|
+
run.text = text.to_s if Array(run.text).join.include?("©")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
56
98
|
def styled_paragraph(style)
|
|
57
99
|
paragraph = Uniword::Wordprocessingml::Paragraph.new
|
|
58
100
|
paragraph.properties = Uniword::Wordprocessingml::ParagraphProperties.new
|
|
@@ -63,22 +105,40 @@ module IsoDoc
|
|
|
63
105
|
paragraph
|
|
64
106
|
end
|
|
65
107
|
|
|
66
|
-
def
|
|
67
|
-
|
|
68
|
-
|
|
108
|
+
def align(paragraph, value)
|
|
109
|
+
paragraph.properties.alignment =
|
|
110
|
+
Uniword::Properties::Alignment.new(value: value)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def right_margin_tab
|
|
114
|
+
Uniword::Wordprocessingml::Run.new(
|
|
115
|
+
position_tab: Uniword::Wordprocessingml::PositionTab.new(
|
|
116
|
+
relative_to: "margin", alignment: "right", leader: "none",
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Same look as the template's FooterPageNumber (bold 11pt) and
|
|
122
|
+
# FooterPageRomanNumber (11pt), which are paragraph styles and so
|
|
123
|
+
# cannot apply to the number alone on a shared line.
|
|
124
|
+
def page_number_properties(scheme)
|
|
125
|
+
return nil unless scheme.roman? || scheme.arabic?
|
|
69
126
|
|
|
70
|
-
|
|
127
|
+
Uniword::Wordprocessingml::RunProperties.new(
|
|
128
|
+
bold: scheme.arabic? ? Uniword::Properties::Bold.new : nil,
|
|
129
|
+
size: Uniword::Properties::FontSize.new(value: 22),
|
|
130
|
+
)
|
|
71
131
|
end
|
|
72
132
|
|
|
73
|
-
#
|
|
133
|
+
# A PAGE complex field as four <w:r> runs (begin, instrText,
|
|
74
134
|
# separate, end). Each OOXML field component MUST be wrapped in a
|
|
75
|
-
# <w:r
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
135
|
+
# <w:r>; bare <w:fldChar>/<w:instrText> is schema-invalid.
|
|
136
|
+
def page_number_runs(scheme)
|
|
137
|
+
runs = [field_char_run("begin"), instr_text_run(PAGE_FIELD_INSTRUCTION),
|
|
138
|
+
field_char_run("separate"), field_char_run("end")]
|
|
139
|
+
properties = page_number_properties(scheme)
|
|
140
|
+
runs.each { |run| run.properties = properties } if properties
|
|
141
|
+
runs
|
|
82
142
|
end
|
|
83
143
|
|
|
84
144
|
def field_char_run(kind)
|