git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: split writeEPUB into writeEPUB2, writeEPUB3.
190943eJohn MacFarlane
MANUAL.txt+12−11
@@ -101,7 +101,7 @@ If no *input-file* is specified, input is read from *stdin*.
101Otherwise, the *input-files* are concatenated (with a blank
101Otherwise, the *input-files* are concatenated (with a blank
102line between each) and used as input. Output goes to *stdout* by
102line between each) and used as input. Output goes to *stdout* by
103default (though output to *stdout* is disabled for the `odt`, `docx`,
103default (though output to *stdout* is disabled for the `odt`, `docx`,
104−`epub`, and `epub3` output formats). For output to a file, use the
104+`epub2`, and `epub3` output formats). For output to a file, use the
105`-o` option:
105`-o` option:
106
106
107 pandoc -o output.html input.txt
107 pandoc -o output.html input.txt
@@ -273,7 +273,7 @@ General options
273 (original unextended Markdown), `markdown_phpextra` (PHP Markdown
273 (original unextended Markdown), `markdown_phpextra` (PHP Markdown
274 Extra), `markdown_github` (GitHub-Flavored Markdown), `markdown_mmd`
274 Extra), `markdown_github` (GitHub-Flavored Markdown), `markdown_mmd`
275 (MultiMarkdown), `commonmark` (CommonMark Markdown), `rst`
275 (MultiMarkdown), `commonmark` (CommonMark Markdown), `rst`
276− (reStructuredText), `html` (XHTML), `html5` (HTML5), `latex`
276+ (reStructuredText), `html4` (XHTML4), `html` or `html5` (HTML5), `latex`
277 (LaTeX), `beamer` (LaTeX beamer slide show), `context` (ConTeXt),
277 (LaTeX), `beamer` (LaTeX beamer slide show), `context` (ConTeXt),
278 `man` (groff man), `mediawiki` (MediaWiki markup),
278 `man` (groff man), `mediawiki` (MediaWiki markup),
279 `dokuwiki` (DokuWiki markup), `zimwiki` (ZimWiki markup),
279 `dokuwiki` (DokuWiki markup), `zimwiki` (ZimWiki markup),
@@ -281,7 +281,7 @@ General options
281 `texinfo` (GNU Texinfo), `opml` (OPML), `docbook` (DocBook 4),
281 `texinfo` (GNU Texinfo), `opml` (OPML), `docbook` (DocBook 4),
282 `docbook5` (DocBook 5), `opendocument` (OpenDocument), `odt`
282 `docbook5` (DocBook 5), `opendocument` (OpenDocument), `odt`
283 (OpenOffice text document), `docx` (Word docx), `haddock`
283 (OpenOffice text document), `docx` (Word docx), `haddock`
284− (Haddock markup), `rtf` (rich text format), `epub` (EPUB v2
284+ (Haddock markup), `rtf` (rich text format), `epub` or `epub2` (EPUB v2
285 book), `epub3` (EPUB v3), `fb2` (FictionBook2 e-book),
285 book), `epub3` (EPUB v3), `fb2` (FictionBook2 e-book),
286 `asciidoc` (AsciiDoc), `icml` (InDesign ICML), `tei` (TEI
286 `asciidoc` (AsciiDoc), `icml` (InDesign ICML), `tei` (TEI
287 Simple), `slidy` (Slidy HTML and JavaScript slide show),
287 Simple), `slidy` (Slidy HTML and JavaScript slide show),
@@ -293,7 +293,7 @@ General options
293 `epub`, and `epub3` output will not be directed to *stdout*;
293 `epub`, and `epub3` output will not be directed to *stdout*;
294 an output filename must be specified using the `-o/--output`
294 an output filename must be specified using the `-o/--output`
295 option. If `+lhs` is appended to `markdown`, `rst`, `latex`,
295 option. If `+lhs` is appended to `markdown`, `rst`, `latex`,
296− `beamer`, `html`, or `html5`, the output will be rendered as
296+ `beamer`, `html4`, or `html5`, the output will be rendered as
297 literate Haskell source: see [Literate Haskell support],
297 literate Haskell source: see [Literate Haskell support],
298 below. Markdown syntax extensions can be individually
298 below. Markdown syntax extensions can be individually
299 enabled or disabled by appending `+EXTENSION` or
299 enabled or disabled by appending `+EXTENSION` or
@@ -626,7 +626,7 @@ Options affecting specific writers
626 images, and videos. The resulting file should be "self-contained,"
626 images, and videos. The resulting file should be "self-contained,"
627 in the sense that it needs no external files and no net access to be
627 in the sense that it needs no external files and no net access to be
628 displayed properly by a browser. This option works only with HTML output
628 displayed properly by a browser. This option works only with HTML output
629− formats, including `html`, `html5`, `html+lhs`, `html5+lhs`, `s5`,
629+ formats, including `html4`, `html5`, `html+lhs`, `html5+lhs`, `s5`,
630 `slidy`, `slideous`, `dzslides`, and `revealjs`. Scripts, images, and
630 `slidy`, `slideous`, `dzslides`, and `revealjs`. Scripts, images, and
631 stylesheets at absolute URLs will be downloaded; those at relative URLs
631 stylesheets at absolute URLs will be downloaded; those at relative URLs
632 will be sought relative to the working directory (if the first source
632 will be sought relative to the working directory (if the first source
@@ -947,10 +947,11 @@ Math rendering in HTML
947
947
948`--mathml`[`=`*URL*]
948`--mathml`[`=`*URL*]
949
949
950−: Convert TeX math to [MathML] (in `docbook`, `docbook5`, `html` and `html5`).
950+: Convert TeX math to [MathML] (in `docbook`, `docbook5`,
951+ `html4` and `html5`). In standalone HTML output, a small
951− In standalone `html` output, a small JavaScript (or a link to such a
952+ JavaScript (or a link to such a script if a *URL* is
952− script if a *URL* is supplied) will be inserted that allows the MathML to
953+ supplied) will be inserted that allows the MathML to be
953− be viewed on some browsers.
954+ viewed on some browsers.
954
955
955`--jsmath`[`=`*URL*]
956`--jsmath`[`=`*URL*]
956
957
@@ -1647,7 +1648,7 @@ Note, however, that this method of providing links to sections works
1647only in HTML, LaTeX, and ConTeXt formats.
1648only in HTML, LaTeX, and ConTeXt formats.
1648
1649
1649If the `--section-divs` option is specified, then each section will
1650If the `--section-divs` option is specified, then each section will
1650−be wrapped in a `div` (or a `section`, if `--html5` was specified),
1651+be wrapped in a `div` (or a `section`, if `html5` was specified),
1651and the identifier will be attached to the enclosing `<div>`
1652and the identifier will be attached to the enclosing `<div>`
1652(or `<section>`) tag rather than the header itself. This allows entire
1653(or `<section>`) tag rather than the header itself. This allows entire
1653sections to be manipulated using JavaScript or treated differently in
1654sections to be manipulated using JavaScript or treated differently in
@@ -3891,7 +3892,7 @@ Literate Haskell support
3891
3892
3892If you append `+lhs` (or `+literate_haskell`) to an appropriate input or output
3893If you append `+lhs` (or `+literate_haskell`) to an appropriate input or output
3893format (`markdown`, `markdown_strict`, `rst`, or `latex` for input or output;
3894format (`markdown`, `markdown_strict`, `rst`, or `latex` for input or output;
3894−`beamer`, `html` or `html5` for output only), pandoc will treat the document as
3895+`beamer`, `html4` or `html5` for output only), pandoc will treat the document as
3895literate Haskell source. This means that
3896literate Haskell source. This means that
3896
3897
3897 - In Markdown input, "bird track" sections will be parsed as Haskell
3898 - In Markdown input, "bird track" sections will be parsed as Haskell
data/templates+1−1

Submodule changed.

pandoc.cabal+1−1
@@ -66,7 +66,7 @@ Data-Files:
66 data/templates/default.haddock
66 data/templates/default.haddock
67 data/templates/default.textile
67 data/templates/default.textile
68 data/templates/default.org
68 data/templates/default.org
69− data/templates/default.epub
69+ data/templates/default.epub2
70 data/templates/default.epub3
70 data/templates/default.epub3
71 -- source files for reference.docx
71 -- source files for reference.docx
72 data/docx/[Content_Types].xml
72 data/docx/[Content_Types].xml
src/Text/Pandoc.hs+7−5
@@ -115,7 +115,8 @@ module Text.Pandoc
115 , writeRTF
115 , writeRTF
116 , writeODT
116 , writeODT
117 , writeDocx
117 , writeDocx
118− , writeEPUB
118+ , writeEPUB2
119+ , writeEPUB3
119 , writeFB2
120 , writeFB2
120 , writeOrg
121 , writeOrg
121 , writeAsciiDoc
122 , writeAsciiDoc
@@ -278,10 +279,9 @@ writers = [
278 ,("json" , StringWriter $ \o d -> return $ writeJSON o d)
279 ,("json" , StringWriter $ \o d -> return $ writeJSON o d)
279 ,("docx" , ByteStringWriter writeDocx)
280 ,("docx" , ByteStringWriter writeDocx)
280 ,("odt" , ByteStringWriter writeODT)
281 ,("odt" , ByteStringWriter writeODT)
281− ,("epub" , ByteStringWriter $ \o ->
282+ ,("epub" , ByteStringWriter writeEPUB2)
282− writeEPUB o{ writerEpubVersion = Just EPUB2 })
283+ ,("epub2" , ByteStringWriter writeEPUB2)
283− ,("epub3" , ByteStringWriter $ \o ->
284+ ,("epub3" , ByteStringWriter writeEPUB3)
284− writeEPUB o{ writerEpubVersion = Just EPUB3 })
285 ,("fb2" , StringWriter writeFB2)
285 ,("fb2" , StringWriter writeFB2)
286 ,("html" , StringWriter writeHtml5String)
286 ,("html" , StringWriter writeHtml5String)
287 ,("html4" , StringWriter writeHtml4String)
287 ,("html4" , StringWriter writeHtml4String)
@@ -349,6 +349,8 @@ getDefaultExtensions "epub" = extensionsFromList
349 Ext_native_divs,
349 Ext_native_divs,
350 Ext_native_spans,
350 Ext_native_spans,
351 Ext_epub_html_exts]
351 Ext_epub_html_exts]
352+getDefaultExtensions "epub2" = getDefaultExtensions "epub"
353+getDefaultExtensions "epub3" = getDefaultExtensions "epub"
352getDefaultExtensions "latex" = extensionsFromList
354getDefaultExtensions "latex" = extensionsFromList
353 [Ext_smart,
355 [Ext_smart,
354 Ext_auto_identifiers]
356 Ext_auto_identifiers]
src/Text/Pandoc/Templates.hs+1
@@ -61,6 +61,7 @@ getDefaultTemplate user writer = do
61 "fb2" -> return $ Right ""
61 "fb2" -> return $ Right ""
62 "odt" -> getDefaultTemplate user "opendocument"
62 "odt" -> getDefaultTemplate user "opendocument"
63 "html" -> getDefaultTemplate user "html5"
63 "html" -> getDefaultTemplate user "html5"
64+ "epub" -> getDefaultTemplate user "epub2"
64 "markdown_strict" -> getDefaultTemplate user "markdown"
65 "markdown_strict" -> getDefaultTemplate user "markdown"
65 "multimarkdown" -> getDefaultTemplate user "markdown"
66 "multimarkdown" -> getDefaultTemplate user "markdown"
66 "markdown_github" -> getDefaultTemplate user "markdown"
67 "markdown_github" -> getDefaultTemplate user "markdown"
src/Text/Pandoc/Writers/EPUB.hs+24−7
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
28
29Conversion of 'Pandoc' documents to EPUB.
29Conversion of 'Pandoc' documents to EPUB.
30-}
30-}
31−module Text.Pandoc.Writers.EPUB ( writeEPUB ) where
31+module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where
32import qualified Data.Map as M
32import qualified Data.Map as M
33import qualified Data.Set as Set
33import qualified Data.Set as Set
34import Data.Maybe ( fromMaybe, catMaybes )
34import Data.Maybe ( fromMaybe, catMaybes )
@@ -75,8 +75,9 @@ import qualified Text.Pandoc.Class as P
75-- in filenames, chapter0003.xhtml.
75-- in filenames, chapter0003.xhtml.
76data Chapter = Chapter (Maybe [Int]) [Block]
76data Chapter = Chapter (Maybe [Int]) [Block]
77
77
78+data EPUBState = EPUBState {
78−data EPUBState = EPUBState { stMediaPaths :: [(FilePath, (FilePath, Maybe Entry))]
79+ stMediaPaths :: [(FilePath, (FilePath, Maybe Entry))]
79− }
80+ }
80
81
81type E m = StateT EPUBState m
82type E m = StateT EPUBState m
82
83
@@ -336,16 +337,32 @@ metadataFromMeta opts meta = EPUBMetadata{
336 Just "rtl" -> Just RTL
337 Just "rtl" -> Just RTL
337 _ -> Nothing
338 _ -> Nothing
338
339
340+-- | Produce an EPUB2 file from a Pandoc document.
341+writeEPUB2 :: PandocMonad m
342+ => WriterOptions -- ^ Writer options
343+ -> Pandoc -- ^ Document to convert
344+ -> m B.ByteString
345+writeEPUB2 = writeEPUB EPUB2
346+
347+-- | Produce an EPUB3 file from a Pandoc document.
348+writeEPUB3 :: PandocMonad m
349+ => WriterOptions -- ^ Writer options
350+ -> Pandoc -- ^ Document to convert
351+ -> m B.ByteString
352+writeEPUB3 = writeEPUB EPUB3
353+
339-- | Produce an EPUB file from a Pandoc document.
354-- | Produce an EPUB file from a Pandoc document.
340writeEPUB :: PandocMonad m
355writeEPUB :: PandocMonad m
356+ => EPUBVersion
341− => WriterOptions -- ^ Writer options
357+ -> WriterOptions -- ^ Writer options
342 -> Pandoc -- ^ Document to convert
358 -> Pandoc -- ^ Document to convert
343 -> m B.ByteString
359 -> m B.ByteString
344−writeEPUB opts doc =
360+writeEPUB epubVersion opts doc =
345 let initState = EPUBState { stMediaPaths = []
361 let initState = EPUBState { stMediaPaths = []
346 }
362 }
347 in
363 in
348− evalStateT (pandocToEPUB opts doc) initState
364+ evalStateT (pandocToEPUB opts{ writerEpubVersion = Just epubVersion } doc)
365+ initState
349
366
350pandocToEPUB :: PandocMonad m
367pandocToEPUB :: PandocMonad m
351 => WriterOptions
368 => WriterOptions
@@ -353,7 +370,7 @@ pandocToEPUB :: PandocMonad m
353 -> E m B.ByteString
370 -> E m B.ByteString
354pandocToEPUB opts doc@(Pandoc meta _) = do
371pandocToEPUB opts doc@(Pandoc meta _) = do
355 let version = fromMaybe EPUB2 (writerEpubVersion opts)
372 let version = fromMaybe EPUB2 (writerEpubVersion opts)
356− let epub3 = version == EPUB3
373+ let epub3 = writerEpubVersion opts == Just EPUB3
357 epochtime <- floor <$> lift P.getPOSIXTime
374 epochtime <- floor <$> lift P.getPOSIXTime
358 let mkEntry path content = toEntry path epochtime content
375 let mkEntry path content = toEntry path epochtime content
359 let vars = ("epub3", if epub3 then "true" else "false")
376 let vars = ("epub3", if epub3 then "true" else "false")