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}")
+ 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
+
+
+ 東京東京東京親友東京東京東南 の方角
+ 東南
+ 護れ!
+ れ護!
+
+
+
+
+ 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
+
+
+ 東京東京東京親友東京東京東南 の方角
+ 東南
+ 護れ!
+ れ護!
+
+
+
+
+ OUTPUT
+ html = <<~OUTPUT
+ #{HTML_HDR}
+
+
+
Foreword
+
東京東京東京親友東京東京東南 の方角
+ 東南
+ 護れ!
+ れ護!
+
+
+