summaryrefslogtreecommitdiff
path: root/src/Doc.lhs
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-06-14 20:35:08 +0200
committerLars-Dominik Braun <lars@6xq.net>2015-06-14 20:35:08 +0200
commite92c82e2c9ff541cd321ad7a8aedcf34e615197c (patch)
treefd07d24164450f25a224eb593922e4a4926d062b /src/Doc.lhs
downloadpesto-e92c82e2c9ff541cd321ad7a8aedcf34e615197c.tar.gz
pesto-e92c82e2c9ff541cd321ad7a8aedcf34e615197c.tar.bz2
pesto-e92c82e2c9ff541cd321ad7a8aedcf34e615197c.zip
First public version
Diffstat (limited to 'src/Doc.lhs')
-rw-r--r--src/Doc.lhs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/Doc.lhs b/src/Doc.lhs
new file mode 100644
index 0000000..5cba5c1
--- /dev/null
+++ b/src/Doc.lhs
@@ -0,0 +1,65 @@
+Building documentation
+++++++++++++++++++++++
+
+.. class:: nodoc
+
+> {-# LANGUAGE OverloadedStrings #-}
+> import Text.Pandoc
+> import Text.Pandoc.Error (handleError)
+> import Text.Highlighting.Kate.Styles (tango)
+> import Data.List (stripPrefix)
+> import System.FilePath (replaceFileName)
+> import qualified Data.Set as S
+
+The documentation is created from the source module Codec.Pesto, which includes
+the other modules. We use a slightly modified template.
+
+> main = do
+> tpl <- readFile "template.html"
+> doc <- readWithInclude "src/Codec/Pesto.lhs"
+> writeFile "_build/index.html" $ rstToHtml tpl doc
+
+Since pandoc currently does not support restructured text’s include directive,
+emulate it.
+
+> readWithInclude f = do
+> c <- readFile f
+> let l = lines c
+> linc <- mapM (\line -> case stripPrefix ".. include:: " line of
+> Just incfile -> readWithInclude $ replaceFileName f incfile
+> Nothing -> return line) l
+> return $ unlines linc
+
+The pass the resulting string to pandoc that builds a doctree, remove unwanted
+content and build a HTML page.
+
+> rstToHtml tpl = writeDoc tpl . dropNoDoc . handleError . readDoc
+
+> readDoc = readRST def {
+> readerExtensions = S.fromList [
+> Ext_literate_haskell
+> , Ext_implicit_header_references
+> ]
+> , readerStandalone = True }
+
+Drop blocks that should not be visible in the documentation, like module
+definitions and imports.
+
+> dropNoDoc = topDown f
+> where
+> f (Div (_, classes, _) _) | "nodoc" `elem` classes = Null
+> f x = x
+
+> writeDoc tpl = writeHtmlString def {
+> writerStandalone = True
+> , writerTemplate = tpl
+> , writerHtml5 = True
+> , writerHighlight = True
+> , writerHighlightStyle = tango
+> , writerNumberSections = True
+> , writerSectionDivs = True
+> , writerTabStop = 4
+> , writerHTMLMathMethod = MathJax "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
+> , writerVariables = [("css", "pesto.css"), ("lang", "en")]
+> }
+