aboutsummaryrefslogtreecommitdiff
path: root/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Utils.hs')
-rw-r--r--Utils.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Utils.hs b/Utils.hs
index 4828335..c72e080 100644
--- a/Utils.hs
+++ b/Utils.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE OverloadedStrings #-}
+
module Utils where
import Control.Monad.IO.Class
@@ -41,6 +43,20 @@ walkURLs f = Text.Pandoc.Walk.walkM go
pure $ Image a i (u', t)
go x = pure x
+-- | A pandoc walker for adding the local links to the headings (links are
+-- appended and get a given class)
+addHeadingLinks ::
+ T.Text -> Text.Pandoc.Definition.Pandoc -> Text.Pandoc.Definition.Pandoc
+addHeadingLinks cls = Text.Pandoc.Walk.walk go
+ where
+ go h@(Header lvl attr@(id, _, _) inlines) =
+ Header
+ lvl
+ attr
+ (inlines ++
+ [Link ("", [cls], []) [Str "#"] ("#" <> id, "Link to this section")])
+ go x = x
+
hasUriScheme :: String -> String -> Bool
hasUriScheme x = all id . zipWith (==) x . (++ ":")