public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Haskell script to create multi-column document
@ 2014-06-13 20:52 Joshua Mendelsohn
       [not found] ` <6e9dd3d6-7fda-4e72-b43e-6d0334885b08-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua Mendelsohn @ 2014-06-13 20:52 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]

Hi,

I'm trying to create a haskell script that takes two single column markdown 
documents and returns a multi-column document. I'm having trouble 
understanding the difference between the [Block] and Blocks data types. 
Here is what I have so far:

#!/usr/bin/env runhaskell
-- makedual.hs
import Text.Pandoc
import Text.Pandoc.Builder


readDoc :: String -> Pandoc
readDoc = readMarkdown def


writeDoc :: Pandoc -> String
writeDoc = writeMarkdown def


discardMeta :: Pandoc -> [Block]
discardMeta ( Pandoc _ x ) = x


docBlocks :: String -> [Blocks]
docBlocks x = discardMeta . readDoc x


dualify :: String -> String -> String
dualify latin english = writeDoc $ table (Str "Test table") [(AlignLeft,0.5
),(AlignLeft,0.5)] [[Plain [Str "English"]], [Plain [Str "Latin"]]] [docBlocks 
latin, docBlocks english]


main = do
 latin <- readFile "Latin12.md"
 english <- readFile "English12.md"
 putStr (dualify latin english)

How can I construct the Blocks element needed for the table headers? There 
are probably other problems too (I'm new to Haskell), so please feel free 
to suggest improvements!

Thanks.

-- 
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/6e9dd3d6-7fda-4e72-b43e-6d0334885b08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 11362 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Haskell script to create multi-column document
       [not found] ` <6e9dd3d6-7fda-4e72-b43e-6d0334885b08-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2014-06-14  8:14   ` Tillmann Rendel
       [not found]     ` <539C046C.1010203-jNDFPZUTrfTbB13WlS47k8u21/r88PR+s0AfqQuZ5sE@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Tillmann Rendel @ 2014-06-14  8:14 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Hi,

Joshua Mendelsohn wrote:
> I'm having trouble understanding the difference between the [Block]
> and Blocks data types.

Internally, pandoc uses [Block], a list of blocks. The 
Text.Pandoc.Builder module defines

   type Blocks = Many Block

and then uses Blocks everywhere. You can convert back and forth using 
the fromList and toList functions from Text.Pandoc.Builder. Note that 
these functions mention `Many a` in their type, not `Blocks`, but for `a 
= Block`, that's the same thing.

But if you use only the operations from Text.Pandoc.Builder to create 
you pandoc documents, you don't have to convert back and forth, because 
these operations all accept and produces Blocks instead of [Block].

For example, here is part of your code:
> table (Str "Test table")
>   [(AlignLeft, 0.5), (AlignLeft, 0.5)]
>   [[Plain [Str"English"]], [Plain [Str"Latin"]]]
>   [docBlocks latin, docBlocks english]

Here, you mix operations from Text.Pandoc.Builder like table and the 
internal data constructors like Plain and Str. I think it would be 
better to write something like this instead:

> table (str "Test" <> space <> str "table")
>   [(AlignLeft, 0.5), (AlignLeft, 0.5)]
>   [plain (str "English"), plain (str "Latin")]
>   [docBLocks latin, docBlocks english]

The differences are:

  1. use plain instead of Plain, str instead of Str, etc.
  2. instead of [..., ...] sometimes use ... <> ...

> There are probably other problems too (I'm new to Haskell), so please feel free to suggest improvements!

I think there are might be some other issues with Blocks vs. Document 
and columns vs. rows in your code, but I'm not sure. Probably a good 
next step would be to first get it to compile at all, and then look at 
the output to understand what else needs to change.

   Tillmann


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Haskell script to create multi-column document
       [not found]     ` <539C046C.1010203-jNDFPZUTrfTbB13WlS47k8u21/r88PR+s0AfqQuZ5sE@public.gmane.org>
@ 2014-06-15 15:15       ` Joshua Mendelsohn
  0 siblings, 0 replies; 3+ messages in thread
From: Joshua Mendelsohn @ 2014-06-15 15:15 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3564 bytes --]

Thank you! The toList and fromList functions were exactly what I was
looking for. Now I can do it all using the Text.Pandoc.Builder constructs.

Could you explain the usage of "<>" in your suggestion? I did some
googling but couldn't find any documentation on that operator.


On Sat, Jun 14, 2014 at 3:14 AM, Tillmann Rendel <
rendel-jNDFPZUTrfTbB13WlS47k8u21/r88PR+s0AfqQuZ5sE@public.gmane.org> wrote:

> Hi,
>
>
> Joshua Mendelsohn wrote:
>
>> I'm having trouble understanding the difference between the [Block]
>> and Blocks data types.
>>
>
> Internally, pandoc uses [Block], a list of blocks. The Text.Pandoc.Builder
> module defines
>
>   type Blocks = Many Block
>
> and then uses Blocks everywhere. You can convert back and forth using the
> fromList and toList functions from Text.Pandoc.Builder. Note that these
> functions mention `Many a` in their type, not `Blocks`, but for `a =
> Block`, that's the same thing.
>
> But if you use only the operations from Text.Pandoc.Builder to create you
> pandoc documents, you don't have to convert back and forth, because these
> operations all accept and produces Blocks instead of [Block].
>
> For example, here is part of your code:
>
>  table (Str "Test table")
>>   [(AlignLeft, 0.5), (AlignLeft, 0.5)]
>>   [[Plain [Str"English"]], [Plain [Str"Latin"]]]
>>   [docBlocks latin, docBlocks english]
>>
>
> Here, you mix operations from Text.Pandoc.Builder like table and the
> internal data constructors like Plain and Str. I think it would be better
> to write something like this instead:
>
>  table (str "Test" <> space <> str "table")
>>   [(AlignLeft, 0.5), (AlignLeft, 0.5)]
>>   [plain (str "English"), plain (str "Latin")]
>>   [docBLocks latin, docBlocks english]
>>
>
> The differences are:
>
>  1. use plain instead of Plain, str instead of Str, etc.
>  2. instead of [..., ...] sometimes use ... <> ...
>
>
>  There are probably other problems too (I'm new to Haskell), so please
>> feel free to suggest improvements!
>>
>
> I think there are might be some other issues with Blocks vs. Document and
> columns vs. rows in your code, but I'm not sure. Probably a good next step
> would be to first get it to compile at all, and then look at the output to
> understand what else needs to change.
>
>   Tillmann
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "pandoc-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/pandoc-discuss/TW5yasRD3l0/unsubscribe.
> To unsubscribe from this group and all its topics, 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/539C046C.1010203%40informatik.uni-marburg.de.
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAOLFbOsStFqTALLbd%2BB28_yhnNq46mo9-%3D50nLkWs8J3qBJiKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 5638 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-15 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-13 20:52 Haskell script to create multi-column document Joshua Mendelsohn
     [not found] ` <6e9dd3d6-7fda-4e72-b43e-6d0334885b08-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2014-06-14  8:14   ` Tillmann Rendel
     [not found]     ` <539C046C.1010203-jNDFPZUTrfTbB13WlS47k8u21/r88PR+s0AfqQuZ5sE@public.gmane.org>
2014-06-15 15:15       ` Joshua Mendelsohn

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).