From 23ffa346b401ac8607583e205d390cd9b9c6fba7 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 18 Dec 2023 23:05:48 +1100 Subject: [PATCH 1/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/metadata.rb | 12 ++--- lib/isodoc/presentation_function/inline.rb | 16 ++++++ lib/isodoc/presentation_xml_convert.rb | 1 + spec/isodoc/presentation_xml_spec.rb | 57 +++++++++++++++++++--- 4 files changed, 72 insertions(+), 14 deletions(-) diff --git a/lib/isodoc/metadata.rb b/lib/isodoc/metadata.rb index 889bc374..ca201323 100644 --- a/lib/isodoc/metadata.rb +++ b/lib/isodoc/metadata.rb @@ -106,12 +106,12 @@ def draftinfo(draft, revdate) end def version(isoxml, _out) - set(:edition, isoxml&.at(ns("//bibdata/edition#{NOLANG}"))&.text) + set(:edition, isoxml.at(ns("//bibdata/edition#{NOLANG}"))&.text) set(:edition_display, - isoxml&.at(ns("//bibdata/edition#{currlang}"))&.text) - set(:docyear, isoxml&.at(ns("//bibdata/copyright/from"))&.text) - set(:draft, isoxml&.at(ns("//bibdata/version/draft"))&.text) - revdate = isoxml&.at(ns("//bibdata/version/revision-date"))&.text + isoxml.at(ns("//bibdata/edition#{currlang}"))&.text) + set(:docyear, isoxml.at(ns("//bibdata/copyright/from"))&.text) + set(:draft, isoxml.at(ns("//bibdata/version/draft"))&.text) + revdate = isoxml.at(ns("//bibdata/version/revision-date"))&.text set(:revdate, revdate) set(:revdate_monthyear, monthyr(revdate)) set(:draftinfo, @@ -119,7 +119,7 @@ def version(isoxml, _out) end def title(isoxml, _out) - main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"))&.text + main = isoxml.at(ns("//bibdata/title[@language='#{@lang}']"))&.text set(:doctitle, main) end diff --git a/lib/isodoc/presentation_function/inline.rb b/lib/isodoc/presentation_function/inline.rb index 86f078d5..c7f95098 100644 --- a/lib/isodoc/presentation_function/inline.rb +++ b/lib/isodoc/presentation_function/inline.rb @@ -137,6 +137,22 @@ def extract_custom_charsets(docxml) end end + def ruby(docxml) + (docxml.xpath(ns("//ruby")) - docxml.xpath(ns("//ruby//ruby"))) + .each do |r| + ruby1(r) + end + end + + def ruby1(elem) + v = elem.at(ns("./pronunciation | ./annotation")).remove + elem.xpath(ns("./ruby")).each do |r| + ruby1(r) + end + t = elem.children.to_xml + elem.replace("#{t}#{v['value']}") + end + private def found_matching_variant_sibling(node) diff --git a/lib/isodoc/presentation_xml_convert.rb b/lib/isodoc/presentation_xml_convert.rb index 67ae3032..289fd083 100644 --- a/lib/isodoc/presentation_xml_convert.rb +++ b/lib/isodoc/presentation_xml_convert.rb @@ -86,6 +86,7 @@ def inline(docxml) quotesource docxml # feeds docxml eref2link docxml mathml docxml + ruby docxml variant docxml identifier docxml date docxml diff --git a/spec/isodoc/presentation_xml_spec.rb b/spec/isodoc/presentation_xml_spec.rb index 3b08cd61..c4f6ef86 100644 --- a/spec/isodoc/presentation_xml_spec.rb +++ b/spec/isodoc/presentation_xml_spec.rb @@ -1851,13 +1851,13 @@ INPUT presxml = <<~OUTPUT - - weather:"OGC Weather Symbols",conscript:"Code 2000" - Table of contents + + weather:"OGC Weather Symbols",conscript:"Code 2000" + Table of contents - -

-
+ +

+
OUTPUT expect(strip_guid(IsoDoc::PresentationXMLConvert .new(presxml_options) @@ -1887,7 +1887,6 @@ - @@ -1906,7 +1905,6 @@ - @@ -1944,6 +1942,49 @@ .to be_equivalent_to xmlpp(presxml) end + it "processes ruby markup" do + input = <<~INPUT + + + +

+ 東京 + 東京 + 東京 + 親友 + + + + + の方角 + + ! + !

+

+
+ INPUT + presxml = <<~OUTPUT + + Table of contents + +

+ 東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōtouとうnanなん の方角 + とうなんたつみ + まもプロテゴ! + まもプロテゴ!

+

+
+
+
+ OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options.merge(output_formats: { html: "html", doc: "doc" })) + .convert("test", input, true)) + .sub(%r{.*}m, "") + .sub(%r{.*}m, ""))) + .to be_equivalent_to xmlpp(presxml) + end + private def mock_symbols From 87736ff2b1495b6f3e98b04ddb0d7d9905c3eade Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 18 Dec 2023 23:15:58 +1100 Subject: [PATCH 2/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/function/inline.rb | 18 ++++++++ lib/isodoc/function/to_word_html.rb | 3 ++ spec/isodoc/inline_spec.rb | 61 ++++++++++++++++++++++++++++ spec/isodoc/presentation_xml_spec.rb | 43 -------------------- 4 files changed, 82 insertions(+), 43 deletions(-) diff --git a/lib/isodoc/function/inline.rb b/lib/isodoc/function/inline.rb index 45d223db..1202a2fc 100644 --- a/lib/isodoc/function/inline.rb +++ b/lib/isodoc/function/inline.rb @@ -155,6 +155,24 @@ def error_parse(node, out) p.b(role: "strong") { |e| e << text } end end + + def ruby_parse(node, out) + out.ruby do |e| + node.children.each { |n| parse(n, e) } + end + end + + def rt_parse(node, out) + out.rt do |e| + node.children.each { |n| parse(n, e) } + end + end + + def rb_parse(node, out) + out.rb do |e| + node.children.each { |n| parse(n, e) } + end + end end end end diff --git a/lib/isodoc/function/to_word_html.rb b/lib/isodoc/function/to_word_html.rb index 0249dbe0..92f3603d 100644 --- a/lib/isodoc/function/to_word_html.rb +++ b/lib/isodoc/function/to_word_html.rb @@ -253,6 +253,9 @@ def parse(node, out) when "span" then span_parse(node, out) when "location" then location_parse(node, out) when "columnbreak" then columnbreak_parse(node, out) + when "ruby" then ruby_parse(node, out) + when "rt" then rt_parse(node, out) + when "rb" then rb_parse(node, out) else error_parse(node, out) end end diff --git a/spec/isodoc/inline_spec.rb b/spec/isodoc/inline_spec.rb index cdd26787..9ad0452c 100644 --- a/spec/isodoc/inline_spec.rb +++ b/spec/isodoc/inline_spec.rb @@ -1978,4 +1978,65 @@ expect(xmlpp(IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true))).to be_equivalent_to xmlpp(output) end + + + it "processes ruby markup" do + input = <<~INPUT + + + +

