Safe Haskell | None |
---|
- type Line = String
- type Lines = String
- type RelativePath = FilePath
- type Context = ContextT IO
- data ContextT m a
- runContext :: Context a -> IO (Either String a)
- runContextT :: Monad m => ContextT m a -> m (Either String a)
- data Transform
- transform :: String -> (Lines -> Context Lines) -> Transform
- runTransform :: Transform -> String -> Context String
- readFile :: RelativePath -> Context String
- writeFile :: RelativePath -> String -> Context ()
- inform :: String -> Context ()
- eval :: Typeable a => String -> Context a
- evalWith :: Typeable a => [String] -> String -> Context a
- addPost :: Context () -> Context ()
- printT :: Transform
- evalT :: Transform
- musicT :: Transform
- data MusicOpts = MusicOpts {}
- musicT' :: MusicOpts -> Transform
- haskellT :: Transform
- musicHaskellT :: Transform
- musicHaskellT' :: MusicOpts -> Transform
- musicExtraT :: Transform
Basic types
type RelativePath = FilePathSource
A relative file path.
The Context type
Transformormations
transform :: String -> (Lines -> Context Lines) -> TransformSource
Create a new transformation.
This transformation processes everything in between lines containing a fence such as
~~~name ~~~
or
```name ```
where name
is the name of the transformation.
To create a suitable change function, use the combinators defined below.
Running transformations
runTransform :: Transform -> String -> Context StringSource
Run a transformation in the Context
monad.
Combinators
Input/output
readFile :: RelativePath -> Context StringSource
Read a file.
writeFile :: RelativePath -> String -> Context ()Source
Write to a file.
Evaluation
evalWith :: Typeable a => [String] -> String -> Context aSource
Evaluate a Haskell expression with the given modules in scope. Note that Prelude is not implicitly imported.
All requested modules must be present on the system or the computation will fail. Also, the string must be a valid Haskell expression using constructs which in scope after loading the given modules.
Errors can be caught using catchError
.
addPost :: Context () -> Context ()Source
Register an action to be run after text processing has finished. This can be used to optimize tasks such as external file generations.
Note that addPost does not work trasitively, i.e. post actions of post actions are thrown away.
Transformormations
This named transformation posts its input to the standard error stream and returns nothing.
This named transformation evaluates its input as a Haskell expression of
type String
and returns the value of the expression.
For example the input
~~~haskell "The number is " ++ show $ 3 + 2 ~~~
Will be transformed into
The number is 6
This named transformation evaluates its input as a music expression.
The music is rendered as an .ly
file and a .mid
fiel, then lilypond
and convert
is run to render a .png
file. A markdown image tag and a HTML play and stop button
is returned.
The expression must return a value of type Score Note
. The Music.Prelude.Basic
module is implicitly imported.
This named transformation passes everything through and retains the source.
musicHaskellT :: TransformSource
This named transformation runs the music
transformation and retains the source.
musicExtraT :: TransformSource
This named transformation includes stuff needed for music playback.
It should be used exactly once in the document.