git.iko.soy/typeable/pandoc
on master help sign in
Allow wildcards in `--epub-embed-font` arguments.

Closes #1939.

commite32227f74482c8a7907c3557fcb42e7f35f0c610 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 13 Feb 2015, 23:29 (12 years ago) parentd5469b3
3 files changed+17−6
README+6−3 pandoc.cabal+2−1 src/Text/Pandoc/Writers/EPUB.hs+9−2
README+6−3
@@ -608,9 +608,12 @@ Options affecting specific writers
608608
609609`--epub-embed-font=`*FILE*
610610: Embed the specified font in the EPUB. This option can be repeated
611− to embed multiple fonts. To use embedded fonts, you
612− will need to add declarations like the following to your CSS (see
613− `--epub-stylesheet`):
611+ to embed multiple fonts. Wildcards can also be used: for example,
612+ `DejaVuSans-*.ttf`. However, if you use wildcards on the command
613+ line, be sure to escape them or put the whole filename in single quotes,
614+ to prevent them from being interpreted by the shell. To use the
615+ embedded fonts, you will need to add declarations like the following
616+ to your CSS (see `--epub-stylesheet`):
614617
615618 @font-face {
616619 font-family: DejaVuSans;
pandoc.cabal+2−1
@@ -253,7 +253,8 @@ Library
253253 haddock-library >= 1.1 && < 1.3,
254254 old-time,
255255 deepseq-generics >= 0.1 && < 0.2,
256− JuicyPixels >= 3.1.6.1 && < 3.3
256+ JuicyPixels >= 3.1.6.1 && < 3.3,
257+ filemanip >= 0.3 && < 0.4
257258 if flag(old-locale)
258259 Build-Depends: old-locale >= 1 && < 1.1,
259260 time >= 1.2 && < 1.5
src/Text/Pandoc/Writers/EPUB.hs+9−2
@@ -36,6 +36,7 @@ import Data.List ( isPrefixOf, isInfixOf, intercalate )
3636import System.Environment ( getEnv )
3737import Text.Printf (printf)
3838import System.FilePath ( takeExtension, takeFileName )
39+import System.FilePath.Glob ( namesMatching )
3940import qualified Data.ByteString.Lazy as B
4041import qualified Data.ByteString.Lazy.Char8 as B8
4142import qualified Text.Pandoc.UTF8 as UTF8
@@ -57,7 +58,7 @@ import Text.Pandoc.Options ( WriterOptions(..)
5758import Text.Pandoc.Definition
5859import Text.Pandoc.Walk (walk, walkM)
5960import Control.Monad.State (modify, get, execState, State, put, evalState)
60−import Control.Monad (foldM, mplus, liftM)
61+import Control.Monad (foldM, mplus, liftM, when)
6162import Text.XML.Light ( unode, Element(..), unqual, Attr(..), add_attrs
6263 , strContent, lookupAttr, Node(..), QName(..), parseXML
6364 , onlyElems, node, ppElement)
@@ -387,8 +388,14 @@ writeEPUB opts doc@(Pandoc meta _) = do
387388 picEntries <- foldM readPicEntry [] pics
388389
389390 -- handle fonts
391+ let matchingGlob f = do
392+ xs <- namesMatching f
393+ when (null xs) $
394+ warn $ f ++ " did not match any font files."
395+ return xs
390396 let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f
391− fontEntries <- mapM mkFontEntry $ writerEpubFonts opts'
397+ fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
398+ fontEntries <- mapM mkFontEntry fontFiles
392399
393400 -- set page progression direction attribution
394401 let progressionDirection = case epubPageDirection metadata of