Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandoc HTML Table of Contents Output

Tags:

haskell

pandoc

I'm using pandoc (not the executable on the command line but the haskell library), and I'm generating HTML output. I cannot make the table of contents appear in the output. Roughly, I have this:

...
writeHtml (def {writerTOCDepth = 4, writerTableOfContents = True} m)
where m =
  [ Header 1 ("myIdentifier",[],[]) [Str "Vulnerabilities"]                                           
  , Div nullAttr otherStuff                                                                                
  ]

I feel like this alone should be sufficient to get HTML output with a simple table of contents (one that has only a link to the Vulnerabilities section). If anyone sees what I've missed, I would appreciate the help.

EDIT

I believe that the issue is related to me needing to set writerStandalone = True, but when I do this, the resulting document is completely blank.

like image 969
Andrew Thaddeus Martin Avatar asked Sep 02 '15 20:09

Andrew Thaddeus Martin


1 Answers

Figured it out. You have to turn on standalone mode and set a template:

loadReportPandocOpts :: IO WriterOptions                                                              
loadReportPandocOpts = do
  t <- readFile "resources/report-template.html"                                                      
  return def
    { writerTOCDepth = 4
    , writerTableOfContents = True                                                                    
    , writerHtml5 = True                                                                              
    , writerStandalone = True                                                                         
    , writerTemplate = t                                                                              
    }

And the template should look something like this:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <meta name="generator" content="pandoc" />
  </head>
  <body>
    <div>$toc$</div>
    <div>$body$</div>
  </body>
</html>
like image 94
Andrew Thaddeus Martin Avatar answered Sep 25 '22 01:09

Andrew Thaddeus Martin