Skip to content

Commit

Permalink
introduce -e for evolve-hub customization, transpect/docx2hub#25
Browse files Browse the repository at this point in the history
  • Loading branch information
gimsieke committed Jun 13, 2021
1 parent e747e6d commit fd5113f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
15 changes: 13 additions & 2 deletions d2t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ usage() {
echo " -r omit page and cross-references and labels"
echo " -t choose table model (tabularx|tabular|htmltabs)"
echo " -l suppress table grid lines"
echo " -x custom XSLT stylesheet for Hub processing"
echo " -x custom XSLT stylesheet for Hub processing (after evolve-hub)"
echo " -e custom XSLT stylesheet for evolve-hub (should import xsl/evolve-hub-driver.xsl)"
echo " -d debug mode"
echo " -h heap (main memory) that Java is allowed to use (for ex., 4096m)"
1>&2; exit 1;
Expand Down Expand Up @@ -56,7 +57,7 @@ REFS=yes
DEBUG=no

# specify options
while getopts ":o:c:m:t:x:plrdh:" opt; do
while getopts ":o:c:m:t:x:e:plrdh:" opt; do
case "${opt}" in
o)
OUT_DIR=${OPTARG}
Expand All @@ -70,6 +71,9 @@ while getopts ":o:c:m:t:x:plrdh:" opt; do
x)
CUSTOMXSL=${OPTARG}
;;
e)
CUSTOMDRIVER=${OPTARG}
;;
t)
TABLEMODEL=${OPTARG}
;;
Expand Down Expand Up @@ -104,6 +108,11 @@ if [ -z "$1" ]; then
usage
fi

# custom evolve-hub driver given (as URI, may also be relative to this directory)
if ! [ -z "$CUSTOMDRIVER" ]; then
INPUTCUSTOMDRIVER="-i custom-evolve-hub-driver=$CUSTOMDRIVER"
fi

# file as 1st argument
FILE="$1"
if ! [[ $FILE =~ \.docx$ ]]; then
Expand Down Expand Up @@ -193,13 +202,15 @@ if [ "$DEBUG" = "yes" ]; then
echo " refs and labels: $REFS"
echo " table model: $TABLEMODEL"
echo " draw table grid lines: $TABLEGRID"
echo " custom evolve-hub: $INPUTCUSTOMDRIVER"
echo " custom xslt: $CUSTOMXSL"
echo " Java heap: $HEAP"
echo ""
fi

# docx2tex xproc pipeline
HEAP=$HEAP $CALABASH \
$INPUTCUSTOMDRIVER \
-o result="$OUT_DIR_PSEUDOURI/$BASENAME.tex" \
-o hub="$OUT_DIR_PSEUDOURI/$BASENAME.xml" \
"$DIR/xpl/docx2tex.xpl" \
Expand Down
2 changes: 1 addition & 1 deletion xmlcatalog/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<nextCatalog catalog="../schema/hub/xmlcatalog/catalog.xml"/>

<rewriteURI uriStartString="http:https://transpect.io/docx2tex/" rewritePrefix="../"/>
<rewriteURI uriStartString="http:https://customers.le-tex.de/generic/book-conversion/" rewritePrefix="../"/>
<rewriteURI uriStartString="http:https://this.transpect.io/" rewritePrefix="../"/>

<nextCatalog catalog="../cascade/xmlcatalog/catalog.xml"/>

Expand Down
9 changes: 7 additions & 2 deletions xpl/docx2tex.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
Provide a custom evolve-hub driver stylesheet if you like. I would strongly advise to
import the standard evolve-hub-driver in ../xsl/evolve-hub-driver.xsl as it brings many
improvements for the subsequent processing.
There is a sample customization, xsl/custom-evolve-hub-driver-example.xsl, that treats
every empty paragraph as a Heading1, that is, a \chapter{} in the generated LaTeX file.
</p:documentation>
</p:input>

Expand Down Expand Up @@ -296,10 +298,13 @@
* -->
<p:choose name="custom-xsl">
<p:when test="$custom-xsl ne ''">
<tr:file-uri name="custom-xsl-uri">
<p:with-option name="filename" select="$custom-xsl"/>
</tr:file-uri>
<p:load name="load-custom-xsl">
<p:with-option name="href" select="$custom-xsl"/>
<p:with-option name="href" select="/*/@local-href"/>
</p:load>
<p:xslt>
<p:xslt name="apply-custom-xsl">
<p:input port="parameters">
<p:empty/>
</p:input>
Expand Down
20 changes: 20 additions & 0 deletions xsl/custom-evolve-hub-driver-example.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http:https://www.w3.org/1999/XSL/Transform"
xmlns:css="http:https://www.w3.org/1996/css"
xmlns:docx2tex="http:https://transpect.io/docx2tex"
xmlns:xs="http:https://www.w3.org/2001/XMLSchema"
xmlns="http:https://docbook.org/ns/docbook"
version="3.0"
exclude-result-prefixes="#all"
xpath-default-namespace="http:https://docbook.org/ns/docbook">

<xsl:import href="http:https://transpect.io/docx2tex/xsl/evolve-hub-driver.xsl"/>

<xsl:template match="para[empty(node())]" mode="docx2tex-preprocess">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="role" select="'Heading1'"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

0 comments on commit fd5113f

Please sign in to comment.