aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/EPUB.hs
AgeCommit message (Collapse)AuthorFilesLines
2021-02-16Rename Text.Pandoc.XMLParser -> Text.Pandoc.XML.Light...John MacFarlane1-183/+173
..and add new definitions isomorphic to xml-light's, but with Text instead of String. This allows us to keep most of the code in existing readers that use xml-light, but avoid lots of unnecessary allocation. We also add versions of the functions from xml-light's Text.XML.Light.Output and Text.XML.Light.Proc that operate on our modified XML types, and functions that convert xml-light types to our types (since some of our dependencies, like texmath, use xml-light). Update golden tests for docx and pptx. OOXML test: Use `showContent` instead of `ppContent` in `displayDiff`. Docx: Do a manual traversal to unwrap sdt and smartTag. This is faster, and needed to pass the tests. Benchmarks: A = prior to 8ca191604dcd13af27c11d2da225da646ebce6fc (Feb 8) B = as of 8ca191604dcd13af27c11d2da225da646ebce6fc (Feb 8) C = this commit | Reader | A | B | C | | ------- | ----- | ------ | ----- | | docbook | 18 ms | 12 ms | 10 ms | | opml | 65 ms | 62 ms | 35 ms | | jats | 15 ms | 11 ms | 9 ms | | docx | 72 ms | 69 ms | 44 ms | | odt | 78 ms | 41 ms | 28 ms | | epub | 64 ms | 61 ms | 56 ms | | fb2 | 14 ms | 5 ms | 4 ms |
2021-02-11Use getTimestamp instead of getCurrentTime in writers.John MacFarlane1-2/+2
Setting SOURCE_DATE_EPOCH will allow reproducible builds. Partially addresses #7093. This does not suffice to fully enable reproducible in EPUB, since a unique id is being generated for each build.
2021-02-10Add new unexported module T.P.XMLParser.John MacFarlane1-3/+10
This exports functions that uses xml-conduit's parser to produce an xml-light Element or [Content]. This allows existing pandoc code to use a better parser without much modification. The new parser is used in all places where xml-light's parser was previously used. Benchmarks show a significant performance improvement in parsing XML-based formats (especially ODT and FB2). Note that the xml-light types use String, so the conversion from xml-conduit types involves a lot of extra allocation. It would be desirable to avoid that in the future by gradually switching to using xml-conduit directly. This can be done module by module. The new parser also reports errors, which we report when possible. A new constructor PandocXMLError has been added to PandocError in T.P.Error [API change]. Closes #7091, which was the main stimulus. These changes revealed the need for some changes in the tests. The docbook-reader.docbook test lacked definitions for the entities it used; these have been added. And the docx golden tests have been updated, because the new parser does not preserve the order of attributes. Add entity defs to docbook-reader.docbook. Update golden tests for docx.
2021-02-03ePub writer: `belongs-to-collection` metadata (#7063)Nick Berendsen1-41/+58
2021-01-10Fix infinite HTTP requests when writing epubs from URL source.John MacFarlane1-5/+9
Due to a bug in code added to avoid overwriting the cover image if it had the form `fileX.YYY`, pandoc made an endless sequence of HTTP requests when writing epub with input from a URL. Closes #7013.
2021-01-08Update copyright notices for 2021 (#7012)Albert Krewinkel1-1/+1
2021-01-04EPUB writer: adjust internal links to identifiers...John MacFarlane1-0/+20
defined in raw HTML sections after splitting into chapters. Closes #7000.
2021-01-03EPUB writer: recognize `Format "html4"`, `Format "html5"` as raw HTML.John MacFarlane1-2/+8
2021-01-03EPUB writer: adjust internal links to images, links, and tables...John MacFarlane1-0/+6
after splitting into chapters. Previously we only did this for Div and Span and Header elements. See #7000.
2020-12-03EPUB writer: include title page in landmarks.John MacFarlane1-2/+7
Closes #6919. Note that the toc is also included if `--toc` is specified.
2020-12-03EPUB writer: add frontmatter type on body element for nav.xhtml.John MacFarlane1-1/+3
Closes #6918.
2020-09-13Fix hlint suggestions, update hlint.yaml (#6680)Christian Despres1-14/+12
* Fix hlint suggestions, update hlint.yaml Most suggestions were redundant brackets. Some required LambdaCase. The .hlint.yaml file had a small typo, and didn't ignore camelCase suggestions in certain modules.
2020-03-30Fix #6228 (#6230)Joseph C. Sible1-3/+3
UUID: Remove `getUUID`, fix `getRandomUUID` and make it polymorphic in PandocMonad.
2020-03-22Finer grained imports of Text.Pandoc.Class submodules (#6203)Albert Krewinkel1-2/+3
This should speed-up recompilation after changes in `Text.Pandoc.Class`, as the number of modules affected by a change will be smaller in general. It also offers faster insights into the parts of `T.P.Class` used within a module.
2020-03-15Use implicit Prelude (#6187)Albert Krewinkel1-2/+0
* Use implicit Prelude The previous behavior was introduced as a fix for #4464. It seems that this change alone did not fix the issue, and `stack ghci` and `cabal repl` only work with GHC 8.4.1 or newer, as no custom Prelude is loaded for these versions. Given this, it seems cleaner to revert to the implicit Prelude. * PandocMonad: remove outdated check for base version Only base versions 4.9 and later are supported, the check for `MIN_VERSION_base(4,8,0)` is therefore unnecessary. * Always use custom prelude Previously, the custom prelude was used only with older GHC versions, as a workaround for problems with ghci. The ghci problems are resolved by replacing package `base` with `base-noprelude`, allowing for consistent use of the custom prelude across all GHC versions.
2020-03-13Update copyright year (#6186)Albert Krewinkel1-1/+1
* Update copyright year * Copyright: add notes for Lua and Jira modules
2020-03-04EPUB writer: fix regression on detection of front/back/bodymatter.John MacFarlane1-1/+2
This bug caused sections with epub:type "dedication" to be misplaced in bodymatter instead of frontmatter as specified in the manual. The same problem would affect other epub:types. The pattern matching needed to be changed with the use of `makeSection`. Closes #6170.
2020-02-07Resolve HLint warningsAlbert Krewinkel1-6/+11
All warnings are either fixed or, if more appropriate, HLint is configured to ignore them. HLint suggestions remain. * Ignore "Use camelCase" warnings in Lua and legacy code * Fix or ignore remaining HLint warnings * Remove redundant brackets * Remove redundant `return`s * Remove redundant as-pattern * Fuse mapM_/map * Use `.` to shorten code * Remove redundant `fmap` * Remove unused LANGUAGE pragmas * Hoist `not` in Text.Pandoc.App * Use fewer imports for `Text.DocTemplates` * Remove redundant `do`s * Remove redundant `$`s * Jira reader: remove unnecessary parentheses
2020-02-03Swap suboptimal uses of maybe and fromMaybe (#6111)Joseph C. Sible1-4/+4
Anywhere "maybe" is used with "id" as its second argument, using "fromMaybe" instead will simplify the code. Conversely, anywhere "fromMaybe" is used with the result of "fmap" or "<$>" as its second argument, using "maybe" instead will simplify the code.
2019-11-25EPUB writer: Fix regression with `--css option.John MacFarlane1-9/+13
Closes #5937.
2019-11-12Switch to new pandoc-types and use Text instead of String [API change].despresc1-77/+80
PR #5884. + Use pandoc-types 1.20 and texmath 0.12. + Text is now used instead of String, with a few exceptions. + In the MediaBag module, some of the types using Strings were switched to use FilePath instead (not Text). + In the Parsing module, new parsers `manyChar`, `many1Char`, `manyTillChar`, `many1TillChar`, `many1Till`, `manyUntil`, `mantyUntilChar` have been added: these are like their unsuffixed counterparts but pack some or all of their output. + `glob` in Text.Pandoc.Class still takes String since it seems to be intended as an interface to Glob, which uses strings. It seems to be used only once in the package, in the EPUB writer, so that is not hard to change.
2019-11-03EPUB writer: ensure that `lang` variable is set on all chapters.John MacFarlane1-3/+5
2019-10-09Options.WriterOptions: Change type of writerVariables to Context Text.John MacFarlane1-31/+54
This will allow structured values. [API change]
2019-09-20Bug fixes to EPUB chapter splitting.John MacFarlane1-15/+16
2019-09-19EPUB writer: make --epub-chapter-level work again.John MacFarlane1-19/+15
It was temporarily broken by the latest change to chapter splitting code.
2019-09-19EPUB writer: improve splitting into chapters.John MacFarlane1-36/+23
+ Use makeSection from T.P.Shared. This deals better with embedded divs. (Closes #5761.) + Remove chapter-title class from chapter h1, for now. (Reverts one change made earlier; we may revisit this in light of #5749.) + Avoid issuing warning multiple times when title not set (see #5760).
2019-09-14Add chapter-title class to EPUB chapter title h1 elements.John MacFarlane1-3/+5
See #5269.
2019-09-14EPUB toChapters: don't treat "refs" Div specially.John MacFarlane1-1/+1
This should make toChapters work better if there are Divs around sections.
2019-09-08Replace Element and makeHierarchical with makeSections.John MacFarlane1-25/+29
Text.Pandoc.Shared: + Remove `Element` type [API change] + Remove `makeHierarchicalize` [API change] + Add `makeSections` [API change] + Export `deLink` [API change] Now that we have Divs, we can use them to represent the structure of sections, and we don't need a special Element type. `makeSections` reorganizes a block list, adding Divs with class `section` around sections, and adding numbering if needed. This change also fixes some longstanding issues recognizing section structure when the document contains Divs. Closes #3057, see also #997. All writers have been changed to use `makeSections`. Note that in the process we have reverted the change c1d058aeb1c6a331a2cc22786ffaab17f7118ccd made in response to #5168, which I'm not completely sure was a good idea. Lua modules have also been adjusted accordingly. Existing lua filters that use `hierarchicalize` will need to be rewritten to use `make_sections`.
2019-07-13Merge pull request #5590 from blmage/fix-4206John MacFarlane1-7/+16
Do not override "fileN" medias when writing to EPUB format (fix #4206)
2019-07-13EPUB writer: Use svg tag wrapper for cover image.John MacFarlane1-2/+12
In addition, the code generating the image has been moved to the template, to make it more customizable. Those who use custom EPUB templates will need to adjust their templates, adding the code to generate the cover image. (Previously this was just inserted into 'body'.) Closes #5643.
2019-06-18Do not override existing "fileN" medias when writing to EPUB format (fix #4206)blmage1-7/+16
2019-06-04Fix document section assignments in EPUB writer.John MacFarlane1-4/+7
For example, introduction should go in bodymatter, not frontmatter, and epigraph, conclusion, and afterward should go in bodymatter, not backmatter. For the full list of assignments, see the manual. Closes #5546.
2019-05-27EPUB writer: don't include 'landmarks' if there aren't any.John MacFarlane1-9/+10
Previously we could get an empty ol element, which caused validation errors with epubcheck.
2019-04-23EPUB writer: Ensure unique ids for styleesheets in content.opf.John MacFarlane1-3/+3
Closes #5463.
2019-03-01Remove license boilerplate.John MacFarlane1-18/+0
The haddock module header contains essentially the same information, so the boilerplate is redundant and just one more thing to get out of sync.
2019-02-04Add missing copyright notices and remove license boilerplate (#5112)Albert Krewinkel1-2/+2
Quite a few modules were missing copyright notices. This commit adds copyright notices everywhere via haddock module headers. The old license boilerplate comment is redundant with this and has been removed. Update copyright years to 2019. Closes #4592.
2019-01-08EPUB writer: ensure that picture transforms are done on metadata too.John MacFarlane1-6/+6
2019-01-02EPUB writer: small fixes to nav.xhtml.John MacFarlane1-0/+1
* Add 'landmarks' id attribute to the landmarks nav. * Replace old default CSS removing numbers from ol.toc li with new rules that match `nav#toc ol, nav#landmarks ol`. * We keep the `toc` class on `ol` for backwards compatibility.
2018-11-24EPUB writer: handle calibre metadata.John MacFarlane1-1/+22
Nodes of the form <meta name="calibre:series" content="Classics on War and Politics"/> are now included from an epub XML metadata file. You can also include this information in your YAML metadata, like so: calibre: series: Classics on War and Policitics In addition, ibooks-specific metadata can now be included via an XML file. (Previously, it could only be included via YAML metadata, see #2693.) Closes #5098.
2018-11-19For bibliography match Div with id 'refs', not class 'references'.John MacFarlane1-2/+2
This was a mismatch between pandoc's docx, epub, latex, and markdown writers and the behavior of pandoc-citeproc, which actually looks for a div with id 'refs' rather than one with class 'references'.
2018-11-11Text.Pandoc.Shared: add parameter to uniqueIdent, inlineListToIdentifier.John MacFarlane1-4/+4
The parameter is Extensions. This allows these functions to be sensitive to the settings of `Ext_gfm_auto_identifiers` and `Ext_ascii_identifiers`. This allows us to use `uniqueIdent` in the CommonMark reader, replacing some custom code. It also means that `gfm_auto_identifiers` can now be used in all formats. Semantically, `gfm_auto_identifiers` is now a modifier of `auto_identifiers`; for identifiers to be set, `auto_identifiers` must be turned on, and then the type of identifier produced depends on `gfm_auto_identifiers` and `ascii_identifiers` are set. Closes #5057.
2018-10-28EPUB writer: use metadata field `css` instead of `stylesheet`mb211-3/+4
closes #4990
2018-09-04hlint some writersAlexander Krotov1-1/+1
2018-08-28EPUB writer: set epub:type on body element intelligently.John MacFarlane1-6/+22
epub:type of first section epub:type of body -------------------------- ------------------ prologue frontmatter abstract frontmatter acknowledgments frontmatter copyright-page frontmatter dedication frontmatter foreword frontmatter halftitle, frontmatter introduction frontmatter preface frontmatter seriespage frontmatter titlepage frontmatter afterword backmatter appendix backmatter colophon backmatter conclusion backmatter epigraph backmatter Otherwise body will have epub:type 'bodymatter'. This only affects epub3. See http://www.idpf.org/epub/profiles/edu/structure/#h.l0bzsloklt10 Closes #4823.
2018-05-12EPUB writer: properly escape pagetitle.John MacFarlane1-3/+6
Previously we weren't escaping `&` and other XML characters in the pagetitle, so a title containing a `&` would be invalid.
2018-03-23EPUB writer: ensure that pagetitle is always set...John MacFarlane1-6/+12
even when structured titles are used. This prevents spurious warnings about empty title elements. Closes #4486.
2018-03-18EPUB writer: remove notes from TOC in nav.xhtml (#4463)Mauro Bieg1-4/+5
fixes #4453
2018-03-18Removed old-locale flag and Text.Pandoc.Compat.Time.John MacFarlane1-1/+1
This is no longer necessary since we no longer support ghc 7.8.
2018-03-18Use NoImplicitPrelude and explicitly import Prelude.John MacFarlane1-0/+2
This seems to be necessary if we are to use our custom Prelude with ghci. Closes #4464.