Skip to content

Commit

Permalink
Allow wildcards in --epub-embed-font arguments.
Browse files Browse the repository at this point in the history
Closes #1939.
  • Loading branch information
jgm committed Feb 14, 2015
1 parent d5469b3 commit e32227f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README
Expand Up @@ -608,9 +608,12 @@ Options affecting specific writers

`--epub-embed-font=`*FILE*
: Embed the specified font in the EPUB. This option can be repeated
to embed multiple fonts. To use embedded fonts, you
will need to add declarations like the following to your CSS (see
`--epub-stylesheet`):
to embed multiple fonts. Wildcards can also be used: for example,
`DejaVuSans-*.ttf`. However, if you use wildcards on the command
line, be sure to escape them or put the whole filename in single quotes,
to prevent them from being interpreted by the shell. To use the
embedded fonts, you will need to add declarations like the following
to your CSS (see `--epub-stylesheet`):

@font-face {
font-family: DejaVuSans;
Expand Down
3 changes: 2 additions & 1 deletion pandoc.cabal
Expand Up @@ -253,7 +253,8 @@ Library
haddock-library >= 1.1 && < 1.3,
old-time,
deepseq-generics >= 0.1 && < 0.2,
JuicyPixels >= 3.1.6.1 && < 3.3
JuicyPixels >= 3.1.6.1 && < 3.3,
filemanip >= 0.3 && < 0.4
if flag(old-locale)
Build-Depends: old-locale >= 1 && < 1.1,
time >= 1.2 && < 1.5
Expand Down
11 changes: 9 additions & 2 deletions src/Text/Pandoc/Writers/EPUB.hs
Expand Up @@ -36,6 +36,7 @@ import Data.List ( isPrefixOf, isInfixOf, intercalate )
import System.Environment ( getEnv )
import Text.Printf (printf)
import System.FilePath ( takeExtension, takeFileName )
import System.FilePath.Glob ( namesMatching )
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.Char8 as B8
import qualified Text.Pandoc.UTF8 as UTF8
Expand All @@ -57,7 +58,7 @@ import Text.Pandoc.Options ( WriterOptions(..)
import Text.Pandoc.Definition
import Text.Pandoc.Walk (walk, walkM)
import Control.Monad.State (modify, get, execState, State, put, evalState)
import Control.Monad (foldM, mplus, liftM)
import Control.Monad (foldM, mplus, liftM, when)
import Text.XML.Light ( unode, Element(..), unqual, Attr(..), add_attrs
, strContent, lookupAttr, Node(..), QName(..), parseXML
, onlyElems, node, ppElement)
Expand Down Expand Up @@ -387,8 +388,14 @@ writeEPUB opts doc@(Pandoc meta _) = do
picEntries <- foldM readPicEntry [] pics

-- handle fonts
let matchingGlob f = do
xs <- namesMatching f
when (null xs) $
warn $ f ++ " did not match any font files."
return xs
let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f
fontEntries <- mapM mkFontEntry $ writerEpubFonts opts'
fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
fontEntries <- mapM mkFontEntry fontFiles

-- set page progression direction attribution
let progressionDirection = case epubPageDirection metadata of
Expand Down

0 comments on commit e32227f

Please sign in to comment.