+ 東京 + 東京 + 東京 + 親友 + + + + + の方角 + + ! + !

+

+
+ INPUT + presxml = <<~OUTPUT + + Table of contents + +

+ 東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōtouとうnanなん の方角 + とうなんたつみ + まもプロテゴ! + まもプロテゴ!

+

+
+
+
+ OUTPUT + html = <<~OUTPUT + #{HTML_HDR} +
+
+

Foreword

+

東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōtouとうnanなん の方角 + とうなんたつみ + まもプロテゴ! + まもプロテゴ!

+
+ + + + OUTPUT + expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options.merge(output_formats: { html: "html", doc: "doc" })) + .convert("test", input, true)) + .sub(%r{.*}m, "") + .sub(%r{.*}m, ""))) + .to be_equivalent_to xmlpp(presxml) + expect(xmlpp(IsoDoc::HtmlConvert.new({}) + .convert("test", presxml, true))).to be_equivalent_to xmlpp(html) + end + end diff --git a/spec/isodoc/presentation_xml_spec.rb b/spec/isodoc/presentation_xml_spec.rb index c4f6ef86..1cb93ce5 100644 --- a/spec/isodoc/presentation_xml_spec.rb +++ b/spec/isodoc/presentation_xml_spec.rb @@ -1942,49 +1942,6 @@ .to be_equivalent_to xmlpp(presxml) end - it "processes ruby markup" do - input = <<~INPUT - - - -

