diff options
| author | Mirek Kratochvil <miroslav.kratochvil@uni.lu> | 2023-06-15 15:05:51 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <miroslav.kratochvil@uni.lu> | 2023-06-15 15:05:51 +0200 |
| commit | 0f97b7a64fa3733689b713a2210a4f7b64e069d7 (patch) | |
| tree | 24f2100d87c58fd68681a88fb300cdaceed80a20 /Utils.hs | |
| parent | 1c214fa9f75247e802d9c4b6a8e5b39a03b0e9df (diff) | |
| download | reploy-0f97b7a64fa3733689b713a2210a4f7b64e069d7.tar.gz reploy-0f97b7a64fa3733689b713a2210a4f7b64e069d7.tar.bz2 | |
add local anchors to headers
Diffstat (limited to 'Utils.hs')
| -rw-r--r-- | Utils.hs | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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 . (++ ":") |
