Reputation: 141
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 ?
Upvotes: 3
Views: 529
Reputation: 2948
In the current Pandoc version (3.6.1) the WriterOptions are changed. There is no option writerStandalone
anymore. I assume you have to set the template with writerTemplate
with Just template
, possibly using the default template, with compileDefaultTemplate
getting the template ready to use.
If no template is desired (equivalent to writerStandalone=False
) use Nothing
as argument.
Upvotes: 0
Reputation: 2741
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
Upvotes: 1
Reputation: 27636
You are not setting a correct writerTemplate
.
You can tweak the template yourself, but should start from the default ones to understand their required structure. This is especially important for the ODT exporter, where the template needs to contain a quite verbose XML prelude.
I was able to get your code working by first loading the default templates, and then populating that with your document:
main = do
Right odtTemplate <- getDefaultTemplate Nothing "odt"
doc <- writeODT def{ writerStandalone = True
, writerTemplate = odtTemplate
}
doctest
Byt.writeFile "test.odt" doc
Right mdTemplate <- getDefaultTemplate Nothing "markdown"
let doc2 = writeMarkdown def{ writerStandalone = True
, writerTemplate = mdTemplate
}
doctest
writeFile "test.txt" doc2
Upvotes: 2