8
8
9
9
module Subst (plugin ) where
10
10
11
- import "MonadCatchIO -mtl" Control.Monad.CatchIO (try )
11
+ -- import "MonadCatchIO-mtl" Control.Monad.CatchIO (try)
12
+ import Control.Monad.Catch (try )
12
13
import Data.FileStore (FileStoreError , retrieve )
13
14
import Text.Pandoc (def , readMarkdown )
14
15
import Network.Gitit.ContentTransformer (inlinesToString )
@@ -19,17 +20,24 @@ plugin :: Plugin
19
20
plugin = mkPageTransformM substituteIntoBlock
20
21
21
22
substituteIntoBlock :: [Block ] -> PluginM [Block ]
22
- substituteIntoBlock ((Para [Link ref (" !subst" , _)]): xs) =
23
+ substituteIntoBlock ((Para [Link attr ref (" !subst" , _)]): xs) =
23
24
do let target = inlinesToString ref
24
25
cfg <- askConfig
25
26
let fs = filestoreFromConfig cfg
26
27
article <- try $ liftIO (retrieve fs (target ++ " .page" ) Nothing )
27
28
case article :: Either FileStoreError String of
28
29
Left _ -> let txt = Str (" [" ++ target ++ " ](!subst)" )
29
30
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)]
31
32
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
+
34
42
substituteIntoBlock (x: xs) = (x: ) `fmap` substituteIntoBlock xs
35
43
substituteIntoBlock [] = return []
0 commit comments