git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: split writeEPUB into writeEPUB2, writeEPUB3.

Also include explicit epub2 output format in CLI tool.

commit190943e1fd75b7fa30689387e4416dd81b584f5e authorJohn MacFarlane <jgm@berkeley.edu> dateThu 26 Jan 2017, 20:39 (10 years ago) parentfce0a60
6 files changed+46−25
MANUAL.txt+12−11 data/templates+1−1 pandoc.cabal+1−1 src/Text/Pandoc.hs+7−5 src/Text/Pandoc/Templates.hs+1 src/Text/Pandoc/Writers/EPUB.hs+24−7
MANUAL.txt+12−11
@@ -101,7 +101,7 @@ If no *input-file* is specified, input is read from *stdin*.
101101Otherwise, the *input-files* are concatenated (with a blank
102102line between each) and used as input. Output goes to *stdout* by
103103default (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
105105`-o` option:
106106
107107 pandoc -o output.html input.txt
@@ -273,7 +273,7 @@ General options
273273 (original unextended Markdown), `markdown_phpextra` (PHP Markdown
274274 Extra), `markdown_github` (GitHub-Flavored Markdown), `markdown_mmd`
275275 (MultiMarkdown), `commonmark` (CommonMark Markdown), `rst`
276− (reStructuredText), `html` (XHTML), `html5` (HTML5), `latex`
276+ (reStructuredText), `html4` (XHTML4), `html` or `html5` (HTML5), `latex`
277277 (LaTeX), `beamer` (LaTeX beamer slide show), `context` (ConTeXt),
278278 `man` (groff man), `mediawiki` (MediaWiki markup),
279279 `dokuwiki` (DokuWiki markup), `zimwiki` (ZimWiki markup),
@@ -281,7 +281,7 @@ General options
281281 `texinfo` (GNU Texinfo), `opml` (OPML), `docbook` (DocBook 4),
282282 `docbook5` (DocBook 5), `opendocument` (OpenDocument), `odt`
283283 (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
285285 book), `epub3` (EPUB v3), `fb2` (FictionBook2 e-book),
286286 `asciidoc` (AsciiDoc), `icml` (InDesign ICML), `tei` (TEI
287287 Simple), `slidy` (Slidy HTML and JavaScript slide show),
@@ -293,7 +293,7 @@ General options
293293 `epub`, and `epub3` output will not be directed to *stdout*;
294294 an output filename must be specified using the `-o/--output`
295295 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
297297 literate Haskell source: see [Literate Haskell support],
298298 below. Markdown syntax extensions can be individually
299299 enabled or disabled by appending `+EXTENSION` or
@@ -626,7 +626,7 @@ Options affecting specific writers
626626 images, and videos. The resulting file should be "self-contained,"
627627 in the sense that it needs no external files and no net access to be
628628 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`,
630630 `slidy`, `slideous`, `dzslides`, and `revealjs`. Scripts, images, and
631631 stylesheets at absolute URLs will be downloaded; those at relative URLs
632632 will be sought relative to the working directory (if the first source
@@ -947,10 +947,11 @@ Math rendering in HTML
947947
948948`--mathml`[`=`*URL*]
949949
950−: Convert TeX math to [MathML] (in `docbook`, `docbook5`, `html` and `html5`).
951− In standalone `html` output, a small JavaScript (or a link to such a
952− script if a *URL* is supplied) will be inserted that allows the MathML to
953− be viewed on some browsers.
950+: Convert TeX math to [MathML] (in `docbook`, `docbook5`,
951+ `html4` and `html5`). In standalone HTML output, a small
952+ JavaScript (or a link to such a script if a *URL* is
953+ supplied) will be inserted that allows the MathML to be
954+ viewed on some browsers.
954955
955956`--jsmath`[`=`*URL*]
956957
@@ -1647,7 +1648,7 @@ Note, however, that this method of providing links to sections works
16471648only in HTML, LaTeX, and ConTeXt formats.
16481649
16491650If 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),
16511652and the identifier will be attached to the enclosing `<div>`
16521653(or `<section>`) tag rather than the header itself. This allows entire
16531654sections to be manipulated using JavaScript or treated differently in
@@ -3891,7 +3892,7 @@ Literate Haskell support
38913892
38923893If you append `+lhs` (or `+literate_haskell`) to an appropriate input or output
38933894format (`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
38953896literate Haskell source. This means that
38963897
38973898 - 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:
6666 data/templates/default.haddock
6767 data/templates/default.textile
6868 data/templates/default.org
69− data/templates/default.epub
69+ data/templates/default.epub2
7070 data/templates/default.epub3
7171 -- source files for reference.docx
7272 data/docx/[Content_Types].xml
src/Text/Pandoc.hs+7−5
@@ -115,7 +115,8 @@ module Text.Pandoc
115115 , writeRTF
116116 , writeODT
117117 , writeDocx
118− , writeEPUB
118+ , writeEPUB2
119+ , writeEPUB3
119120 , writeFB2
120121 , writeOrg
121122 , writeAsciiDoc
@@ -278,10 +279,9 @@ writers = [
278279 ,("json" , StringWriter $ \o d -> return $ writeJSON o d)
279280 ,("docx" , ByteStringWriter writeDocx)
280281 ,("odt" , ByteStringWriter writeODT)
281− ,("epub" , ByteStringWriter $ \o ->
282− writeEPUB o{ writerEpubVersion = Just EPUB2 })
283− ,("epub3" , ByteStringWriter $ \o ->
284− writeEPUB o{ writerEpubVersion = Just EPUB3 })
282+ ,("epub" , ByteStringWriter writeEPUB2)
283+ ,("epub2" , ByteStringWriter writeEPUB2)
284+ ,("epub3" , ByteStringWriter writeEPUB3)
285285 ,("fb2" , StringWriter writeFB2)
286286 ,("html" , StringWriter writeHtml5String)
287287 ,("html4" , StringWriter writeHtml4String)
@@ -349,6 +349,8 @@ getDefaultExtensions "epub" = extensionsFromList
349349 Ext_native_divs,
350350 Ext_native_spans,
351351 Ext_epub_html_exts]
352+getDefaultExtensions "epub2" = getDefaultExtensions "epub"
353+getDefaultExtensions "epub3" = getDefaultExtensions "epub"
352354getDefaultExtensions "latex" = extensionsFromList
353355 [Ext_smart,
354356 Ext_auto_identifiers]
src/Text/Pandoc/Templates.hs+1
@@ -61,6 +61,7 @@ getDefaultTemplate user writer = do
6161 "fb2" -> return $ Right ""
6262 "odt" -> getDefaultTemplate user "opendocument"
6363 "html" -> getDefaultTemplate user "html5"
64+ "epub" -> getDefaultTemplate user "epub2"
6465 "markdown_strict" -> getDefaultTemplate user "markdown"
6566 "multimarkdown" -> getDefaultTemplate user "markdown"
6667 "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
2828
2929Conversion of 'Pandoc' documents to EPUB.
3030-}
31−module Text.Pandoc.Writers.EPUB ( writeEPUB ) where
31+module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where
3232import qualified Data.Map as M
3333import qualified Data.Set as Set
3434import Data.Maybe ( fromMaybe, catMaybes )
@@ -75,8 +75,9 @@ import qualified Text.Pandoc.Class as P
7575-- in filenames, chapter0003.xhtml.
7676data Chapter = Chapter (Maybe [Int]) [Block]
7777
78−data EPUBState = EPUBState { stMediaPaths :: [(FilePath, (FilePath, Maybe Entry))]
79− }
78+data EPUBState = EPUBState {
79+ stMediaPaths :: [(FilePath, (FilePath, Maybe Entry))]
80+ }
8081
8182type E m = StateT EPUBState m
8283
@@ -336,16 +337,32 @@ metadataFromMeta opts meta = EPUBMetadata{
336337 Just "rtl" -> Just RTL
337338 _ -> Nothing
338339
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+
339354-- | Produce an EPUB file from a Pandoc document.
340355writeEPUB :: PandocMonad m
341− => WriterOptions -- ^ Writer options
356+ => EPUBVersion
357+ -> WriterOptions -- ^ Writer options
342358 -> Pandoc -- ^ Document to convert
343359 -> m B.ByteString
344−writeEPUB opts doc =
360+writeEPUB epubVersion opts doc =
345361 let initState = EPUBState { stMediaPaths = []
346362 }
347363 in
348− evalStateT (pandocToEPUB opts doc) initState
364+ evalStateT (pandocToEPUB opts{ writerEpubVersion = Just epubVersion } doc)
365+ initState
349366
350367pandocToEPUB :: PandocMonad m
351368 => WriterOptions
@@ -353,7 +370,7 @@ pandocToEPUB :: PandocMonad m
353370 -> E m B.ByteString
354371pandocToEPUB opts doc@(Pandoc meta _) = do
355372 let version = fromMaybe EPUB2 (writerEpubVersion opts)
356− let epub3 = version == EPUB3
373+ let epub3 = writerEpubVersion opts == Just EPUB3
357374 epochtime <- floor <$> lift P.getPOSIXTime
358375 let mkEntry path content = toEntry path epochtime content
359376 let vars = ("epub3", if epub3 then "true" else "false")