Commit graph

3782 commits

Author SHA1 Message Date
Jesse Rosenthal
4fe499d3f2 Have a common state for all PandocMonad instances. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
3574b98f81 Unify Errors. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
52859b9863 Finish converting readers over. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
3f7b3f5fd0 Add Text2Tags to Text.Pandoc 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
6a9a38c92d Add input and output filepaths to PandocMonad.
We'll want these in a number of places, but right now it will be
necessary for the macros in T2T.
2017-01-25 17:07:40 +01:00
Jesse Rosenthal
9d9f615593 Add Zoned time to class. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
fe0b71a2f1 Class: Add getModificationTime
This is to enable macros in T2T, but can be used for other stuff in the
future, I imagine.

This requires building up the info in our fake file trees. Note the
version in IO is safe.
2017-01-25 17:07:40 +01:00
Jesse Rosenthal
b53ebcdf8e Working on readers. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
840439ab2a Add IncoherentInstances pragma for HasQuotedContext.
We can remove this if we can figure out a better way to do this.
2017-01-25 17:07:40 +01:00
Jesse Rosenthal
d9f5f551dd Class: add setMediaBag function. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
d447552be1 Add ParseError to PandocExecutionError.
This will be unified with Text.Pandoc.Error eventually. But I'm building
it out here so as not to interfere with other modules that might be
using the error module currently.
2017-01-25 17:07:40 +01:00
Jesse Rosenthal
b34bb8be01 List derived instances vertically one-per-line for readability. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
97be338188 Change Test{State,Env} to Pure{State,Env}
This was left over from when the pure function was called runTest.
2017-01-25 17:07:40 +01:00
Jesse Rosenthal
2fc47ceebf Class: Add MediaBag to MonadState. 2017-01-25 17:07:40 +01:00
Jesse Rosenthal
cc7191b3b1 Class: Add stateful IO warnings, and function to get warndings.
Right now, the io warnings both print to stderr and write to the
state. That can be easily modified.

We also add a getWarnings function which pulls warnings out of the state
for instances of PandocMonad.
2017-01-25 17:07:40 +01:00
John MacFarlane
18e85f8dfb Changed readNative to use PandocMonad. 2017-01-25 17:07:40 +01:00
John MacFarlane
300d94ac24 Deleted whitespace at end of source lines. 2017-01-25 17:07:39 +01:00
John MacFarlane
0e4f959981 Fixed regression in OPML writer.
OPML writer should note include `_notes` attribute when there's
no content.
2017-01-25 17:07:39 +01:00
John MacFarlane
22ffbad9e8 Texinfo writer: restore former behavior for headers level > 4.
The recent changes made the writer fail with an error if it
encountered a header with level 5.  Better to do as we did
before and just print a paragraph in that case.  Eventually
we should emit a warning here.
2017-01-25 17:07:39 +01:00
John MacFarlane
33af62acc5 Fixes to compile after rebase. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
23c5b0d0f1 Implement Errors in PandocMonad
Errors can be thrown purely with `throwError`. At the moment there are
only three kinds of errors:

1. PandocFileReadError FilePath (for problems reading a file from the
filesystem)

2. PandocShouldNeverHappenError String (for stuff that should never
happen but we need to pattern-match anyway)

3. PandocSomeError String (a grab bag of everything else)

Of course, we need to subdivide the third item in this list.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
04487779b2 Convert all writers to use PandocMonad.
Since PandocMonad is an instance of MonadError, this will allow us, in a
future commit, to change all invocations of `error` to `throwError`,
which will be preferable for the pure versions. At the moment, we're
disabling the lua custom writers (this is temporary).

This requires changing the type of the Writer in Text.Pandoc. Right now,
we run `runIOorExplode` in pandoc.hs, to make the conversion easier. We
can switch it to the safer `runIO` in the future.

