Skip to content

Commit

Permalink
Adding support for colspan in tables (#52)
Browse files Browse the repository at this point in the history
Transformed into w:gridSpan
  • Loading branch information
filipkis authored and Lukas Alexandre committed Aug 25, 2017
1 parent 531d99b commit cc557cb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/htmltoword/xslt/tables.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<xsl:variable name="cell-bg" select="str:tokenize(substring-after(@class, 'ms-fill-'), ' ')[1]"/>
<w:shd w:val="clear" w:color="auto" w:fill="{$cell-bg}" />
</xsl:if>
<xsl:if test="@colspan &gt; 1">
<w:gridSpan w:val="{@colspan}"/>
</xsl:if>
</w:tcPr>
</xsl:template>

Expand Down
48 changes: 48 additions & 0 deletions spec/xslt_tables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,52 @@
EOL
compare_resulting_wordml_with_expected(html, expected_wordml.strip, extras: false)
end

it "transforms a colspan into a gridSpan table cell property" do
html = <<-EOL
<!DOCTYPE html>
<html>
<head></head>
<body>
<table>
<tbody>
<tr>
<td colspan='4'>Hello</td>
</tr>
</tbody>
</table>
</body>
</html>
EOL
expected_wordml = <<-EOL
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="5000" w:type="pct"/>
<w:tblBorders>
<w:top w:val="none" w:sz="0" w:space="0" w:color="auto"/>
<w:left w:val="none" w:sz="0" w:space="0" w:color="auto"/>
<w:bottom w:val="none" w:sz="0" w:space="0" w:color="auto"/>
<w:right w:val="none" w:sz="0" w:space="0" w:color="auto"/>
<w:insideH w:val="none" w:sz="0" w:space="0" w:color="auto"/>
<w:insideV w:val="none" w:sz="0" w:space="0" w:color="auto"/>
</w:tblBorders>
<w:tblLook w:val="0600" w:firstRow="0" w:lastRow="0" w:firstColumn="0" w:lastColumn="0" w:noHBand="1" w:noVBand="1"/>
</w:tblPr>
<w:tr>
<w:tc>
<w:tcPr>
<w:gridSpan w:val="4"/>
</w:tcPr>
<w:p>
<w:r>
<w:t xml:space="preserve">Hello</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
EOL
compare_resulting_wordml_with_expected(html, expected_wordml.strip)
end
end

0 comments on commit cc557cb

Please sign in to comment.