From 40934fa72e375d48d83f50a33c1d2110e1144170 Mon Sep 17 00:00:00 2001 From: Everett Hildenbrandt Date: Fri, 27 Apr 2018 02:40:26 -0600 Subject: [PATCH] hakyll-std/{TableOfContents,hakyll-std}: switch from string-based alignment to sum-type --- site/hakyll-std/TableOfContents.hs | 23 ++++++++++++----------- site/hakyll-std/hakyll-std.hs | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/site/hakyll-std/TableOfContents.hs b/site/hakyll-std/TableOfContents.hs index 6886aa1ed..9745cdf94 100644 --- a/site/hakyll-std/TableOfContents.hs +++ b/site/hakyll-std/TableOfContents.hs @@ -7,6 +7,7 @@ module TableOfContents ( tableOfContents, ignoreTOC, collectHeaders, + TOCAlignment(TOCOff,TOCLeft,TOCRight) ) where import Text.Pandoc @@ -28,6 +29,8 @@ import Text.Blaze.Html.Renderer.String (renderHtml) import qualified Text.Blaze.Html5 as H import qualified Text.Blaze.Html5.Attributes as A +data TOCAlignment = TOCOff | TOCLeft | TOCRight + headerLevel :: Block -> Int headerLevel (Header level _ _) = level headerLevel _ = error "not a header" @@ -69,20 +72,18 @@ createTable headers = H.p "Contents" H.ol $ markupHeaders headers -generateTOC :: [Block] -> String -> Block -> Block +generateTOC :: [Block] -> TOCAlignment -> Block -> Block generateTOC [] _ x = x generateTOC headers alignment x@(BulletList (( (( Plain ((Str "toc"):_)):_)):_)) - | alignment == "right" = render . (! A.class_ "right-toc") . table $ headers - | alignment == "left" = render . table $ headers - | otherwise = x + = case alignment of + TOCRight -> render . (! A.class_ "right-toc") . table $ headers + TOCLeft -> render . table $ headers + _ -> x where render = (RawBlock "html") . renderHtml table = createTable . groupByHierarchy generateTOC _ _ x = x -tableOfContents :: String -> Pandoc -> Pandoc -tableOfContents alignment ast = - if alignment /= "off" - then let headers = query collectHeaders ast - in walk (generateTOC headers alignment) ast - else walk ignoreTOC ast - +tableOfContents :: TOCAlignment -> Pandoc -> Pandoc +tableOfContents TOCOff ast = walk ignoreTOC ast +tableOfContents alignment ast = let headers = query collectHeaders ast + in walk (generateTOC headers alignment) ast diff --git a/site/hakyll-std/hakyll-std.hs b/site/hakyll-std/hakyll-std.hs index f37c2cf4b..5491e8cbe 100755 --- a/site/hakyll-std/hakyll-std.hs +++ b/site/hakyll-std/hakyll-std.hs @@ -53,7 +53,7 @@ import System.Process (system) -- import Text.Highlighting.Kate (pygments, kate, espresso, tango, haddock, monochrome, zenburn) import Text.Pandoc.Options -import TableOfContents (tableOfContents) +import TableOfContents (tableOfContents, TOCAlignment(TOCRight)) import Debug.Trace strace :: Show a => a -> a @@ -118,7 +118,7 @@ pandocWriterOptions = def -- ,writerHighlightStyle=tango --- } -pandocTransform = tableOfContents "right" +pandocTransform = tableOfContents TOCRight main = do args <- getArgs