pandocで日本語epub

2010年8月3日

epub pandoc

t f B! P L
pandocでepubを作る時, metadata.xmlに言語を指定できるが, content.opfに書き込まれるだけで, 個々のxhtmlには言語は指定されない. このままだとAdobe Digital Editionsでは文字化けしてしまう. 横浜工文社のbatスクリプトを参考にpandocが生成したepubを解凍, xhtmlを編集, 再びepubにまとめるスクリプトを作成した.

#!/bin/sh
epub=$1
bname=`basename ${epub}`
base=${bname%.*}
epubo=${base}_jp.epub
TMPDIR=/tmp/${base}

if [ -d ${TMPDIR} ]; then
rm -rf ${TMPDIR}
fi
if [ -f ${TMPDIR}/../${epubo} ]; then
rm -f ${TMPDIR}/../${epubo}
fi
if [ -f ${epubo} ]; then
rm -f ${epubo}
fi
mkdir ${TMPDIR}

unzip ${epub} -d ${TMPDIR}

cd ${TMPDIR}
for f in *.xhtml; do
g=${f}j
sed -e 's|html xmlns="http://www.w3.org/1999/xhtml"|html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"|' ${f} > ${g}
mv -f ${g} ${f}
done

zip -0 ../${epubo} mimetype
zip -r ../${epubo} * -x mimetype

mv ../${epubo} ${OLDPWD}
rm -rf ${TMPDIR}
rm -f ${TMPDIR}../${epubo}

このブログを検索

ブログ アーカイブ

Translate

QooQ