From 7d4c8d641443d668392ef8c3c58b155033003ff6 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Sun, 24 Nov 2024 21:08:54 +1100 Subject: [PATCH] semantically annotate hierarchically formed labels of bloocks: https://github.com/metanorma/isodoc/issues/617 --- lib/isodoc/xref/xref_anchor.rb | 1 - lib/isodoc/xref/xref_util.rb | 5 +- spec/isodoc/blocks_spec.rb | 8 +- spec/isodoc/figures_spec.rb | 4 +- spec/isodoc/table_spec.rb | 4 +- spec/isodoc/xref_spec.rb | 560 ++++++++++++++++++--------------- 6 files changed, 321 insertions(+), 261 deletions(-) diff --git a/lib/isodoc/xref/xref_anchor.rb b/lib/isodoc/xref/xref_anchor.rb index 4277bcee..bbcb817a 100644 --- a/lib/isodoc/xref/xref_anchor.rb +++ b/lib/isodoc/xref/xref_anchor.rb @@ -44,7 +44,6 @@ def anchor_struct_label(lbl, node, elem) def anchor_struct_xref(lbl, node, elem) unless lbl.blank? lbl = semx(node, lbl) - #lbl = "#{lbl}" s = " #{anchor_struct_value(lbl, elem)}" end l10n("#{elem}#{s}") diff --git a/lib/isodoc/xref/xref_util.rb b/lib/isodoc/xref/xref_util.rb index 9c907737..49a9f038 100644 --- a/lib/isodoc/xref/xref_util.rb +++ b/lib/isodoc/xref/xref_util.rb @@ -48,9 +48,12 @@ def child_sections CHILD_SECTIONS end + # if hierarchically marked up node in label already, + # leave alone, else wrap in semx def semx(node, label, element = "autonum") - l = stripsemx(label) id = node["id"] || node[:id] + /#{l}) end diff --git a/spec/isodoc/blocks_spec.rb b/spec/isodoc/blocks_spec.rb index e34f4269..62eccf7e 100644 --- a/spec/isodoc/blocks_spec.rb +++ b/spec/isodoc/blocks_spec.rb @@ -625,7 +625,9 @@ Formula ( - A.1 + A + . + 1 ) r = 1 % @@ -1075,7 +1077,9 @@ Permission - A.1 + A + . + 1

As for the measurement targets,

diff --git a/spec/isodoc/figures_spec.rb b/spec/isodoc/figures_spec.rb index 213af88c..91201154 100644 --- a/spec/isodoc/figures_spec.rb +++ b/spec/isodoc/figures_spec.rb @@ -232,7 +232,9 @@ Figure - A.1 + A + . + 1
A <
   B
diff --git a/spec/isodoc/table_spec.rb b/spec/isodoc/table_spec.rb index fab085ea..7db98413 100644 --- a/spec/isodoc/table_spec.rb +++ b/spec/isodoc/table_spec.rb @@ -301,7 +301,9 @@ Table - A.1 + A + . + 1 diff --git a/spec/isodoc/xref_spec.rb b/spec/isodoc/xref_spec.rb index cb5992cd..4c4511cc 100644 --- a/spec/isodoc/xref_spec.rb +++ b/spec/isodoc/xref_spec.rb @@ -533,67 +533,73 @@ INPUT output = <<~OUTPUT - - Foreword - - - Foreword - - -

- - Figure - 1 - - - Figure - (??) - - - Figure - 2 - - - Figure - 3 - - - Figure - 4 - - - Figure - 5 - - - Figure - 6 - - [note51] - - Figure - A.1 - - - Figure - (??) - - - Figure - A.2 - - - Figure - A.3 - - - Bibliographical Section - , - Figure - 1 - -

-
+ + Foreword + + + Foreword + + +

+ + Figure + 1 + + + Figure + (??) + + + Figure + 2 + + + Figure + 3 + + + Figure + 4 + + + Figure + 5 + + + Figure + 6 + + [note51] + + Figure + A + . + 1 + + + Figure + (??) + + + Figure + A + . + 2 + + + Figure + A + . + 3 + + + Bibliographical Section + , + Figure + 1 + +

