tools/pandoc-site: remove unused datastructure TOCAlignment and function ignoreTOC
This commit is contained in:
parent
946fa1d498
commit
78e10f7663
@ -15,17 +15,10 @@ import Data.Function (on)
|
|||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Text (unpack)
|
import Data.Text (unpack)
|
||||||
|
|
||||||
data TOCAlignment = TOCOff | TOCLeft | TOCRight
|
|
||||||
|
|
||||||
headerLevel :: Block -> Int
|
headerLevel :: Block -> Int
|
||||||
headerLevel (Header level _ _) = level
|
headerLevel (Header level _ _) = level
|
||||||
headerLevel _ = error "not a header"
|
headerLevel _ = error "not a header"
|
||||||
|
|
||||||
ignoreTOC :: Block -> Block
|
|
||||||
ignoreTOC (Header level (ident, classes, params) inlines) =
|
|
||||||
Header level (ident, "notoc" : classes, params) inlines
|
|
||||||
ignoreTOC x = x
|
|
||||||
|
|
||||||
collectHeaders :: Block -> [Block]
|
collectHeaders :: Block -> [Block]
|
||||||
collectHeaders header@(Header _ (_, classes, _) _) =
|
collectHeaders header@(Header _ (_, classes, _) _) =
|
||||||
if "notoc" `elem` classes
|
if "notoc" `elem` classes
|
||||||
@ -52,13 +45,10 @@ markupHeader n = error $ "'markupHeader' should only be passed a 'Node $ Head
|
|||||||
markupHeaders :: Forest Block -> Block
|
markupHeaders :: Forest Block -> Block
|
||||||
markupHeaders = OrderedList (1, Decimal, Period) . map markupHeader
|
markupHeaders = OrderedList (1, Decimal, Period) . map markupHeader
|
||||||
|
|
||||||
createTable :: TOCAlignment -> Forest Block -> Block
|
createTable :: Forest Block -> Block
|
||||||
createTable _ [] = Null
|
createTable [] = Null
|
||||||
createTable alignment headers
|
createTable headers
|
||||||
= let alignAttr = case alignment of
|
= let navBegin = "<nav id=\"toc\" class=\"right-toc\">"
|
||||||
TOCRight -> " class=\"right-toc\""
|
|
||||||
_ -> ""
|
|
||||||
navBegin = "<nav id=\"toc\"" ++ alignAttr ++ ">"
|
|
||||||
navEnd = "</nav>"
|
navEnd = "</nav>"
|
||||||
tocDoc = Pandoc nullMeta [Para [Str "Contents"], markupHeaders headers]
|
tocDoc = Pandoc nullMeta [Para [Str "Contents"], markupHeaders headers]
|
||||||
tocString = unpack . fromRight mempty . runPure . writeHtml5String def $ tocDoc
|
tocString = unpack . fromRight mempty . runPure . writeHtml5String def $ tocDoc
|
||||||
@ -68,12 +58,11 @@ generateTOC :: Block -> Block -> Block
|
|||||||
generateTOC toc (Para [Str "$toc$"]) = toc
|
generateTOC toc (Para [Str "$toc$"]) = toc
|
||||||
generateTOC _ x = x
|
generateTOC _ x = x
|
||||||
|
|
||||||
tableOfContents :: TOCAlignment -> Pandoc -> Pandoc
|
tableOfContents :: Pandoc -> Pandoc
|
||||||
tableOfContents TOCOff ast = walk ignoreTOC ast
|
tableOfContents ast
|
||||||
tableOfContents alignment ast
|
|
||||||
= let headers = query collectHeaders ast
|
= let headers = query collectHeaders ast
|
||||||
toc = createTable alignment . groupByHierarchy $ headers
|
toc = createTable . groupByHierarchy $ headers
|
||||||
in walk (generateTOC toc) ast
|
in walk (generateTOC toc) ast
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = toJSONFilter (tableOfContents TOCRight)
|
main = toJSONFilter tableOfContents
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user