I would like to create a Haskell program to automatically generate documents with Pandoc.
I created a small example document with the data types provided by Pandoc but when I launch my program, the ODT document is empty (But with the title My own test file
in the properties) and the text file only contain the word Template
.
This is the code snippet of my program :
import Text.Pandoc
import qualified Data.ByteString.Lazy as Byt
import Data.Map (fromList)
main = do
doc <- writeODT WriterOptions{ writerStandalone=True
, writerReferenceODT=Nothing
, writerUserDataDir=Nothing
, writerTemplate="Template"} doctest
let doc2 = writeMarkdown WriterOptions{ writerStandalone=True
, writerTemplate="Template"} doctest
putStrLn $ show doctest
Byt.writeFile "test.odt" doc
writeFile "test.txt" doc2
doctest = Pandoc ( Meta {unMeta = fromList [("title", MetaInlines [Str "My own testfile"])
,("authors", MetaInlines [Str "My Name"]) ]} )
[Para [Str "This",Space,Str "is",Space,Str "some",Space,Str "text"],HorizontalRule]
Both of the text file and the ODT docuement should contain the phrase This is some text
and I don't understand why it doesn't appear.
Do you know what I have made wrong ?
Do you have a working example on how to generate a Pandoc file with Haskell ?
You have enabled the option writerStandalone
which require a template to be defined to work properly. Personally, I don't use templates and I set the writerStandalone
option to False
To make it work, use these WriterOptions
for the plain text writer :
let textfile = writePlain WriterOptions{ writerStandalone=False
, writerExtensions=plainExtensions
, writerWrapText=True
, writerColumns=80} pandoc
for the docx writer :
docxfile <- writeDocx WriterOptions{ writerStandalone=False
, writerReferenceDocx=Nothing
, writerUserDataDir=Nothing
, writerHighlight = False
} pandoc