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: over;}
Copy link

Choose a reason for hiding this comment

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

Properties should be ordered -webkit-ruby-position, ruby-position

ruby ruby { ruby-position: under; -webkit-ruby-position: under; }
Copy link

Choose a reason for hiding this comment

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

Merge rule ruby ruby with rule on line 166
Properties should be ordered -webkit-ruby-position, ruby-position


/* 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
61 changes: 61 additions & 0 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<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
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)
end

end
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