+
OUTPUT expect(Xml::C14n.format(strip_guid(Nokogiri.XML(IsoDoc::PresentationXMLConvert .new(presxml_options) @@ -700,70 +706,76 @@ INPUT output = <<~OUTPUT - - Foreword - - - Foreword - - -

- - Figure - 1 - - - Figure - (??) - - - Diagram - 1 - - - Plate - 1 - - - Figure - 2 - - - Figure - 3 - - - Diagram - 2 - - - Figure - 4 - - - Diagram - A.1 - - - Plate - (??) - - - Figure - A.1 - - - Figure - A.2 - - - Bibliographical Section - , - Figure - 1 - -

-
+ + Foreword + + + Foreword + + +

+ + Figure + 1 + + + Figure + (??) + + + Diagram + 1 + + + Plate + 1 + + + Figure + 2 + + + Figure + 3 + + + Diagram + 2 + + + Figure + 4 + + + Diagram + A + . + 1 + + + Plate + (??) + + + Figure + A + . + 1 + + + Figure + A + . + 2 + + + Bibliographical Section + , + Figure + 1 + +

+
OUTPUT expect(Xml::C14n.format(strip_guid(Nokogiri.XML(IsoDoc::PresentationXMLConvert .new(presxml_options) @@ -867,17 +879,23 @@ Figure - A.1 + A + . + 1 Figure - A.1 + A + . + 1 - 1 Figure - A.1 + A + . + 1 - 2 @@ -1236,9 +1254,9 @@ Clause - 3 - . - 1 + 3 + . + 1 , Formula ( @@ -1248,8 +1266,8 @@ Clause 3 - . - 1 + . + 1 , Formula ( @@ -1259,7 +1277,9 @@ Formula ( - A.1 + A + . + 1 ) @@ -1271,7 +1291,9 @@ Formula ( - A.2 + A + . + 2 ) @@ -1409,7 +1431,9 @@ Requirement - A.1 + A + . + 1 Requirement @@ -1417,7 +1441,9 @@ Requirement - A.2 + A + . + 2 Bibliographical Section @@ -1536,7 +1562,9 @@ Recommendation - A.1 + A + . + 1 Recommendation @@ -1544,7 +1572,9 @@ Recommendation - A.2 + A + . + 2 Bibliographical Section @@ -1633,7 +1663,7 @@ INPUT output = <<~OUTPUT - + Foreword @@ -1663,7 +1693,9 @@ Permission - A.1 + A + . + 1 Permission @@ -1671,7 +1703,9 @@ Permission - A.2 + A + . + 2 Bibliographical Section @@ -1754,116 +1788,126 @@ INPUT output = <<~OUTPUT - - Foreword - - - Foreword - - -

- - Permission - 1 - - - Permission - 1 - - - 1 - - - Permission - 1 - - - 1 - - - 1 - - - Requirement - 1 - - - 1 - - - Recommendation - 1 - - - 1 - - - Permission - A.1 - - - Permission - A.1 - - - 1 - - - Permission - A.1 - - - 1 - - - 1 - - - Requirement - A.1 - - - 1 - - - Recommendation - A.1 - - - 1 - - - Bibliographical Section - , - Permission - 1 - - - Bibliographical Section - , - Permission - 1 - - - 1 - - - Bibliographical Section - , - Permission - 1 - - - 1 - - - 1 - - - Bibliographical Section - , - Requirement - 1 - - - 1 - - - Bibliographical Section - , - Recommendation - 1 - - - 1 - -

-
+ + Foreword + + + Foreword + + +

+ + Permission + 1 + + + Permission + 1 + - + 1 + + + Permission + 1 + - + 1 + - + 1 + + + Requirement + 1 + - + 1 + + + Recommendation + 1 + - + 1 + + + Permission + A + . + 1 + + + Permission + A + . + 1 + - + 1 + + + Permission + A + . + 1 + - + 1 + - + 1 + + + Requirement + A + . + 1 + - + 1 + + + Recommendation + A + . + 1 + - + 1 + + + Bibliographical Section + , + Permission + 1 + + + Bibliographical Section + , + Permission + 1 + - + 1 + + + Bibliographical Section + , + Permission + 1 + - + 1 + - + 1 + + + Bibliographical Section + , + Requirement + 1 + - + 1 + + + Bibliographical Section + , + Recommendation + 1 + - + 1 + +

+
OUTPUT expect(Xml::C14n.format(strip_guid(Nokogiri.XML(IsoDoc::PresentationXMLConvert .new(presxml_options) @@ -2036,7 +2080,9 @@
Table - A.1 + A + . + 1 Table @@ -2044,7 +2090,9 @@ Table - A.2 + A + . + 2 Bibliographical Section @@ -3038,7 +3086,9 @@ Figure - A.1 + A + . + 1 Annex