Skip to content

Commit

Permalink
https://github.com/metanorma/metanorma-ieee/issues/4
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Oct 8, 2023
1 parent 993742e commit 9f31b5f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/isodoc/ieee/word_wp_cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def toWord(result, filename, dir, header)

def table_cleanup(docxml)
super
docxml.xpath("//div[@class = 'table_container']//p[@class = 'Note']")
docxml.xpath("//div[@class = 'table_container']//div[@class = 'Note']//p")
.each do |n|
n["class"] = "Tablenotes"
end
Expand Down
94 changes: 93 additions & 1 deletion spec/isodoc/word_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,99 @@
.to be_equivalent_to xmlpp(output)
end

it "process tables" do
input = <<~INPUT
<iso-standard xmlns='http://riboseinc.com/isoxml' type="presentation">
<bibdata><ext><doctype>standard</doctype></ext></bibdata>
<sections>
<clause id="a" displayorder="1">
<table id="figureA-1" keep-with-next="true" keep-lines-together="true">
<name>Figure 1&#xA0;&#x2014; Split-it-right <em>sample</em> divider<fn reference="1"><p>X</p></fn></name>
<thead><tr><th>A</th></tr></thead>
<tbody><tr><td>B</td></tr></tbody>
<note id="A"><p>This is a note</p></note>
</table>
</clause>
</sections>
</iso-standard>
INPUT
output = <<~OUTPUT
<div>
<a name="a" id="a"/>
<p class="IEEEStdsLevel1Header"/>
<p class="IEEEStdsRegularTableCaption" style="text-align:center;">Figure 1 — Split-it-right <i>sample</i> divider<span style="mso-bookmark:_Ref"><a class="FootnoteRef" href="#_ftn1" type="footnote" style="mso-footnote-id:ftn1" name="_" title="" id="_"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"/></span></a></span></p>
<div align="center" class="table_container">
<table class="MsoISOTable" style="mso-table-anchor-horizontal:column;mso-table-overlap:never;border-spacing:0;border-width:1px;page-break-after: avoid;page-break-inside: avoid;">
<a name="figureA-1" id="figureA-1"/>
<thead>
<tr>
<th style="font-weight:bold;border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;mso-border-bottom-alt:solid windowtext 1.5pt;page-break-after:avoid;">
<p class="IEEEStdsTableColumnHead" style="page-break-after:avoid">A</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;mso-border-bottom-alt:solid windowtext 1.5pt;page-break-after:auto;">
<p class="IEEEStdsTableData-Left" style="page-break-after:auto">B</p>
</td>
</tr>
</tbody>
<div>
<a name="A" id="A"/>
<p class="IEEEStdsParagraph">This is a note</p>
</div>
</table>
</div>
</div>
OUTPUT
IsoDoc::IEEE::WordConvert.new({}).convert("test", input, false)
expect(File.exist?("test.doc")).to be true
doc = Nokogiri::XML(word2xml("test.doc"))
.at("//xmlns:div[xmlns:a[@id = 'a']]")
expect(strip_guid(xmlpp(doc.to_xml)))
.to be_equivalent_to xmlpp(output)

output = <<~OUTPUT
<div>
<a name="a" id="a"/>
<p class="IEEESectionHeader"/>
<p class="TableTitles" style="text-align:center;">Figure 1 — Split-it-right <i>sample</i> divider<span style="mso-bookmark:_Ref"><a class="FootnoteRef" href="#_ftn1" type="footnote" style="mso-footnote-id:ftn1" name="_" title="" id="_"><span class="MsoFootnoteReference"><span style="mso-special-character:footnote"/></span></a></span></p>
<div align="center" class="table_container">
<table class="MsoISOTable" style="mso-table-anchor-horizontal:column;mso-table-overlap:never;border-spacing:0;border-width:1px;page-break-after: avoid;page-break-inside: avoid;">
<a name="figureA-1" id="figureA-1"/>
<thead>
<tr>
<th style="font-weight:bold;border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;mso-border-bottom-alt:solid windowtext 1.5pt;page-break-after:avoid;">
<p class="Tablecolumnheader" style="page-break-after:avoid">A</p>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-top:solid windowtext 1.5pt;mso-border-top-alt:solid windowtext 1.5pt;border-bottom:solid windowtext 1.5pt;mso-border-bottom-alt:solid windowtext 1.5pt;page-break-after:auto;">
<p class="Tablecelltext" style="page-break-after:auto">B</p>
</td>
</tr>
</tbody>
<div class="Note">
<a name="A" id="A"/>
<p class="Tablenotes">This is a note</p>
</div>
</table>
</div>
</div>
OUTPUT
IsoDoc::IEEE::WordConvert.new({})
.convert("test", input.sub("<doctype>standard</doctype>",
"<doctype>whitepaper</doctype>"), false)
expect(File.exist?("test.doc")).to be true
doc = Nokogiri::XML(word2xml("test.doc"))
.at("//xmlns:div[xmlns:a[@id = 'a']]")
expect(strip_guid(xmlpp(doc.to_xml)))
.to be_equivalent_to xmlpp(output)
end

it "process clause" do
input = <<~INPUT
<iso-standard xmlns='http://riboseinc.com/isoxml' type="presentation">
Expand Down Expand Up @@ -931,7 +1024,6 @@
.to be_equivalent_to xmlpp(word)
end


it "process annex" do
input = <<~INPUT
<iso-standard xmlns='http://riboseinc.com/isoxml' type="presentation">
Expand Down

0 comments on commit 9f31b5f

Please sign in to comment.