Use pandoc templates to set root element, xml:id, and default title

Change-Id: I9d4217bb977401a2abd678835f4fbbd842a05a8c
This commit is contained in:
dcramer 2014-02-21 12:59:09 -06:00 committed by Andreas Jaeger
parent fc6ea69f1c
commit 8e8c9108cc
2 changed files with 40 additions and 4 deletions

View File

@ -9,6 +9,23 @@
BRANCH=$ZUUL_REFNAME
shopt -s extglob
# This function figures out the location of the original script (as opposed to any chain of
# symlinks pointing to it). Source:
# http://muffinresearch.co.uk/archives/2008/10/10/bash-resolving-symlinks-to-shellscripts/
function resolve_symlink {
SCRIPT=$1 NEWSCRIPT=''
until [ "$SCRIPT" = "$NEWSCRIPT" ]; do
if [ "${SCRIPT:0:1}" = '.' ]; then SCRIPT=$PWD/$SCRIPT; fi
cd $(dirname $SCRIPT)
if [ ! "${SCRIPT:0:1}" = '.' ]; then SCRIPT=$(basename $SCRIPT); fi
SCRIPT=${NEWSCRIPT:=$SCRIPT}
NEWSCRIPT=$(ls -l $SCRIPT | awk '{ print $NF }')
done
if [ ! "${SCRIPT:0:1}" = '/' ]; then SCRIPT=$PWD/$SCRIPT; fi
echo $(dirname $SCRIPT)
}
DIR=$(resolve_symlink $0)
# Find location of db4-upgrade-xsl:
if [ -e /usr/share/xml/docbook/stylesheet/docbook5/db4-upgrade.xsl ] ; then
DB_UPGRADE=/usr/share/xml/docbook/stylesheet/docbook5/db4-upgrade.xsl
@ -33,10 +50,8 @@ type -P pandoc > /dev/null 2>&1 || { echo >&2 "pandoc not installed. Aborting."
type -P xsltproc > /dev/null 2>&1 || { echo >&2 "xsltproc not installed. Aborting."; exit 1; }
type -P xmllint > /dev/null 2>&1 || { echo >&2 "xmllint not installed. Aborting."; exit 1; }
pandoc -f markdown -t docbook -s ${SOURCES} |\
pandoc -V xmlid=$FILENAME --template=$DIR/pandoc-template.docbook -f markdown -t docbook -s ${SOURCES} |\
xsltproc -o - ${DB_UPGRADE} - |\
xmllint --format - | \
sed -e "s,<article,<chapter xml:id=\"$FILENAME\"," | \
sed -e 's,</article>,</chapter>,' > ${DIRPATH}/$FILENAME.xml
xmllint --format - > ${DIRPATH}/$FILENAME.xml
pwd

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<chapter id="$xmlid$">
<chapterinfo>
<title>$if(title)$ $title$ $else$NO TITLE$endif$</title>
$for(author)$
<author>
$author$
</author>
$endfor$
$if(date)$
<date>$date$</date>
$endif$
</chapterinfo>
$for(include-before)$
$include-before$
$endfor$
$body$
$for(include-after)$
$include-after$
$endfor$
</chapter>