- 東京 - 東京 - 東京 - 親友 - - - - - の方角 - - ! - !

-

-
- INPUT - presxml = <<~OUTPUT - - Table of contents - -

- 東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōtouとうnanなん の方角 - とうなんたつみ - まもプロテゴ! - まもプロテゴ!

-

-
-
-
- OUTPUT - expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert - .new(presxml_options.merge(output_formats: { html: "html", doc: "doc" })) - .convert("test", input, true)) - .sub(%r{.*}m, "") - .sub(%r{.*}m, ""))) - .to be_equivalent_to xmlpp(presxml) - end - private def mock_symbols From a7459c07522b7d7b7fa26304c723002436c7b073 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 18 Dec 2023 23:18:04 +1100 Subject: [PATCH 3/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/base_style/reset.scss | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/isodoc/base_style/reset.scss b/lib/isodoc/base_style/reset.scss index 99162520..d63f0c4e 100644 --- a/lib/isodoc/base_style/reset.scss +++ b/lib/isodoc/base_style/reset.scss @@ -163,6 +163,9 @@ a.FootnoteRef, span.FootnoteRef { text-decoration: line-through; } +ruby { ruby-position: over; } +ruby ruby { ruby-position: under; } + /* code highlighting with line numbers */ table.rouge-line-table td.rouge-gutter { From 94e5bc35e0a9d00804ad65ddb5a07d7e01013800 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 18 Dec 2023 23:22:35 +1100 Subject: [PATCH 4/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/base_style/reset.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/isodoc/base_style/reset.scss b/lib/isodoc/base_style/reset.scss index d63f0c4e..141119ed 100644 --- a/lib/isodoc/base_style/reset.scss +++ b/lib/isodoc/base_style/reset.scss @@ -163,8 +163,8 @@ a.FootnoteRef, span.FootnoteRef { text-decoration: line-through; } -ruby { ruby-position: over; } -ruby ruby { ruby-position: under; } +ruby { ruby-position: over; -webkit-ruby-position: over;} +ruby ruby { ruby-position: under; -webkit-ruby-position: under; } /* code highlighting with line numbers */ From 26d8fd91ca18be34a438f1f82666b467fb6ecdd7 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 18 Dec 2023 23:24:47 +1100 Subject: [PATCH 5/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/base_style/reset.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/isodoc/base_style/reset.scss b/lib/isodoc/base_style/reset.scss index 141119ed..a4161c0a 100644 --- a/lib/isodoc/base_style/reset.scss +++ b/lib/isodoc/base_style/reset.scss @@ -163,8 +163,8 @@ a.FootnoteRef, span.FootnoteRef { text-decoration: line-through; } -ruby { ruby-position: over; -webkit-ruby-position: over;} -ruby ruby { ruby-position: under; -webkit-ruby-position: under; } +ruby { ruby-position: over; -webkit-ruby-position: before;} +ruby ruby { ruby-position: under; -webkit-ruby-position: after; } /* code highlighting with line numbers */ From 0b50f31c6d13c2a4a2cad8f2757c9220f7a14bae Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Mon, 18 Dec 2023 23:58:21 +1100 Subject: [PATCH 6/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/word_function/inline.rb | 37 ++++++++++++++++++++++++++---- spec/isodoc/inline_spec.rb | 15 ++++++++++-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/isodoc/word_function/inline.rb b/lib/isodoc/word_function/inline.rb index 01153d78..1899c1b0 100644 --- a/lib/isodoc/word_function/inline.rb +++ b/lib/isodoc/word_function/inline.rb @@ -42,6 +42,15 @@ def imgsrc(node) end def image_parse(node, out, caption) + emf_attributes(node) + attrs = { src: imgsrc(node), + height: node["height"], alt: node["alt"], + title: node["title"], width: node["width"] } + out.img **attr_code(attrs) + image_title_parse(out, caption) + end + + def emf_attributes(node) if emf = node.at(ns("./emf")) node["src"] = emf["src"] node["height"] ||= emf["height"] @@ -49,11 +58,6 @@ def image_parse(node, out, caption) node["mimetype"] = "image/x-emf" node.children.remove end - attrs = { src: imgsrc(node), - height: node["height"], alt: node["alt"], - title: node["title"], width: node["width"] } - out.img **attr_code(attrs) - image_title_parse(out, caption) end def xref_parse(node, out) @@ -73,6 +77,29 @@ def suffix_url(url) url.sub(/#{File.extname(url)}$/, ".doc") end + + def ruby_parse(node, out) + if r = node.at(ns("./rb[ruby]")) + double_ruby = r.at(ns("./ruby/rt")).remove + r.replace(r.at(ns("./ruby/rb"))) + end + out.ruby do |e| + node.children.each { |n| parse(n, e) } + end + double_ruby and out << "(#{double_ruby.text})" + end + + def rt_parse(node, out) + out.rt do |e| + node.children.each { |n| parse(n, e) } + end + end + + def rb_parse(node, out) + out.rb do |e| + node.children.each { |n| parse(n, e) } + end + end end end end diff --git a/spec/isodoc/inline_spec.rb b/spec/isodoc/inline_spec.rb index 9ad0452c..46a13426 100644 --- a/spec/isodoc/inline_spec.rb +++ b/spec/isodoc/inline_spec.rb @@ -1979,7 +1979,6 @@ .convert("test", input, true))).to be_equivalent_to xmlpp(output) end - it "processes ruby markup" do input = <<~INPUT @@ -2029,6 +2028,15 @@ OUTPUT + doc = <<~OUTPUT +
+

Foreword

+

東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōとう(tou)なん(nan) の方角 + たつみ(とう) + プロテゴ(まも)! + プロテゴ(まも)!

+
+ OUTPUT expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert .new(presxml_options.merge(output_formats: { html: "html", doc: "doc" })) .convert("test", input, true)) @@ -2037,6 +2045,9 @@ .to be_equivalent_to xmlpp(presxml) expect(xmlpp(IsoDoc::HtmlConvert.new({}) .convert("test", presxml, true))).to be_equivalent_to xmlpp(html) + expect(xmlpp(IsoDoc::WordConvert.new({}) + .convert("test", presxml, true) + .sub(/^.*

.*$}m, ""))) + .to be_equivalent_to xmlpp(doc) end - end From 38299ad8b2a067c5ab3ae904c16264848c13f19c Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Tue, 19 Dec 2023 00:12:16 +1100 Subject: [PATCH 7/8] Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 --- lib/isodoc/word_function/inline.rb | 8 +------- spec/isodoc/inline_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/isodoc/word_function/inline.rb b/lib/isodoc/word_function/inline.rb index 1899c1b0..b232b77c 100644 --- a/lib/isodoc/word_function/inline.rb +++ b/lib/isodoc/word_function/inline.rb @@ -90,13 +90,7 @@ def ruby_parse(node, out) end def rt_parse(node, out) - out.rt do |e| - node.children.each { |n| parse(n, e) } - end - end - - def rb_parse(node, out) - out.rb do |e| + out.rt **{ style: "font-size: 6pt;" } do |e| node.children.each { |n| parse(n, e) } end end diff --git a/spec/isodoc/inline_spec.rb b/spec/isodoc/inline_spec.rb index 46a13426..52fac4d1 100644 --- a/spec/isodoc/inline_spec.rb +++ b/spec/isodoc/inline_spec.rb @@ -2029,13 +2029,13 @@ OUTPUT doc = <<~OUTPUT -
-

Foreword

-

東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōとう(tou)なん(nan) の方角 - たつみ(とう) - プロテゴ(まも)! - プロテゴ(まも)!

-
+
+

Foreword

+

東京とうきょう東京とうきょう東京Tōkyō親友ライバルとうきょうkyōとう(tou)なん(nan) の方角 + たつみ(とう) + プロテゴ(まも)! + プロテゴ(まも)!

+
OUTPUT expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert .new(presxml_options.merge(output_formats: { html: "html", doc: "doc" })) From 08f0d1077f0fad38e931ab4c97ae287cb4a02ef2 Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Tue, 19 Dec 2023 00:28:40 +1100 Subject: [PATCH 8/8] rspec --- spec/isodoc/metadata_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/isodoc/metadata_spec.rb b/spec/isodoc/metadata_spec.rb index fc81c752..2a931906 100644 --- a/spec/isodoc/metadata_spec.rb +++ b/spec/isodoc/metadata_spec.rb @@ -35,6 +35,9 @@ 2021 2022 2023 + 2024 + 2025 + 2026 2second edition 2016-05-01 @@ -129,7 +132,9 @@ output = <<~OUTPUT {:accesseddate=>"2012", :activateddate=>"2013", + :adapteddate=>"2024", :agency=>"ISO", + :announceddate=>"2025", :authors=>["Barney Rubble", "Fred Flintstone", "B. B. Rubble"], :authors_affiliations=>{"Chief Engineer, Slate Inc., Hermeneutics Unit, Exegesis Subunit, Bedrock"=>["Barney Rubble"], ""=>["Fred Flintstone", "B. B. Rubble"]}, :circulateddate=>"2015", @@ -165,6 +170,7 @@ :revdate=>"2016-05-01", :revdate_monthyear=>"May 2016", :script=>"Latn", + :stable_untildate=>"2026", :stage=>"Committee Draft", :stage_display=>"Committee Draft", :stageabbr=>"CD", @@ -262,7 +268,9 @@ INPUT output = <<~OUTPUT {:accesseddate=>"XXX", + :adapteddate=>"XXX", :agency=>"ISO/IEC/IEEE", + :announceddate=>"XXX", :circulateddate=>"XXX", :confirmeddate=>"XXX", :copieddate=>"XXX", @@ -294,6 +302,7 @@ :revdate=>"2016-05", :revdate_monthyear=>"May 2016", :script=>"Latn", + :stable_untildate=>"XXX", :stage=>"Published", :stage_display=>"Published", :subdivision=>"Subdivision", @@ -336,7 +345,9 @@ INPUT output = <<~OUTPUT {:accesseddate=>"XXX", + :adapteddate=>"XXX", :agency=>"NAME1/NAME", + :announceddate=>"XXX", :circulateddate=>"XXX", :confirmeddate=>"XXX", :copieddate=>"XXX", @@ -350,6 +361,7 @@ :publisher=>"NAME1 and NAME", :receiveddate=>"XXX", :script=>"Latn", + :stable_untildate=>"XXX", :transmitteddate=>"XXX", :unchangeddate=>"XXX", :unpublished=>true, @@ -440,7 +452,9 @@ INPUT output = <<~OUTPUT {:accesseddate=>"XXX", + :adapteddate=>"XXX", :agency=>"ISO/IEC", + :announceddate=>"XXX", :circulateddate=>"XXX", :confirmeddate=>"XXX", :copieddate=>"XXX", @@ -463,6 +477,7 @@ :revdate=>"2016-05", :revdate_monthyear=>"Mai 2016", :script=>"Latn", + :stable_untildate=>"XXX", :stage=>"Committee Draft", :stage_display=>"Projet De Comité", :stageabbr=>"CD",