mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:02:44 +03:00
Shake.hs, tools/pandoc-drop-toc: switch to lua script filter
This commit is contained in:
parent
95c9af5664
commit
ddaea7cffc
4
Shake.hs
4
Shake.hs
@ -87,7 +87,7 @@ main = do
|
|||||||
--- "tools" </> "pandoc-drop-html-inlines"
|
--- "tools" </> "pandoc-drop-html-inlines"
|
||||||
--- "tools" </> "pandoc-drop-links"
|
--- "tools" </> "pandoc-drop-links"
|
||||||
--- "tools" </> "pandoc-drop-notes"
|
--- "tools" </> "pandoc-drop-notes"
|
||||||
"tools" </> "pandoc-drop-toc"
|
--- "tools" </> "pandoc-drop-toc"
|
||||||
]
|
]
|
||||||
|
|
||||||
shakeArgs
|
shakeArgs
|
||||||
@ -286,7 +286,7 @@ main = do
|
|||||||
cmd Shell ("printf '\\n\\n' >>") webmanall :: Action ExitCode
|
cmd Shell ("printf '\\n\\n' >>") webmanall :: Action ExitCode
|
||||||
cmd Shell "pandoc" f "-t markdown-fenced_divs --atx-headers"
|
cmd Shell "pandoc" f "-t markdown-fenced_divs --atx-headers"
|
||||||
-- "--filter tools/pandoc-drop-man-blocks"
|
-- "--filter tools/pandoc-drop-man-blocks"
|
||||||
"--filter tools/pandoc-drop-toc"
|
"--lua-filter tools/pandoc-drop-toc.lua"
|
||||||
-- "--filter tools/pandoc-capitalize-headers"
|
-- "--filter tools/pandoc-capitalize-headers"
|
||||||
"--lua-filter tools/pandoc-demote-headers.lua"
|
"--lua-filter tools/pandoc-demote-headers.lua"
|
||||||
">>" webmanall :: Action ExitCode
|
">>" webmanall :: Action ExitCode
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
#!/usr/bin/env stack
|
|
||||||
{- stack runghc
|
|
||||||
--verbosity info
|
|
||||||
--stack-yaml=stack-ghc8.2.yaml
|
|
||||||
--package pandoc-types
|
|
||||||
--package safe
|
|
||||||
--package split
|
|
||||||
-}
|
|
||||||
-- Remove a table of contents marker
|
|
||||||
-- (a bullet list item containing "toc[-N[-M]]")
|
|
||||||
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
|
|
||||||
import Data.Char (isDigit)
|
|
||||||
import Data.List.Split
|
|
||||||
import Data.Maybe
|
|
||||||
import Safe
|
|
||||||
import Text.Pandoc.JSON
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = toJSONFilter dropToc
|
|
||||||
|
|
||||||
dropHtmlBlocks :: Block -> Block
|
|
||||||
dropHtmlBlocks (RawBlock (Format "html") _) = Plain []
|
|
||||||
dropHtmlBlocks x = x
|
|
||||||
|
|
||||||
-- BulletList
|
|
||||||
-- [ [Plain [Str "toc"]] ]
|
|
||||||
dropToc :: Block -> Block
|
|
||||||
dropToc (BulletList is) =
|
|
||||||
BulletList $ filter (not.null) $ map (filter isNotToc) is
|
|
||||||
where
|
|
||||||
isNotToc (Plain [Str s]) | isJust $ tocParams s = False
|
|
||||||
isNotToc _ = True
|
|
||||||
dropToc x = x
|
|
||||||
|
|
||||||
tocParams :: String -> Maybe (Maybe Int, Maybe Int)
|
|
||||||
tocParams s =
|
|
||||||
case splitOn "-" s of
|
|
||||||
["toc"] -> Just (Nothing, Nothing)
|
|
||||||
["toc",a] | all isDigit a -> Just (Nothing, readMay a)
|
|
||||||
["toc",a,b] | all isDigit a, all isDigit b -> Just (readMay a, readMay b)
|
|
||||||
_ -> Nothing
|
|
||||||
|
|
16
tools/pandoc-drop-toc.lua
Normal file
16
tools/pandoc-drop-toc.lua
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
function keepBi(bi)
|
||||||
|
if not (bi[1].t == "Plain") then return true end
|
||||||
|
if not (bi[1].content[1].t == "Str") then return true end
|
||||||
|
if not (string.find(bi[1].content[1].text, "toc") == 1) then return true end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function BulletList(bl)
|
||||||
|
local newBl = { }
|
||||||
|
for i,bi in pairs(bl.content) do
|
||||||
|
if keepBi(bi)
|
||||||
|
then table.insert(newBl, bi)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return pandoc.BulletList(newBl)
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user