Note that this required a change to Text.Pandoc.PDF as well. Since
running an external program is necessarily IO, we can be clearer about
using PandocIO.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
b19f79f672 Add runPure function.
This requires a default environment. The state variables are pretty
straightforward. The env variables are a little trickier. I'm just
making most of them empty for now. Note that some of them (like
defaultReferenceDocx/ODT) will be coming out soon anyway.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
b2721c6b02 Make PandocExecutionError an exception
Until we fix fetchItem and fetchItem' to make use of MonadError, we have
to thow an exception. We'll throw PandocFileReadError. Note that this is
temporary.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
a94f3dddee Make opaque typeclasses PandocPure and PandocIO 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
45f3c53dd9 Class: Specify Functor and Applicative
We're still compiling for 7.8 which is pre-AMP, so let's just be
explicit about it so we can use applicative notation.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
6595318142 Remove Text.Pandoc.Free 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
957eee24ec Convert writers to use PandocMonad typeclass.
Instead of Free Monad with runIO
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
239880f412 Introduce PandocMonad typeclass.
This can be instantiated by both an IO monad or a pure State monad.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
f22bc52864 Remove GetPOSIXTime from Free monad.
We still export a P.getPOSIXTime function, but it's just internally
defined in terms of P.getCurrentTime.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
2ffd630a43 Free: Remove readFileUTF8.
This is just defined in term of a bytestring, so we convert when necessary.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
314a4c7296 Remove readFileStrict.
We only used it once, and then immediately converted to lazy.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
c9e67163fd Remove IO UUID functions. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
8b144db6e5 Write Pure uuid function taking stdgen.
We're trying to cut down the necessarily IO functions. Since we alerady
have a newStdGen function, we don't need this one.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
1c589c51b1 ODT Writer: fix compiler complaint. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
f404412331 Free: Add Typeable instance to PandocActionError 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
2ea3e77172 Finish pure writer of FB2. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
e711043dee FB2 writer: Rewrite image-fetching to use fetchItem.
This uses the function from shared, which will allow us to convert it
over to the free monad.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
30cfda7a71 Continue refactoring FB2 writer. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
d97fb5f3c6 FB2 writer: bring functions to toplevel.
This is the first of a number of changes to bring the FB2 writer a bit
closer to the idioms used elsewhere in pandoc, so it can be more easily
converted to using the pure functions from Free.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
9ac1303660 Make pure rtf writer using free. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
590e119df0 Fix up compiler warnings.
Export TestState and TestEnv, and remove redundant import.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
e24d5a56a7 Implement runTest functions.
These work with a State monad and a Reader monad to produce
deterministic results. It can probably be simplified somewhat.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
072107d1a2 Remove IORef from EPUB writer. 2017-01-25 17:07:39 +01:00
Jesse Rosenthal
8d1d0eb9a5 Remove IORef from ODT writer.
We want pure writers, so IORef shouldn't be in there. We switch to using
a normal State Monad. If this produces performance problems, we can look
into trying STRefs, but that seems like unnecessary complication at the
moment.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
32c68dada9 Introduce pure versions of IO Writers.
Using Text.Pandoc.Free, introduce pure versions of Docx, EPUB, ICML, and
ODT writers. Each of the pure versions is exported along with the IO
version (produced by running `runIO` on the pure reader). Ideally, this
should make the writers easier to test.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
0ab4af2f03 New Free module, with pure versions of IO funcs
Introduce a new module, Text.Pandoc.Free, with pure versions, based on
the free monad, of numerous IO functions used in writers and
readers. These functions are in a pure
Monad (PandocAction). PandocAction takes as a parameter the type of
IORefs in it. It can be aliased in individual writers and readers to
avoid this parameter.

Note that this means that at the moment a reader can only use one type
of IORef. If possible, it would be nice to remove this limitation.
2017-01-25 17:07:39 +01:00
Hubert Plociniczak
a6b469c02b Adds support for pagebreaks (when it makes sense)
Update all writers to take into account page breaks.
A straightforwad, far from complete, implementation of page
breaks in selected writers.
Readers will have to follow in the future as well.
2017-01-25 17:07:39 +01:00
Hubert Plociniczak
30b3412857 Added page breaks into Pandoc.
This requires an updated version of pandoc-types that
introduces PageBreak definition.
Not that this initial commit only introduces ODT pagebreaks
and distinguishes for it page breaks before, after, or both,
the paragraph, as read from the style definition.
2017-01-25 17:07:39 +01:00
John MacFarlane
a5d855d342 Update list of listings languages in Highlighting.
This allows more languages to be used when using the `--listings`
option.

Closes #3374.
2017-01-25 12:35:14 +01:00