88
99module Subst (plugin ) where
1010
11- import "MonadCatchIO -mtl" Control.Monad.CatchIO (try )
11+ -- import "MonadCatchIO-mtl" Control.Monad.CatchIO (try)
12+ import Control.Monad.Catch (try )
1213import Data.FileStore (FileStoreError , retrieve )
1314import Text.Pandoc (def , readMarkdown )
1415import Network.Gitit.ContentTransformer (inlinesToString )
@@ -19,17 +20,24 @@ plugin :: Plugin
1920plugin = mkPageTransformM substituteIntoBlock
2021
2122substituteIntoBlock :: [Block ] -> PluginM [Block ]
22- substituteIntoBlock ((Para [Link ref (" !subst" , _)]): xs) =
23+ substituteIntoBlock ((Para [Link attr ref (" !subst" , _)]): xs) =
2324 do let target = inlinesToString ref
2425 cfg <- askConfig
2526 let fs = filestoreFromConfig cfg
2627 article <- try $ liftIO (retrieve fs (target ++ " .page" ) Nothing )
2728 case article :: Either FileStoreError String of
2829 Left _ -> let txt = Str (" [" ++ target ++ " ](!subst)" )
2930 alt = " '" ++ target ++ " ' doesn't exist. Click here to create it."
30- lnk = Para [Link [txt] (target,alt)]
31+ lnk = Para [Link attr [txt] (target,alt)]
3132 in (lnk : ) `fmap` substituteIntoBlock xs
32- Right a -> let (Pandoc _ content) = readMarkdown def a
33- in (content ++ ) `fmap` substituteIntoBlock xs
33+ -- Right a -> let (Pandoc _ content) = readMarkdown def a
34+ -- in (content ++) `fmap` substituteIntoBlock xs
35+
36+ Right a -> case readMarkdown def a of
37+ Left err ->
38+ let content = [Para $ [Str " Error parsing markdown in subst?" ]] in
39+ (content ++ ) `fmap` substituteIntoBlock xs
40+ Right (Pandoc _ content) -> (content ++ ) `fmap` substituteIntoBlock xs
41+
3442substituteIntoBlock (x: xs) = (x: ) `fmap` substituteIntoBlock xs
3543substituteIntoBlock [] = return []
0 commit comments