Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated ruby: https://github.com/metanorma/metanorma-standoc/issues/73 #555

Merged
merged 8 commits into from
Dec 18, 2023
3 changes: 3 additions & 0 deletions lib/isodoc/base_style/reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions lib/isodoc/function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions lib/isodoc/function/to_word_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/isodoc/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ 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,
draftinfo(get[:draft], get[:revdate]))
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

Expand Down
16 changes: 16 additions & 0 deletions lib/isodoc/presentation_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ruby><rb>#{t}</rb><rt>#{v['value']}</rt></ruby>")
end

private

def found_matching_variant_sibling(node)
Expand Down
1 change: 1 addition & 0 deletions lib/isodoc/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def inline(docxml)
quotesource docxml # feeds docxml
eref2link docxml
mathml docxml
ruby docxml
variant docxml
identifier docxml
date docxml
Expand Down
31 changes: 26 additions & 5 deletions lib/isodoc/word_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ 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"]
node["width"] ||= emf["width"]
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)
Expand All @@ -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
72 changes: 72 additions & 0 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="semantic">
<preface>
<foreword id="A">
<p>
<ruby><pronunciation value="とうきょう"/>東京</ruby>
<ruby><pronunciation value="とうきょう" lang="ja" script="Hira"/>東京</ruby>
<ruby><pronunciation value="Tōkyō" script="Latn"/>東京</ruby>
<ruby><annotation value="ライバル"/>親友</ruby>
<ruby><pronunciation value="とう"/>東</ruby> <ruby><pronunciation value="きょう"/>京</ruby>
<ruby><pronunciation value="Tō" script="Latn"/>東</ruby><ruby><pronunciation value="kyō" script="Latn"/>京</ruby>


<ruby><pronunciation value="とう"/><ruby><pronunciation value="tou"/>東</ruby></ruby> <ruby><pronunciation value="なん"/><ruby><pronunciation value="nan"/>南</ruby></ruby> の方角
<ruby><pronunciation value="たつみ"/><ruby><pronunciation value="とう"/>東</ruby><ruby><pronunciation value="なん"/>南</ruby></ruby>
<ruby><pronunciation value="プロテゴ"/><ruby><pronunciation value="まも"/>護</ruby>れ</ruby>!
<ruby><pronunciation value="プロテゴ"/>れ<ruby><pronunciation value="まも"/>護</ruby></ruby>!</p>
</p>
</foreword></preface></standard-document>
INPUT
presxml = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
<preface><clause type="toc" id="_" displayorder="1"><title depth="1">Table of contents</title></clause>
<foreword id="A" displayorder="2">
<p>
<ruby><rb>東京</rb><rt>とうきょう</rt></ruby><ruby><rb>東京</rb><rt>とうきょう</rt></ruby><ruby><rb>東京</rb><rt>Tōkyō</rt></ruby><ruby><rb>親友</rb><rt>ライバル</rt></ruby><ruby><rb>東</rb><rt>とう</rt></ruby><ruby><rb>京</rb><rt>きょう</rt></ruby><ruby><rb>東</rb><rt>Tō</rt></ruby><ruby><rb>京</rb><rt>kyō</rt></ruby><ruby><rb><ruby><rb>東</rb><rt>tou</rt></ruby></rb><rt>とう</rt></ruby><ruby><rb><ruby><rb>南</rb><rt>nan</rt></ruby></rb><rt>なん</rt></ruby> の方角
<ruby><rb><ruby><rb>東</rb><rt>とう</rt></ruby><ruby><rb>南</rb><rt>なん</rt></ruby></rb><rt>たつみ</rt></ruby>
<ruby><rb><ruby><rb>護</rb><rt>まも</rt></ruby>れ</rb><rt>プロテゴ</rt></ruby>!
<ruby><rb>れ<ruby><rb>護</rb><rt>まも</rt></ruby></rb><rt>プロテゴ</rt></ruby>!</p>
</p>
</foreword>
</preface>
</standard-document>
OUTPUT
html = <<~OUTPUT
#{HTML_HDR}
<br/>
<div id="A">
<h1 class="ForewordTitle">Foreword</h1>
<p><ruby><rb>東京</rb><rt>とうきょう</rt></ruby><ruby><rb>東京</rb><rt>とうきょう</rt></ruby><ruby><rb>東京</rb><rt>Tōkyō</rt></ruby><ruby><rb>親友</rb><rt>ライバル</rt></ruby><ruby><rb>東</rb><rt>とう</rt></ruby><ruby><rb>京</rb><rt>きょう</rt></ruby><ruby><rb>東</rb><rt>Tō</rt></ruby><ruby><rb>京</rb><rt>kyō</rt></ruby><ruby><rb><ruby><rb>東</rb><rt>tou</rt></ruby></rb><rt>とう</rt></ruby><ruby><rb><ruby><rb>南</rb><rt>nan</rt></ruby></rb><rt>なん</rt></ruby> の方角
<ruby><rb><ruby><rb>東</rb><rt>とう</rt></ruby><ruby><rb>南</rb><rt>なん</rt></ruby></rb><rt>たつみ</rt></ruby>
<ruby><rb><ruby><rb>護</rb><rt>まも</rt></ruby>れ</rb><rt>プロテゴ</rt></ruby>!
<ruby><rb>れ<ruby><rb>護</rb><rt>まも</rt></ruby></rb><rt>プロテゴ</rt></ruby>!</p>
</div>
</div>
</body>
</html>
OUTPUT
doc = <<~OUTPUT
<div>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a heredoc.

