From 7d32f1b8104574ab9b43e0f0f707c756938e827b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 13 Sep 2022 15:45:00 +1000 Subject: [server] fixing wikilinks --- src/Servall/WikiParser.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Servall/WikiParser.hs') 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 -- cgit v1.2.3