diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-10-25 23:01:59 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-10-25 23:01:59 +0200 |
commit | e8f2b6e704e870caa16926e7f1a65f52217f552f (patch) | |
tree | 254672b622a01f2e9fc46c1c30bc69d591db037f | |
parent | work (diff) | |
download | vimwiki-scripts-e8f2b6e704e870caa16926e7f1a65f52217f552f.tar.gz vimwiki-scripts-e8f2b6e704e870caa16926e7f1a65f52217f552f.tar.xz |
Cleanup.
-rw-r--r-- | hs/Html.hs | 47 | ||||
-rw-r--r-- | hs/Util.hs | 37 | ||||
-rw-r--r-- | hs/vimwiki.cabal | 3 |
3 files changed, 51 insertions, 36 deletions
@@ -82,6 +82,7 @@ import Text.Pandoc.Definition import Files import Links +import Util -- import Text.DocTemplates (Context(..), ToContext(toVal)) import Data.Map qualified as M @@ -89,7 +90,6 @@ import Data.Set (Set) import Data.Set qualified as S import Data.String (IsString) -(&) = flip ($) isWikiFile = isFiletype "wiki" @@ -179,20 +179,21 @@ rebuildLinks l = l -- Link ("",[],[]) [Str "https://styrdokument.liu.se/Regelsamling/Fil/1513619"] ("https://styrdokument.liu.se/Regelsamling/Fil/1513619","") -- Link ("",[],[]) [Str "Beslut",Space,Str "LIU-2020-02033"] ("file:LinTek/2021/Beslut om riktlinjer och rutiner f\246r genomf\246rande av skriftliga salsskrivningar inklusive digitala tent.pdf","wikilink") +checkbox extra = RawInline (Format "html") + $ "<input type='checkbox' disabled='true' " <> extra <> "/>" + -- buildCheckboxes s@(Span (ids, cls, kvs) _) buildCheckboxes s@(Span (_, cls, _) _) - | "done0" `elem` cls = RawInline (Format "html") "<input type='checkbox' disabled='true'/>" - | "done1" `elem` cls = RawInline (Format "html") "<input type='checkbox' disabled='true'/>" - | "done2" `elem` cls = RawInline (Format "html") "<input type='checkbox' disabled='true'/>" - | "done3" `elem` cls = RawInline (Format "html") "<input type='checkbox' disabled='true'/>" - | "done4" `elem` cls = RawInline (Format "html") "<input type='checkbox' disabled='true' checked/>" + | "done0" `elem` cls = checkbox "" + | "done1" `elem` cls = checkbox "" + | "done2" `elem` cls = checkbox "" + | "done3" `elem` cls = checkbox "" + | "done4" `elem` cls = checkbox "checked" | otherwise = s buildCheckboxes l = l -buildCheckboxes' (Plain (Str "[-]" : Space : xs)) = Plain - [ RawInline (Format "html") "<input type='checkbox' disabled='true' checked/>" - , Strikeout xs - ] +buildCheckboxes' (Plain (Str "[-]" : Space : xs)) + = Plain [ checkbox "checked", Strikeout xs ] buildCheckboxes' l = l applyFilters :: Pandoc -> Pandoc @@ -232,21 +233,6 @@ handleSourceText text = do return pandoc' --- Accumulate all sub-sequences, --- For example, accumulate [1,2,3] == [[1], [1, 2], [1, 2, 3]] -accumulate :: [a] -> [[a]] -accumulate [] = [] -accumulate (x:xs) = (x:) <$> ([]:accumulate xs) - --- Insert element at every other position of list -intersperse :: a -> [a] -> [a] -intersperse _ [] = [] -intersperse _ [x] = [x] -intersperse y (x:xs) = x : y : intersperse y xs - -joinBy :: Monoid a => a -> [a] -> a -joinBy delim lst = mconcat $ intersperse delim lst - -- Becomes wikilink when the URI scheme doesn't match one of -- Text.Pandoc.Shared (schemes) -- Link (_,_,_) _ (_, "wikilink") @@ -294,27 +280,18 @@ htmlWrap title parts backlinks toc main = docTypeHtml $ do backlinks -firstJust :: a -> [Maybe a] -> a -firstJust x [] = x -firstJust _ (Just x:_) = x -firstJust x (_:xs) = firstJust x xs - allHeaders :: Pandoc -> [Block] allHeaders = query f where f h@(Header {}) = [h] f _ = [] + headerContent :: Block -> Maybe Text headerContent (Header _ _ inlines) = Just $ stringify inlines headerContent _ = Nothing -nullToMaybe :: (Eq a, Monoid a) => a -> Maybe a -nullToMaybe m - | m == mempty = Nothing - | otherwise = Just m - handlePart :: FilePath -> M.Map Text (Set FilePath) -> FilePath -> [FilePath] -> PandocIO () handlePart outdir backlinks wiki_root parts = do diff --git a/hs/Util.hs b/hs/Util.hs new file mode 100644 index 0000000..54a334e --- /dev/null +++ b/hs/Util.hs @@ -0,0 +1,37 @@ +module Util +( accumulate +, intersperse +, joinBy +, (&) +, nullToMaybe +, firstJust +) where + +-- Accumulate all sub-sequences, +-- For example, accumulate [1,2,3] == [[1], [1, 2], [1, 2, 3]] +accumulate :: [a] -> [[a]] +accumulate [] = [] +accumulate (x:xs) = (x:) <$> ([]:accumulate xs) + +-- Insert element at every other position of list +intersperse :: a -> [a] -> [a] +intersperse _ [] = [] +intersperse _ [x] = [x] +intersperse y (x:xs) = x : y : intersperse y xs + +joinBy :: Monoid a => a -> [a] -> a +joinBy delim lst = mconcat $ intersperse delim lst + +(&) = flip ($) + + +nullToMaybe :: (Eq a, Monoid a) => a -> Maybe a +nullToMaybe m + | m == mempty = Nothing + | otherwise = Just m + + +firstJust :: a -> [Maybe a] -> a +firstJust x [] = x +firstJust _ (Just x:_) = x +firstJust x (_:xs) = firstJust x xs diff --git a/hs/vimwiki.cabal b/hs/vimwiki.cabal index 850461e..bf290f9 100644 --- a/hs/vimwiki.cabal +++ b/hs/vimwiki.cabal @@ -30,7 +30,8 @@ executable Main Files, Links, Html, - Handlingar + Handlingar, + Util build-depends: base >=4.9, data-default, |