diff options
author | Yuchen Pei <hi@ypei.me> | 2022-09-13 15:45:00 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-09-13 15:45:00 +1000 |
commit | 7d32f1b8104574ab9b43e0f0f707c756938e827b (patch) | |
tree | 315f6d33117247d38acc02b2902c16f6ee8cd3c6 /src/Servall/WikiParser.hs | |
parent | e1e795e8152c435ca408de3c373c6687f4bf415e (diff) |
[server] fixing wikilinks
Diffstat (limited to 'src/Servall/WikiParser.hs')
-rw-r--r-- | src/Servall/WikiParser.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Servall/WikiParser.hs b/src/Servall/WikiParser.hs index ec15e1c..2680fad 100644 --- a/src/Servall/WikiParser.hs +++ b/src/Servall/WikiParser.hs @@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} module Servall.WikiParser ( parseWikiTemplates + , wikiFilter ) where import Control.Applicative ( (<|>) ) @@ -31,6 +32,10 @@ import qualified Data.Text as T import Data.Text ( Text ) import GHC.Generics ( Generic ) import Servall.Types +import Text.Pandoc.Definition ( Inline(..) + , Pandoc + ) +import Text.Pandoc.Generic ( topDown ) parseWikiTemplates :: Text -> Either String [WikiTemplate] parseWikiTemplates = parseOnly wikiP @@ -103,3 +108,11 @@ wikilinkP = do beg <- string "[[" content <- T.pack <$> manyTill anyChar (string "]]") return $ beg <> content <> "]]" + +wikiFilter :: Pandoc -> Pandoc +wikiFilter = topDown fixUrl + +fixUrl :: Inline -> Inline +fixUrl (Link attr label (url, "wikilink")) = + Link attr label ("wiki:" <> url, "") +fixUrl x = x |