Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Dec 18, 2023
1 parent 26d8fd9 commit 0b50f31
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
37 changes: 32 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,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
15 changes: 13 additions & 2 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,6 @@
.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">
Expand Down Expand Up @@ -2029,6 +2028,15 @@
</body>
</html>
OUTPUT
doc = <<~OUTPUT
<div>
<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>東</rb><rt>とう</rt></ruby>(tou)<ruby><rb>南</rb><rt>なん</rt></ruby>(nan) の方角
<ruby><rb>東</rb><rt>たつみ</rt></ruby>(とう)
<ruby><rb>護</rb><rt>プロテゴ</rt></ruby>(まも)!
<ruby><rb>護</rb><rt>プロテゴ</rt></ruby>(まも)!</p>
</div>
OUTPUT
expect(xmlpp(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options.merge(output_formats: { html: "html", doc: "doc" }))
.convert("test", input, true))
Expand All @@ -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(/^.*<h1/m, "<div><h1").sub(%r{</div>.*$}m, "</div>")))
.to be_equivalent_to xmlpp(doc)
end

end

0 comments on commit 0b50f31

Please sign in to comment.