From: Mohammed Haris Minai <mhminai-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Graphviz python filter without using pygraphviz
Date: Wed, 21 Jan 2015 06:58:38 -0800 (PST) [thread overview]
Message-ID: <b96d2e46-4be0-4725-9276-ed1790ea8c6c@googlegroups.com> (raw)
In-Reply-To: <CA+u6gbwc2CGBzyuY1SKbC15kYAk9LZOH5tP8yaG=N+doNCxLGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 1573 bytes --]
Well, I am simply completely uncomfortable with Haskell (and python as
well). Anyway having seen the gitit and the examples john has given I gave
it a shot.
Am attching the filter (Example.hs), a sample pdc file(input.pdc) and the
markdown output I get when I use the filter (output.pdc). Somehow my first
code block is not transformed whereas the second one is. Could someone
please help me out here.
I compiled Example.hs file using "ghc --make Example.hs" then used:
pandoc --filter ./Example -t markdown input.pdc > output.pdc
This is the first time I have touched haskell code, so please forgive any
blunders I have made, I have simply tried to combine the gitit plugin with
some code pointed out earlier to me by jon + some understanding from what
the pandoc page says about scripting. I almost have no idea how it is even
working.
On Wednesday, January 21, 2015 at 5:42:33 PM UTC+5:30, Ivan Miljenovic
wrote:
>
> Is there any reason you can't use that gitit filter directly?
>
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/b96d2e46-4be0-4725-9276-ed1790ea8c6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 2138 bytes --]
[-- Attachment #2: input.pdc --]
[-- Type: application/octet-stream, Size: 1044 bytes --]
% Title
% Mohd. Haris Minai
% 25th December, 2015
# This is a level 1 header
~~~ {.dot, name=diagram}
digraph finite_state_machine {
rankdir=LR;
size="8,5"
node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
node [shape = circle];
LR_0 -> LR_2 [ label = "SS(B)" ];
LR_0 -> LR_1 [ label = "SS(S)" ];
LR_1 -> LR_3 [ label = "S($end)" ];
LR_2 -> LR_6 [ label = "SS(b)" ];
LR_2 -> LR_5 [ label = "SS(a)" ];
LR_2 -> LR_4 [ label = "S(A)" ];
LR_5 -> LR_7 [ label = "S(b)" ];
LR_5 -> LR_5 [ label = "S(a)" ];
LR_6 -> LR_6 [ label = "S(b)" ];
LR_6 -> LR_5 [ label = "S(a)" ];
LR_7 -> LR_8 [ label = "S(b)" ];
LR_7 -> LR_5 [ label = "S(a)" ];
LR_8 -> LR_6 [ label = "S(b)" ];
LR_8 -> LR_5a [ label = "S(a)" ];
}
~~~
Some other text in between
~~~ {.dot name=hello}
graph hello2 {
// Hello World with nice colors and big fonts
Node1 [label="Hello, World!", color=Blue, fontcolor=Red,
fontsize=24, shape=box]
}
~~~
~~~{.c name=hello.c}
main () {
print "hello";
}
~~~
[-- Attachment #3: output.pdc --]
[-- Type: application/octet-stream, Size: 842 bytes --]
This is a level 1 header
========================
~\~~ {.dot, name=diagram}
digraph finite\_state\_machine { rankdir=LR; size="8,5" node [shape =
doublecircle]; LR\_0 LR\_3 LR\_4 LR\_8; node [shape = circle]; LR\_0 -\>
LR\_2 [ label = "SS(B)" ]; LR\_0 -\> LR\_1 [ label = "SS(S)" ];
LR\_1 -\> LR\_3 [ label = "S(\$end)" ]; LR\_2 -\> LR\_6 [ label =
"SS(b)" ]; LR\_2 -\> LR\_5 [ label = "SS(a)" ]; LR\_2 -\> LR\_4 [ label
= "S(A)" ]; LR\_5 -\> LR\_7 [ label = "S(b)" ]; LR\_5 -\> LR\_5 [ label
= "S(a)" ]; LR\_6 -\> LR\_6 [ label = "S(b)" ]; LR\_6 -\> LR\_5 [ label
= "S(a)" ]; LR\_7 -\> LR\_8 [ label = "S(b)" ]; LR\_7 -\> LR\_5 [ label
= "S(a)" ]; LR\_8 -\> LR\_6 [ label = "S(b)" ]; LR\_8 -\> LR\_5a [ label
= "S(a)" ]; }
~\~~
Some other text in between
![hello](img/hello.png)
``` {.c name="hello.c"}
main () {
print "hello";
}
```
[-- Attachment #4: Example.hs --]
[-- Type: text/x-haskell, Size: 1121 bytes --]
#!/usr/bin/env haskell
import System.Process (readProcessWithExitCode)
import System.Exit (ExitCode(ExitSuccess))
import Data.ByteString.Lazy.UTF8 (fromString)
-- from the SHA package on HackageDB:
import Data.Digest.Pure.SHA (sha1, showDigest)
import System.FilePath ((</>))
import Control.Monad.Trans (liftIO)
import Text.Pandoc.JSON
transform :: Block -> IO Block
transform (CodeBlock (id, classes, namevals) contents) | "dot" `elem` classes = do
let (name, outfile) = case lookup "name" namevals of
Just fn -> ([Str fn], fn ++ ".png")
Nothing -> ([], uniqueName contents ++ ".png")
liftIO $ do
(ec, _out, err) <- readProcessWithExitCode "dot" ["-Tpng", "-o", "img/" ++ outfile] contents
if ec == ExitSuccess
then return $ Para [Image name ("img/" ++ outfile, "")]
else error $ "dot returned an error status: " ++ err
transform x = return x
-- | Generate a unique filename given the file's contents.
uniqueName :: String -> String
uniqueName = showDigest . sha1 . fromString
main :: IO ()
main = toJSONFilter transform
next prev parent reply other threads:[~2015-01-21 14:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 11:47 Mohammed Haris Minai
[not found] ` <229bfb34-a5bd-4b31-8511-ef9573585990-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-20 12:05 ` Ivan Lazar Miljenovic
[not found] ` <CA+u6gbzNcjOfitQ4hqYbYQARer3_yX-txc=oRb6KyivgAmD2pA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-21 11:52 ` Mohammed Haris Minai
2015-01-21 12:00 ` Mohammed Haris Minai
[not found] ` <1b3951ec-ae53-4943-a4a9-ed5362dc9434-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-21 12:12 ` Ivan Lazar Miljenovic
[not found] ` <CA+u6gbwc2CGBzyuY1SKbC15kYAk9LZOH5tP8yaG=N+doNCxLGA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-21 14:58 ` Mohammed Haris Minai [this message]
[not found] ` <b96d2e46-4be0-4725-9276-ed1790ea8c6c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-22 9:49 ` Mohammed Haris Minai
[not found] ` <ff78de30-d031-4b5b-9021-be32c111db2b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-22 10:18 ` Ivan Lazar Miljenovic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b96d2e46-4be0-4725-9276-ed1790ea8c6c@googlegroups.com \
--to=mhminai-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).