Commit 5d842bf2 authored by Wendell Piez's avatar Wendell Piez
Browse files

Bug fix with punctuation-sliding logic

parent 69704b49
......@@ -101,7 +101,7 @@
</splice>
<!-- Replace runs of multiple consecutive spaces with just one space-->
<match replace="&#x20;">{$space}+</match>
<!--<match replace="&#x20;">{$space}+</match>-->
<!-- omit whitespace around em dashes -->
<match replace="&#x2014;">\s*&#x2014;\s*</match>
......@@ -153,8 +153,15 @@
<xsl:template match="xsw:match">
<xsl:param name="str" required="yes" as="xs:string"/>
<xsl:message><xsl:value-of select="@replace"/></xsl:message>
<xsl:sequence select="replace($str,string(.),(@replace,'')[1])"/>
<!-- permits empty xsw:match as a no-op -->
<xsl:choose>
<xsl:when test="matches(.,'\S')">
<xsl:sequence select="replace($str,string(.),(@replace,'')[1])"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="$str"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="xsw:match[exists(@when-next)]">
......@@ -390,15 +397,20 @@
<!-- The operation to perform on this text node, if any, depends on what it is -->
<xsl:variable name="replacement" expand-text="true">
<!-- if not in an em, but following an em, we remove the initial punctuation... -->
<xsl:if test="empty($original/ancestor::em) and exists($prev/ancestor::em)">
<xsw:match>^{$puncts}</xsw:match>
</xsl:if>
<!-- if we are inside an 'em', we acquire following punctuation -->
<xsl:if test="exists($original/ancestor::em) and empty($next/ancestor::em)">
<xsl:variable name="p" select="replace($next, ('^(' || $puncts || ').*$'), '$1')"/>
<xsw:match replace="$1{$p}">(.)$</xsw:match>
</xsl:if>
<xsl:choose>
<!-- if not in an em, but following an em, we remove the initial punctuation... -->
<xsl:when test="empty($original/ancestor::em) and exists($prev/ancestor::em)">
<xsw:match>^{$puncts}</xsw:match>
</xsl:when>
<!-- if we are inside an 'em', we acquire following punctuation -->
<xsl:when test="exists($original/ancestor::em) and empty($next/ancestor::em)">
<xsl:variable name="p" select="replace($next, ('^(' || $puncts || ').*$'), '$1')"/>
<xsw:match replace="$1{$p}">(.)$</xsw:match>
</xsl:when>
<xsl:otherwise>
<xsw:match/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:apply-templates select="$replacement">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment