diff options
| author | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-25 00:42:26 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <exa.exa@gmail.com> | 2023-05-25 00:42:26 +0200 |
| commit | 919e953d2035836cf537beb31610e7b2edce8833 (patch) | |
| tree | 407e7fc427bfe8b0c6b0526eba0436afe76194ca /Utils.hs | |
| parent | 32e050bac753687b801a40c91e398a0132ccffbc (diff) | |
| download | reploy-919e953d2035836cf537beb31610e7b2edce8833.tar.gz reploy-919e953d2035836cf537beb31610e7b2edce8833.tar.bz2 | |
link modification works
Diffstat (limited to 'Utils.hs')
| -rw-r--r-- | Utils.hs | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -3,6 +3,11 @@ module Utils where import Control.Monad.IO.Class import Data.List.Extra (stripSuffix) import Data.Maybe (isJust) +import Text.Pandoc.Definition +import qualified Text.Pandoc.Walk +import qualified Data.Text as T + +import Types -- | A shortcut for `liftIO`. io :: MonadIO m => IO a -> m a @@ -20,3 +25,15 @@ hasSuffix s = isJust . stripSuffix s -- | The same second as from arrows et al. second :: (a -> b) -> (c, a) -> (c, b) second f (a, b) = (a, f b) + +-- | A pandoc walker for printing the URLs. +walkURLs :: (FilePath -> Site FilePath) -> Text.Pandoc.Definition.Pandoc -> Site Text.Pandoc.Definition.Pandoc +walkURLs f = Text.Pandoc.Walk.walkM go + where + go (Link a i (u,t)) = do + u' <- T.pack <$> f (T.unpack u) + pure $ Link a i (u',t) + go (Image a i (u,t)) = do + u' <- T.pack <$> f (T.unpack u) + pure $ Image a i (u',t) + go x = pure x |
