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
|
@@ -100,6 +100,16 @@ module IsoDoc
|
|
|
100
100
|
@resolver.auto_numbered_style?(style.value)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
+
# Runs the block with autonum stripping off. A cross-reference's
|
|
104
|
+
# label ("Clause 1") is its own content, not the heading's number.
|
|
105
|
+
def without_autonum_stripping
|
|
106
|
+
was_stripping = @strip_autonum
|
|
107
|
+
@strip_autonum = false
|
|
108
|
+
yield
|
|
109
|
+
ensure
|
|
110
|
+
@strip_autonum = was_stripping
|
|
111
|
+
end
|
|
112
|
+
|
|
103
113
|
# Whether the renderer is currently stripping autonum carriers
|
|
104
114
|
# (i.e., inside a heading render where the paragraph style
|
|
105
115
|
# carries numPr). Handlers consult this to skip autonum content.
|
|
@@ -227,16 +237,7 @@ module IsoDoc
|
|
|
227
237
|
# MixedInlineFallbackRenderer, FmtXrefRenderer).
|
|
228
238
|
def render_mixed_inline_fallback(element, para)
|
|
229
239
|
if ordered?(element)
|
|
230
|
-
|
|
231
|
-
element.each_mixed_content do |child|
|
|
232
|
-
case child
|
|
233
|
-
when String then add_text(para, child)
|
|
234
|
-
else
|
|
235
|
-
next if fmt_twin_of_stem?(child, twins)
|
|
236
|
-
|
|
237
|
-
dispatch_inline(child, para)
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
+
render_ordered_inline(element, para)
|
|
240
241
|
else
|
|
241
242
|
text = collect_text(element)
|
|
242
243
|
add_text(para, text) if text && !text.empty?
|
|
@@ -250,20 +251,32 @@ module IsoDoc
|
|
|
250
251
|
def render_with_run_format(element, para)
|
|
251
252
|
temp = Uniword::Builder::ParagraphBuilder.new
|
|
252
253
|
render_mixed_inline_fallback(element, temp)
|
|
253
|
-
temp.model
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
end
|
|
261
|
-
temp.model.hyperlinks.each do |link|
|
|
262
|
-
link.runs.each do |run|
|
|
254
|
+
each_ordered_element(temp.model) do |type, child|
|
|
255
|
+
next unless type == :element
|
|
256
|
+
|
|
257
|
+
runs = child.is_a?(Uniword::Wordprocessingml::Hyperlink) ? child.runs : [child]
|
|
258
|
+
runs.each do |run|
|
|
259
|
+
next unless run.is_a?(Uniword::Wordprocessingml::Run)
|
|
260
|
+
|
|
263
261
|
run.properties ||= Uniword::Wordprocessingml::RunProperties.new
|
|
264
262
|
yield run
|
|
265
263
|
end
|
|
266
|
-
para
|
|
264
|
+
append_formatted_child(para, child)
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Uniword merges a new run with its last run even when a hyperlink
|
|
269
|
+
# or equation intervenes. Keep that boundary in the mixed sequence.
|
|
270
|
+
def append_formatted_child(para, child)
|
|
271
|
+
if child.is_a?(Uniword::Wordprocessingml::Run) &&
|
|
272
|
+
!child.tab && !child.break &&
|
|
273
|
+
para.is_a?(Uniword::Builder::ParagraphBuilder) &&
|
|
274
|
+
para.model.element_order&.last &&
|
|
275
|
+
para.model.element_order.last.name != "r"
|
|
276
|
+
para.model.runs << child
|
|
277
|
+
para.model.element_order << Lutaml::Xml::Element.new("Element", "r")
|
|
278
|
+
else
|
|
279
|
+
para << child
|
|
267
280
|
end
|
|
268
281
|
end
|
|
269
282
|
|
|
@@ -429,16 +442,16 @@ module IsoDoc
|
|
|
429
442
|
# TextElements::Asciiml carries :value, the presentation
|
|
430
443
|
# Inline::AsciimathElement carries :text. Prefer whichever the
|
|
431
444
|
# model declares.
|
|
432
|
-
def stem_asciimath_content(
|
|
433
|
-
return
|
|
445
|
+
def stem_asciimath_content(asciimath)
|
|
446
|
+
return asciimath if asciimath.is_a?(String)
|
|
434
447
|
|
|
435
|
-
return nil unless
|
|
448
|
+
return nil unless asciimath.is_a?(Lutaml::Model::Serializable)
|
|
436
449
|
|
|
437
|
-
if
|
|
438
|
-
value = attribute_value(
|
|
450
|
+
if asciimath.class.attributes.key?(:value)
|
|
451
|
+
value = attribute_value(asciimath, :value)
|
|
439
452
|
return value if value.is_a?(String) && !value.empty?
|
|
440
453
|
end
|
|
441
|
-
return attribute_value(
|
|
454
|
+
return attribute_value(asciimath, :text) if asciimath.class.attributes.key?(:text)
|
|
442
455
|
|
|
443
456
|
nil
|
|
444
457
|
end
|
|
@@ -536,14 +549,31 @@ module IsoDoc
|
|
|
536
549
|
segments.join
|
|
537
550
|
end
|
|
538
551
|
|
|
539
|
-
#
|
|
540
|
-
#
|
|
541
|
-
#
|
|
552
|
+
# Presentation targets can be reused across numbering scopes. Include
|
|
553
|
+
# the body to distinguish collisions while repeated references still
|
|
554
|
+
# share one definition. Ignore source IDs, which differ between copies.
|
|
542
555
|
def footnote_cache_key(element)
|
|
543
|
-
|
|
544
|
-
return
|
|
556
|
+
identity = element.target || element.id
|
|
557
|
+
return unless identity
|
|
545
558
|
|
|
546
|
-
|
|
559
|
+
bodies = Array(element.p).map do |paragraph|
|
|
560
|
+
xml = Nokogiri::XML(paragraph.to_xml)
|
|
561
|
+
xml.xpath("//@id | //@semx-id | //@original-id | //@source").remove
|
|
562
|
+
xml.root.to_xml
|
|
563
|
+
end
|
|
564
|
+
[identity, bodies]
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
def with_heading_annotations_suppressed
|
|
568
|
+
previous = @heading_annotations_suppressed
|
|
569
|
+
@heading_annotations_suppressed = true
|
|
570
|
+
yield
|
|
571
|
+
ensure
|
|
572
|
+
@heading_annotations_suppressed = previous
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
def heading_annotations_suppressed?
|
|
576
|
+
@heading_annotations_suppressed
|
|
547
577
|
end
|
|
548
578
|
|
|
549
579
|
def cached_footnote_id(cache_key)
|
|
@@ -598,25 +628,79 @@ module IsoDoc
|
|
|
598
628
|
# FootnoteText style, so the body text matches the Era C
|
|
599
629
|
# template's footnote typography rather than the document
|
|
600
630
|
# default.
|
|
601
|
-
#
|
|
602
|
-
#
|
|
603
|
-
#
|
|
604
|
-
|
|
605
|
-
def build_footnote_with_style(text, closing: nil)
|
|
631
|
+
# DOCX uses Word's bare number marker and a space before the text.
|
|
632
|
+
# +element+ is the footnote, whose body paragraphs are rendered
|
|
633
|
+
# with their inline markup when they carry any.
|
|
634
|
+
def build_footnote_with_style(text, element: nil)
|
|
606
635
|
style = @resolver.paragraph_style(:footnote_text)
|
|
607
636
|
run = @doc.footnote do |p|
|
|
608
637
|
p.style = style if style
|
|
609
|
-
p
|
|
638
|
+
if element && Array(element.p).any? { |body| has_rich_children?(body) }
|
|
639
|
+
with_footnote_body do
|
|
640
|
+
Array(element.p).each_with_index do |body, index|
|
|
641
|
+
p << " " unless index.zero?
|
|
642
|
+
render(body, p)
|
|
643
|
+
end
|
|
644
|
+
end
|
|
645
|
+
else
|
|
646
|
+
p << text
|
|
647
|
+
end
|
|
610
648
|
end
|
|
611
|
-
finish_footnote_body(@doc.model.footnotes.footnote_entries.last
|
|
649
|
+
finish_footnote_body(@doc.model.footnotes.footnote_entries.last)
|
|
612
650
|
run
|
|
613
651
|
end
|
|
614
652
|
|
|
653
|
+
# True while a footnote body is being rendered: its hyperlinks live
|
|
654
|
+
# in word/footnotes.xml, so their rIds belong to the footnotes part.
|
|
655
|
+
def in_footnote_body?
|
|
656
|
+
@in_footnote_body ? true : false
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
def with_footnote_body
|
|
660
|
+
previous = @in_footnote_body
|
|
661
|
+
@in_footnote_body = true
|
|
662
|
+
yield
|
|
663
|
+
ensure
|
|
664
|
+
@in_footnote_body = previous
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
# The rId of an external hyperlink for +url+ in
|
|
668
|
+
# word/_rels/footnotes.xml.rels, registered once per target.
|
|
669
|
+
# Ids are allocated in their own allocator scope, seeded from any
|
|
670
|
+
# relationships the footnotes part already carries.
|
|
671
|
+
def footnote_hyperlink_rid(url)
|
|
672
|
+
rels = footnote_rels
|
|
673
|
+
type = Uniword::Docx::IdAllocator::HYPERLINK_REL_TYPE
|
|
674
|
+
rid = @doc.allocator.alloc_rid(target: url, type: type,
|
|
675
|
+
target_mode: "External",
|
|
676
|
+
scope: :footnotes)
|
|
677
|
+
unless rels.relationships.any? { |r| r.id == rid }
|
|
678
|
+
rels.relationships << Uniword::Ooxml::Relationships::PackageRelationship.new(
|
|
679
|
+
id: rid, type: type, target: url, target_mode: "External",
|
|
680
|
+
)
|
|
681
|
+
end
|
|
682
|
+
rid
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
# The footnotes relationships part being built (the adapter resets
|
|
686
|
+
# it per conversion), seeded once into the allocator so new ids
|
|
687
|
+
# cannot collide with relationships it already carries.
|
|
688
|
+
def footnote_rels
|
|
689
|
+
model = @doc.model
|
|
690
|
+
rels = (model.footnotes_rels ||=
|
|
691
|
+
Uniword::Ooxml::Relationships::PackageRelationships.new)
|
|
692
|
+
unless @seeded_footnote_rels.equal?(rels)
|
|
693
|
+
@doc.allocator.seed_from_rels(rels.relationships, scope: :footnotes)
|
|
694
|
+
@seeded_footnote_rels = rels
|
|
695
|
+
end
|
|
696
|
+
rels
|
|
697
|
+
end
|
|
698
|
+
|
|
615
699
|
# The builder prepends the number marker as the paragraph's first
|
|
616
700
|
# run, ahead of w:pPr, and leaves it in the body style. Put w:pPr
|
|
617
701
|
# first (CT_P order), superscript the marker with the template's
|
|
618
|
-
# FootnoteReference style, and
|
|
619
|
-
def finish_footnote_body(entry
|
|
702
|
+
# FootnoteReference style, and separate it from the body text.
|
|
703
|
+
def finish_footnote_body(entry)
|
|
620
704
|
para = entry.paragraphs.first
|
|
621
705
|
order = para.element_order
|
|
622
706
|
if order.is_a?(Array) && (ppr = order.find { |e| e.name == "pPr" })
|
|
@@ -625,18 +709,12 @@ module IsoDoc
|
|
|
625
709
|
end
|
|
626
710
|
marker = para.runs.first
|
|
627
711
|
apply_run_char_style(marker, :footnote_reference)
|
|
628
|
-
add_footnote_closing(para, order, closing) if closing
|
|
629
|
-
end
|
|
630
|
-
|
|
631
|
-
def add_footnote_closing(para, order, closing)
|
|
632
|
-
closing_run = Uniword::Wordprocessingml::Run.new(text: closing)
|
|
633
|
-
apply_run_char_style(closing_run, :footnote_reference)
|
|
634
712
|
gap = Uniword::Wordprocessingml::Run.new(text: " ")
|
|
635
|
-
para.runs.insert(1,
|
|
713
|
+
para.runs.insert(1, gap)
|
|
636
714
|
return unless order.is_a?(Array)
|
|
637
715
|
|
|
638
716
|
at = order.index { |e| e.name == "r" }.to_i + 1
|
|
639
|
-
|
|
717
|
+
order.insert(at, Lutaml::Xml::Element.new("Element", "r"))
|
|
640
718
|
end
|
|
641
719
|
|
|
642
720
|
def lookup_comment_id(annotation_target_id)
|
|
@@ -700,7 +778,8 @@ module IsoDoc
|
|
|
700
778
|
return if walked
|
|
701
779
|
|
|
702
780
|
node.each_mixed_content do |child|
|
|
703
|
-
case child
|
|
781
|
+
case child
|
|
782
|
+
when String then add_text(para, child)
|
|
704
783
|
else dispatch_inline(child, para)
|
|
705
784
|
end
|
|
706
785
|
end
|
|
@@ -822,11 +901,28 @@ module IsoDoc
|
|
|
822
901
|
when :element
|
|
823
902
|
next if autonum_carrier?(obj)
|
|
824
903
|
|
|
825
|
-
segments <<
|
|
904
|
+
segments << collect_heading_element_text(obj)
|
|
826
905
|
end
|
|
827
906
|
end
|
|
828
907
|
segments.join
|
|
829
908
|
end
|
|
909
|
+
|
|
910
|
+
# Text of a heading child at any depth. collect_text reads only an
|
|
911
|
+
# element's own strings, so a title holding only <tt> read empty.
|
|
912
|
+
# A cross-reference's label is its own content, so its autonum
|
|
913
|
+
# spans count.
|
|
914
|
+
def collect_heading_element_text(element)
|
|
915
|
+
return collect_all_text(element) if element.is_a?(Metanorma::Document::Components::Inline::FmtXrefElement)
|
|
916
|
+
return collect_text(element).to_s unless ordered?(element)
|
|
917
|
+
|
|
918
|
+
segments = []
|
|
919
|
+
each_ordered_element(element) do |type, obj|
|
|
920
|
+
next if type == :element && autonum_carrier?(obj)
|
|
921
|
+
|
|
922
|
+
segments << (type == :text ? obj.to_s : collect_heading_element_text(obj))
|
|
923
|
+
end
|
|
924
|
+
segments.join
|
|
925
|
+
end
|
|
830
926
|
end
|
|
831
927
|
end
|
|
832
928
|
end
|
|
@@ -12,6 +12,8 @@ module IsoDoc
|
|
|
12
12
|
# The name is claimed like every other id bookmark, so an id
|
|
13
13
|
# already bookmarked (a clause, a block) is not emitted twice.
|
|
14
14
|
def render(element, para)
|
|
15
|
+
return if parent.heading_annotations_suppressed?
|
|
16
|
+
|
|
15
17
|
name = context.claim_bookmark_name(bookmark_name(element))
|
|
16
18
|
return unless name
|
|
17
19
|
|
|
@@ -32,7 +32,9 @@ module IsoDoc
|
|
|
32
32
|
link_model.anchor = context.bookmark_name(target)
|
|
33
33
|
|
|
34
34
|
temp = Uniword::Builder::ParagraphBuilder.new
|
|
35
|
-
parent.
|
|
35
|
+
parent.without_autonum_stripping do
|
|
36
|
+
parent.render_mixed_inline_fallback(element, temp)
|
|
37
|
+
end
|
|
36
38
|
temp.model.runs.each { |r| link_model.runs << r }
|
|
37
39
|
|
|
38
40
|
if link_model.runs.empty?
|
|
@@ -16,6 +16,9 @@ module IsoDoc
|
|
|
16
16
|
include Base
|
|
17
17
|
|
|
18
18
|
def render(element, para)
|
|
19
|
+
return if parent.heading_annotations_suppressed?
|
|
20
|
+
return render_nested(element, para) if parent.in_footnote_body?
|
|
21
|
+
|
|
19
22
|
handler = context.formula_key_footnote_handler
|
|
20
23
|
return handler.call(element, para) if handler && !element.reference.to_s.strip.empty?
|
|
21
24
|
|
|
@@ -27,11 +30,9 @@ module IsoDoc
|
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
text = parent.extract_footnote_text(element)
|
|
30
|
-
return if text.nil? || text.empty?
|
|
33
|
+
return if (text.nil? || text.empty?) && !has_bare_link?(element)
|
|
31
34
|
|
|
32
|
-
fn_run = parent.build_footnote_with_style(
|
|
33
|
-
text, closing: label_closing(element)
|
|
34
|
-
)
|
|
35
|
+
fn_run = parent.build_footnote_with_style(text, element: element)
|
|
35
36
|
fn_id = fn_run.footnote_reference&.id
|
|
36
37
|
parent.store_footnote_id(cache_key, fn_id) if cache_key && fn_id
|
|
37
38
|
parent.apply_run_char_style(fn_run, :footnote_reference)
|
|
@@ -41,20 +42,20 @@ module IsoDoc
|
|
|
41
42
|
|
|
42
43
|
private
|
|
43
44
|
|
|
44
|
-
# ISO
|
|
45
|
-
#
|
|
46
|
-
# footnote
|
|
47
|
-
def label_closing(element)
|
|
48
|
-
return unless element.fmt_fn_label
|
|
45
|
+
# ISO marks a body reference "1)", as the DOC output does. The
|
|
46
|
+
# presentation XML carries the parenthesis in fmt-fn-label. The
|
|
47
|
+
# mark in the footnote area stays a bare number, also as in DOC.
|
|
48
|
+
def label_closing?(element)
|
|
49
|
+
return false unless element.fmt_fn_label
|
|
49
50
|
|
|
50
|
-
parent.collect_all_text(element.fmt_fn_label).rstrip.end_with?(")")
|
|
51
|
+
parent.collect_all_text(element.fmt_fn_label).rstrip.end_with?(")")
|
|
51
52
|
end
|
|
52
53
|
|
|
54
|
+
# Word supplies the number, so the parenthesis is its own run,
|
|
55
|
+
# placed before the separator that follows the fn element.
|
|
53
56
|
def append_marker_suffix(element, para)
|
|
54
|
-
return unless label_closing(element)
|
|
57
|
+
return unless label_closing?(element)
|
|
55
58
|
|
|
56
|
-
# Word supplies the number. Add the presentation label's closing
|
|
57
|
-
# parenthesis before the separator that follows the fn element.
|
|
58
59
|
properties = Uniword::Wordprocessingml::RunProperties.new(
|
|
59
60
|
vertical_align: Uniword::Properties::VerticalAlign.new(value: "superscript"),
|
|
60
61
|
)
|
|
@@ -63,6 +64,21 @@ module IsoDoc
|
|
|
63
64
|
para << run
|
|
64
65
|
end
|
|
65
66
|
|
|
67
|
+
# Word cannot nest a footnote in a footnote body, so the inner
|
|
68
|
+
# footnote's content is kept inline in the outer body.
|
|
69
|
+
def render_nested(element, para)
|
|
70
|
+
Array(element.p).each_with_index do |body, index|
|
|
71
|
+
para << " " unless index.zero?
|
|
72
|
+
parent.render(body, para)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def has_bare_link?(element)
|
|
77
|
+
element.p&.any? do |paragraph|
|
|
78
|
+
Array(paragraph.link).any? { |link| !link.target.to_s.empty? }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
66
82
|
def append_cached_reference(para, cache_key)
|
|
67
83
|
id = parent.cached_footnote_id(cache_key)
|
|
68
84
|
fn_run = Uniword::Wordprocessingml::Run.new(
|
|
@@ -11,8 +11,9 @@ module IsoDoc
|
|
|
11
11
|
include Base
|
|
12
12
|
|
|
13
13
|
def render(element, para)
|
|
14
|
-
text = parent.
|
|
14
|
+
text = parent.collect_all_text(element)
|
|
15
15
|
target = element.target
|
|
16
|
+
target = nil if target.to_s.strip.empty?
|
|
16
17
|
|
|
17
18
|
if text.nil? || text.empty?
|
|
18
19
|
text = target
|
|
@@ -22,7 +23,7 @@ module IsoDoc
|
|
|
22
23
|
|
|
23
24
|
if target
|
|
24
25
|
link = Uniword::Hyperlink.new(url: target, text: text)
|
|
25
|
-
model = link
|
|
26
|
+
model = hyperlink_model(link, target)
|
|
26
27
|
parent.apply_hyperlink_style(model)
|
|
27
28
|
para << model
|
|
28
29
|
else
|
|
@@ -31,6 +32,16 @@ module IsoDoc
|
|
|
31
32
|
para << run.build
|
|
32
33
|
end
|
|
33
34
|
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
# A footnote body is written to word/footnotes.xml, whose
|
|
39
|
+
# relationships are separate from the document's.
|
|
40
|
+
def hyperlink_model(link, target)
|
|
41
|
+
return link.to_model(allocator: doc.allocator) unless parent.in_footnote_body?
|
|
42
|
+
|
|
43
|
+
link.to_model.tap { |m| m.id = parent.footnote_hyperlink_rid(target) }
|
|
44
|
+
end
|
|
34
45
|
end
|
|
35
46
|
end
|
|
36
47
|
end
|
|
@@ -11,11 +11,30 @@ module IsoDoc
|
|
|
11
11
|
include Base
|
|
12
12
|
|
|
13
13
|
def render(element, para)
|
|
14
|
+
if parent.ordered?(element) && parent.has_rich_children?(element)
|
|
15
|
+
return render_rich(element, para)
|
|
16
|
+
end
|
|
17
|
+
|
|
14
18
|
text = parent.collect_text(element)
|
|
15
19
|
return if text.nil? || text.empty?
|
|
16
20
|
|
|
17
21
|
parent.add_text_with_char_style(para, text, :inline_code)
|
|
18
22
|
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# Keep nested xref/link/footnote/stem/bold content in order and
|
|
27
|
+
# give every produced text run the InlineCode style. A link's
|
|
28
|
+
# Hyperlink style yields to it; other styles are kept.
|
|
29
|
+
def render_rich(element, para)
|
|
30
|
+
link_style = parent.resolver.character_style(:hyperlink)
|
|
31
|
+
parent.render_with_run_format(element, para) do |run|
|
|
32
|
+
current = run.properties.style&.value
|
|
33
|
+
next if current && current != link_style
|
|
34
|
+
|
|
35
|
+
parent.apply_run_char_style(run, :inline_code)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
19
38
|
end
|
|
20
39
|
end
|
|
21
40
|
end
|
|
@@ -11,28 +11,30 @@ module IsoDoc
|
|
|
11
11
|
# - MainTitle2 paragraph for title part (with optional prefix)
|
|
12
12
|
#
|
|
13
13
|
# Title text is sourced from bibdata.titles (TitleCollection)
|
|
14
|
-
# for
|
|
14
|
+
# for the document's language. No hardcoded title strings.
|
|
15
15
|
class MiddleTitleRenderer
|
|
16
16
|
TITLE_SEPARATOR = " — "
|
|
17
17
|
private_constant :TITLE_SEPARATOR
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
# The DIS Word stylesheet sets zzSTDTitle to blue.
|
|
20
|
+
DIS_COLOR = "0000FF"
|
|
21
|
+
|
|
22
|
+
def initialize(resolver:, inline_renderer:, color: nil)
|
|
20
23
|
@resolver = resolver
|
|
21
24
|
@inline_renderer = inline_renderer
|
|
25
|
+
@color = color
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def render(model, doc)
|
|
25
29
|
bib = bibdata(model)
|
|
26
30
|
return unless bib
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
next unless localized
|
|
32
|
+
localized = localized_title(bib, document_language(bib))
|
|
33
|
+
return unless localized
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
end
|
|
35
|
+
render_main(localized, doc)
|
|
36
|
+
render_part(localized, doc)
|
|
37
|
+
render_amd(localized, doc)
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
private
|
|
@@ -43,23 +45,34 @@ module IsoDoc
|
|
|
43
45
|
model.bibdata
|
|
44
46
|
end
|
|
45
47
|
|
|
48
|
+
def document_language(bib)
|
|
49
|
+
language = Array(bib.language).first if bib.class.attributes.key?(:language)
|
|
50
|
+
value = language.is_a?(String) ? language : language&.value
|
|
51
|
+
code = value.to_s.split(/[-_]/).first.to_s
|
|
52
|
+
code.empty? ? "en" : code
|
|
53
|
+
end
|
|
54
|
+
|
|
46
55
|
def render_main(localized, doc)
|
|
47
56
|
text = main_text(localized)
|
|
48
57
|
return if text.nil? || text.empty?
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
para.style = @resolver.paragraph_style(:main_title1)
|
|
52
|
-
para << text
|
|
53
|
-
doc << para
|
|
59
|
+
append_title(doc, :main_title1, text)
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
def render_part(localized, doc)
|
|
57
63
|
text = part_text(localized)
|
|
58
64
|
return if text.nil? || text.empty?
|
|
59
65
|
|
|
66
|
+
append_title(doc, :main_title2, text)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def append_title(doc, style_key, text)
|
|
70
|
+
run = Uniword::Builder::RunBuilder.new
|
|
71
|
+
run.text(text)
|
|
72
|
+
run.color(@color) if @color
|
|
60
73
|
para = Uniword::Builder::ParagraphBuilder.new
|
|
61
|
-
para.style = @resolver.paragraph_style(
|
|
62
|
-
para <<
|
|
74
|
+
para.style = @resolver.paragraph_style(style_key)
|
|
75
|
+
para << run.build
|
|
63
76
|
doc << para
|
|
64
77
|
end
|
|
65
78
|
|
|
@@ -77,10 +90,7 @@ module IsoDoc
|
|
|
77
90
|
return if label.empty? && description.empty?
|
|
78
91
|
|
|
79
92
|
text = label.empty? ? description : "#{label}: #{description}"
|
|
80
|
-
|
|
81
|
-
para.style = @resolver.paragraph_style(:main_title2)
|
|
82
|
-
para << text
|
|
83
|
-
doc << para
|
|
93
|
+
append_title(doc, :main_title2, text)
|
|
84
94
|
end
|
|
85
95
|
|
|
86
96
|
def main_text(localized)
|
|
@@ -88,7 +98,7 @@ module IsoDoc
|
|
|
88
98
|
parts << localized.title_intro.value if localized.title_intro
|
|
89
99
|
parts << localized.title_main.value if localized.title_main
|
|
90
100
|
parts << localized.title_full.value if localized.title_full && !localized.title_main
|
|
91
|
-
parts.
|
|
101
|
+
parts.reject { |text| text.to_s.strip.empty? }.join(TITLE_SEPARATOR)
|
|
92
102
|
end
|
|
93
103
|
|
|
94
104
|
def part_text(localized)
|
|
@@ -96,13 +106,13 @@ module IsoDoc
|
|
|
96
106
|
|
|
97
107
|
prefix = localized.title_part_prefix&.value.to_s.strip
|
|
98
108
|
part_val = localized.title_part.value
|
|
99
|
-
return nil if part_val.nil? || part_val.to_s.empty?
|
|
109
|
+
return nil if part_val.nil? || part_val.to_s.strip.empty?
|
|
100
110
|
|
|
101
|
-
if
|
|
111
|
+
if prefix.empty?
|
|
112
|
+
part_val.to_s
|
|
113
|
+
else
|
|
102
114
|
sep = prefix.end_with?(":") ? " " : ": "
|
|
103
115
|
"#{prefix}#{sep}#{part_val}"
|
|
104
|
-
else
|
|
105
|
-
part_val.to_s
|
|
106
116
|
end
|
|
107
117
|
end
|
|
108
118
|
|
|
@@ -112,7 +122,11 @@ module IsoDoc
|
|
|
112
122
|
titles = bib.titles
|
|
113
123
|
return nil unless titles.is_a?(Metanorma::Iso::Document::Metadata::TitleCollection)
|
|
114
124
|
|
|
115
|
-
titles.for_language(language)
|
|
125
|
+
candidates = [titles.for_language(language), titles.for_language("en")]
|
|
126
|
+
candidates.concat(Array(titles.per_language)).compact.find do |title|
|
|
127
|
+
[main_text(title), part_text(title), title.title_amd&.value,
|
|
128
|
+
title.title_amendment_prefix&.value].any? { |text| !text.to_s.strip.empty? }
|
|
129
|
+
end
|
|
116
130
|
rescue StandardError
|
|
117
131
|
nil
|
|
118
132
|
end
|
|
@@ -47,6 +47,7 @@ module IsoDoc
|
|
|
47
47
|
para = build_paragraph(:admonition)
|
|
48
48
|
@inline_renderer.render(admonition, para)
|
|
49
49
|
doc << para
|
|
50
|
+
@walker.walk_attribute(admonition, :note, doc)
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
def render_body_paragraph(paragraph, doc)
|
|
@@ -54,6 +55,7 @@ module IsoDoc
|
|
|
54
55
|
@inline_renderer.render(paragraph, para)
|
|
55
56
|
anchor_paragraph(paragraph, para)
|
|
56
57
|
doc << para
|
|
58
|
+
@walker.walk_attribute(paragraph, :note, doc)
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
def attribute_value(node, attr)
|