<h1 class="ForewordTitle">Foreword</h1>
<p><ruby><rb>東京</rb><rt style="font-size: 6pt;">とうきょう</rt></ruby><ruby><rb>東京</rb><rt style="font-size: 6pt;">とうきょう</rt></ruby><ruby><rb>東京</rb><rt style="font-size: 6pt;">Tōkyō</rt></ruby><ruby><rb>親友</rb><rt style="font-size: 6pt;">ライバル</rt></ruby><ruby><rb>東</rb><rt style="font-size: 6pt;">とう</rt></ruby><ruby><rb>京</rb><rt style="font-size: 6pt;">きょう</rt></ruby><ruby><rb>東</rb><rt style="font-size: 6pt;">Tō</rt></ruby><ruby><rb>京</rb><rt style="font-size: 6pt;">kyō</rt></ruby><ruby><rb>東</rb><rt style="font-size: 6pt;">とう</rt></ruby>(tou)<ruby><rb>南</rb><rt style="font-size: 6pt;">なん</rt></ruby>(nan) の方角
<ruby><rb>東</rb><rt style="font-size: 6pt;">たつみ</rt></ruby>(とう)
<ruby><rb>護</rb><rt style="font-size: 6pt;">プロテゴ</rt></ruby>(まも)!
<ruby><rb>護</rb><rt style="font-size: 6pt;">プロテゴ</rt></ruby>(まも)!</p>
</div>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

OUTPUT
expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html", doc: "doc" }))
.convert("test", input, true))
.sub(%r{<metanorma-extension>.*</metanorma-extension>}m, "")
.sub(%r{<localized-strings>.*</localized-strings>}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(/^.*<h1/m, "<div><h1").sub(%r{</div>.*$}m, "</div>")))
.to be_equivalent_to xmlpp(doc)
end
end
15 changes: 15 additions & 0 deletions spec/isodoc/metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<date type="vote-started"><on>2021</on></date>
<date type="vote-ended"><on>2022</on></date>
<date type="corrected"><on>2023</on></date>
<date type="adapted"><on>2024</on></date>
<date type="announced"><on>2025</on></date>
<date type="stable_until"><on>2026</on></date>
<edition>2</edition><edition language="en">second edition</edition>
<version>
<revision-date>2016-05-01</revision-date>
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -262,7 +268,9 @@
INPUT
output = <<~OUTPUT
{:accesseddate=>"XXX",
:adapteddate=>"XXX",
:agency=>"ISO/IEC/IEEE",
:announceddate=>"XXX",
:circulateddate=>"XXX",
:confirmeddate=>"XXX",
:copieddate=>"XXX",
Expand Down Expand Up @@ -294,6 +302,7 @@
:revdate=>"2016-05",
:revdate_monthyear=>"May 2016",
:script=>"Latn",
:stable_untildate=>"XXX",
:stage=>"Published",
:stage_display=>"Published",
:subdivision=>"Subdivision",
Expand Down Expand Up @@ -336,7 +345,9 @@
INPUT
output = <<~OUTPUT
{:accesseddate=>"XXX",
:adapteddate=>"XXX",
:agency=>"NAME1/NAME",
:announceddate=>"XXX",
:circulateddate=>"XXX",
:confirmeddate=>"XXX",
:copieddate=>"XXX",
Expand All @@ -350,6 +361,7 @@
:publisher=>"NAME1 and NAME",
:receiveddate=>"XXX",
:script=>"Latn",
:stable_untildate=>"XXX",
:transmitteddate=>"XXX",
:unchangeddate=>"XXX",
:unpublished=>true,
Expand Down Expand Up @@ -440,7 +452,9 @@
INPUT
output = <<~OUTPUT
{:accesseddate=>"XXX",
:adapteddate=>"XXX",
:agency=>"ISO/IEC",
:announceddate=>"XXX",
:circulateddate=>"XXX",
:confirmeddate=>"XXX",
:copieddate=>"XXX",
Expand All @@ -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",
Expand Down
14 changes: 6 additions & 8 deletions spec/isodoc/presentation_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1851,13 +1851,13 @@
</foreword></preface></standard-document>
INPUT
presxml = <<~OUTPUT
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
<presentation-metadata><custom-charset-font>weather:"OGC Weather Symbols",conscript:"Code 2000"</custom-charset-font></presentation-metadata>
<preface><clause type="toc" id="_" displayorder="1"><title depth="1">Table of contents</title></clause>
<standard-document xmlns="https://www.metanorma.org/ns/standoc" type="presentation">
<presentation-metadata><custom-charset-font>weather:"OGC Weather Symbols",conscript:"Code 2000"</custom-charset-font></presentation-metadata>
<preface><clause type="toc" id="_" displayorder="1"><title depth="1">Table of contents</title></clause>

<foreword id="A" displayorder="2">
<p id="_"><span custom-charset="weather" style=";font-family:&quot;OGC Weather Symbols&quot;">&#xFD80;</span></p>
</foreword></preface></standard-document>
<foreword id="A" displayorder="2">
<p id="_"><span custom-charset="weather" style=";font-family:&quot;OGC Weather Symbols&quot;">&#xFD80;</span></p>
</foreword></preface></standard-document>
OUTPUT
expect(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options)
Expand Down Expand Up @@ -1887,7 +1887,6 @@
<preprocess-xslt format="html">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
Expand All @@ -1906,7 +1905,6 @@
<preprocess-xslt format="doc">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
Expand Down
Loading