diff --git a/lib/isodoc/base_style/reset.scss b/lib/isodoc/base_style/reset.scss index 99162520..a4161c0a 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; -webkit-ruby-position: before;} +ruby ruby { ruby-position: under; -webkit-ruby-position: after; } + /* code highlighting with line numbers */ table.rouge-line-table td.rouge-gutter { 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/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/lib/isodoc/word_function/inline.rb b/lib/isodoc/word_function/inline.rb index 01153d78..b232b77c 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,23 @@ 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 **{ style: "font-size: 6pt;" } 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 cdd26787..52fac4d1 100644 --- a/spec/isodoc/inline_spec.rb +++ b/spec/isodoc/inline_spec.rb @@ -1978,4 +1978,76 @@ 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 + 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)) + .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) + expect(xmlpp(IsoDoc::WordConvert.new({}) + .convert("test", presxml, true) + .sub(/^.*

.*$}m, ""))) + .to be_equivalent_to xmlpp(doc) + end end 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", diff --git a/spec/isodoc/presentation_xml_spec.rb b/spec/isodoc/presentation_xml_spec.rb index 3b08cd61..1cb93ce5 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 @@ -