Skip to content

Commit

Permalink
fixed table merged cells, better support for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
ottoville committed Feb 9, 2016
1 parent dd8321b commit e1d3ab3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
8 changes: 6 additions & 2 deletions docx2html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,12 @@
var tabinterval=parseFloat(tabs[t].style.minWidth);
var realwidth=parseFloat(window.getComputedStyle(tabs[t]).width)
if(realwidth>tabinterval) {
tabs[t].style.width=Math.ceil(realwidth/tabinterval)*tabinterval+'px';
}
var tabnumber=Math.ceil(realwidth/tabinterval);
for(tt=tabnumber-1,next=tabs[t].nextSibling; tt>0&&next&&next.classList.contains('tab')&&!next.firstChild ;next=next.nextSibling,tt--) {
next.parentNode.removeChild(next);
}
tabs[t].style.width=tabnumber*tabinterval+'px';
}
}
]]>
</xsl:text>
Expand Down
11 changes: 7 additions & 4 deletions table.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
<td>
<!-- Check if cell will span multiple cells -->
<xsl:if test="w:tcPr/w:vMerge[@w:val='restart']">
<xsl:attribute name="rowspan">
<xsl:value-of select="count(../following-sibling::w:tr/w:tc/w:tcPr/w:vMerge)+1"/>
</xsl:attribute>
<!-- Calculate cell index with combined cells -->
<xsl:variable name="celindex" select="count(current()/preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])+sum(current()/preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val)" />
<!-- How many combined rows have so far -->
<xsl:variable name="restartindex" select="count(current()/../preceding-sibling::w:tr/w:tc[count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])+sum(current()/../preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val)=$celindex]/w:tcPr/w:vMerge[@w:val='restart'])" />
<!-- Apply rowspan attribute -->
<xsl:attribute name="rowspan" select="count(current()/../following-sibling::w:tr/w:tc[count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])+sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val)=$celindex][count(../preceding-sibling::w:tr/w:tc[count(preceding-sibling::w:tc[not(w:tcPr/w:gridSpan)])+sum(preceding-sibling::w:tc/w:tcPr/w:gridSpan/@w:val)=$celindex]/w:tcPr/w:vMerge[@w:val='restart'])=$restartindex+1]/w:tcPr/w:vMerge[not(@w:val='restart')])+1" />
</xsl:if>
<xsl:if test="w:tcPr/w:gridSpan">
<xsl:attribute name="colspan"><xsl:value-of select="w:tcPr/w:gridSpan/@w:val"/></xsl:attribute>
<xsl:attribute name="colspan" select="w:tcPr/w:gridSpan/@w:val" />
</xsl:if>
<xsl:apply-templates select="w:tcPr|w:p|w:sdt">
<xsl:with-param name="reldocument" select="$reldocument" />
Expand Down
22 changes: 12 additions & 10 deletions text.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,18 @@
<xsl:value-of select="concat(' ',../../w:pPr/w:rPr/w:rStyle/@w:val)"/>
</xsl:if>
</xsl:variable>
<span>
<xsl:attribute name="class" select="normalize-space($class)"/>
<xsl:attribute name="style">
<xsl:apply-templates select="w:rPr"/>
</xsl:attribute>
<xsl:apply-templates select="w:t|w:pict|w:drawing|mc:AlternateContent">
<xsl:with-param name="reldocument" select="$reldocument" />
<xsl:with-param name="themefile" select="$themefile" />
</xsl:apply-templates>
</span>
<xsl:if test="w:t|w:pict|w:drawing|mc:AlternateContent">
<span>
<xsl:attribute name="class" select="normalize-space($class)"/>
<xsl:attribute name="style">
<xsl:apply-templates select="w:rPr"/>
</xsl:attribute>
<xsl:apply-templates select="w:t|w:pict|w:drawing|mc:AlternateContent">
<xsl:with-param name="reldocument" select="$reldocument" />
<xsl:with-param name="themefile" select="$themefile" />
</xsl:apply-templates>
</span>
</xsl:if>
</xsl:template>
<xsl:template match="w:r[w:fldChar[@w:fldCharType='begin']]">
<xsl:param name="reldocument" />
Expand Down

0 comments on commit e1d3ab3

Please sign in to comment.