Commit graph

7678 commits

Author SHA1 Message Date
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
bf8fb78389 Text.Pandoc: Change Reader to Reader m.
For now I just replaced occurences of Reader with Reader IO,
so nothing is really different.

When we move readers into instances of PandocMonad, though,
we can change things here so that the readers will work
with any instance of PandocMonad.
2017-01-25 17:07:40 +01:00
John MacFarlane
8978689c08 Removed some commented-out source. 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
23baba2243 Fixed icml tables test (no newline at end). 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
fb2ae14977 Fixed rtf tables test 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
1673bda95e Update tests to work with runPure. 2017-01-25 17:07:39 +01:00
John MacFarlane
b969863e07 Export Text.Pandoc.Class from Text.Pandoc. 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
04545c92c8 Clean up Text.Pandoc
We had primed versions of all the Writer types and getWriter
functions, as we transitioned. Now that we're using the new ones
exclusively, we'll get rid of the old ones, and get rid of the primes in
the names.
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
211d0f9574 Tests: have docx writer test use runIOorExplode.
Note that part of the reason for making a pure writer is to have better
tests, so this is a temporary fix.
2017-01-25 17:07:39 +01:00
Jesse Rosenthal
989971fce1 Pandoc.hs: Run runIOorExplode on IO functions.
This is a compatibility layer to reintroduce something like the old
errors into the functions.
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