Skip to content

Commit d0031cf

Browse files
authored
Merge pull request #592 from icefoxen/subst-plugin-fix
Fixed Subst plugin.
2 parents 34ff594 + 8a8d33f commit d0031cf

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

plugins/Subst.hs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
module 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)
1213
import Data.FileStore (FileStoreError, retrieve)
1314
import Text.Pandoc (def, readMarkdown)
1415
import Network.Gitit.ContentTransformer (inlinesToString)
@@ -19,17 +20,24 @@ plugin :: Plugin
1920
plugin = mkPageTransformM substituteIntoBlock
2021

2122
substituteIntoBlock :: [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+
3442
substituteIntoBlock (x:xs) = (x:) `fmap` substituteIntoBlock xs
3543
substituteIntoBlock [] = return []

0 commit comments

Comments
 (0)