demydd / pandoc

Automatically exported from code.google.com/p/pandoc
0 stars 0 forks source link

Plugin system #102

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Users should be able to write their own plugins that transform a pandoc
document between reader and writer.  These transformations are now made
easy to write by the 'processPandoc' function.  The plugin mechanism can be
provided by the plugins library.

Usage examples:

- modifying inline math to work with Wordpress blog ($2+2$ -> $latex 2+2$)
- using delimited code blocks for purposes other than code (e.g. lilypond
notation, to be converted to an image)
- generating source code snippets programatically (see Issue #90)
- automatically turning CamelCase words into wikilinks

The plugins themselves would be short Haskell programs (which could
themselves call other external programs).  It would be included via a
command-line option:
--plugins=FirstPlugin.hs,SecondPlugin.hs

Steps:
_ provide a plugin API, Pandoc.Interface
_ in Main.hs, apply plugin transformations between reader and writer
_ add a "How to Write a Plugin" tutorial
_ possibly add more functions like 'processPandoc' to simplify the writing
of plugins?

Original issue reported on code.google.com by fiddloso...@gmail.com on 6 Nov 2008 at 10:22

GoogleCodeExporter commented 8 years ago

Original comment by fiddloso...@gmail.com on 6 Nov 2008 at 10:23

GoogleCodeExporter commented 8 years ago
Unfortunately, dons says that the plugins library is no longer maintained.

Original comment by fiddloso...@gmail.com on 11 Nov 2008 at 3:04

GoogleCodeExporter commented 8 years ago
The hint library might be an alternative to plugins.  Check to see if it is 
actively
maintained.

Original comment by fiddloso...@gmail.com on 12 Nov 2008 at 12:57

GoogleCodeExporter commented 8 years ago
Or mueval, for more safety.

Original comment by fiddloso...@gmail.com on 12 Nov 2008 at 1:06

GoogleCodeExporter commented 8 years ago
Example of use of hint, in ghci:

> :m + Language.Haskell.Interpreter.GHC
> :m + Text.Pandoc
> inp <- readFile "README"
> let y = withSession ses (setImports ["Text.Pandoc","Prelude"] >> (interpret
("writeLaTeX defaultWriterOptions $ readMarkdown defaultParserState $ " ++ show 
inp)
(as :: Pandoc)))
> y

Original comment by fiddloso...@gmail.com on 13 Nov 2008 at 7:04

GoogleCodeExporter commented 8 years ago
Note:  the example above is missing
ses <- newSession
also try this:

> :m + Control.Monad.Errors
> e <- withSession ses (setImports ["Prelude"] >> (catchError (interpret "(+)" 
(as ::
Int -> Int)) (\e -> return id)))
> e 2
4
>  e <- withSession sess (setImports ["Prelude","Text.Pandoc"] >> (interpret
"processPandoc (const Space)" (as :: Pandoc -> Pandoc)))
> e $ Pandoc (Meta [] [] []) [Para [Str "Hi",Space,Emph [Str "there"]]]
Pandoc (Meta [] [] "") [Para [Space,Space,Space]]

Original comment by fiddloso...@gmail.com on 14 Nov 2008 at 7:30

GoogleCodeExporter commented 8 years ago
This is fun:
-- MyMod.hs
module MyMod (doit) where
import Text.Pandoc

doit :: Inline -> Inline
doit (Str x) = Str (x ++ "!")
doit x = x

-- GHCI:
GHCI> e <- withSession sess (loadModules ["MyMod"] >> setImports
["Prelude","Text.Pandoc","MyMod"] >> (catchError (interpret "processPandoc 
doit" (as
:: Pandoc -> Pandoc)) (\e -> throwError e >>  return id)))
GHCI> e $ Pandoc (Meta [] [] []) [Para [Str "Hi",Space,Emph [Str "there"]]]
Pandoc (Meta [] [] "") [Para [Str "Hi!",Space,Emph [Str "there!"]]]

Original comment by fiddloso...@gmail.com on 14 Nov 2008 at 7:44

GoogleCodeExporter commented 8 years ago
The newest release of hint supports GHC 6.10.
Time to get going on this!

Original comment by fiddloso...@gmail.com on 1 Jan 2009 at 5:02

GoogleCodeExporter commented 8 years ago
> Or mueval, for more safety.

Mueval might work as a library, with some modification to the internal API. But 
given
that the code is either A) supplied by the developers and presumably vetted and
checked; or B) written by the user who has incentive to not write evil code, 
mueval
may be the wrong solution. 

It is also relatively inefficient compared to running Hint directly, due to the
resource-limiting, process-level and thread-level watchdogs, checks to sanitize 
the
code, etc. That's fine for running potentially-evil code since the alternative 
to
running slowly & safely is not running at all.

I would suggest Hint instead of Mueval. It is pleasant to use & Daniel Gorin has
always responded quickly to my needs (for mueval development), and I don't 
foresee it
being abandoned anytime soon. (It certainly is currently a better solution than
hs-plugins inasmuch as the latter does not even work on 6.10.)

Original comment by gwe...@gmail.com on 23 Jan 2009 at 9:47

GoogleCodeExporter commented 8 years ago
Actually, I've already got all the plugin stuff written, using hint.
I've just been waiting for Daniel to upload the latest version (which
he did today), since the old version didn't cabal install under ghc 6.8.

So you should see the plugin stuff, including some worked-out examples,
in the repository before too long!

Original comment by fiddloso...@gmail.com on 24 Jan 2009 at 2:29

GoogleCodeExporter commented 8 years ago
Added as of r1526.

Original comment by fiddloso...@gmail.com on 24 Jan 2009 at 8:01