Permalink
Browse files

Added Subst plugin (due mostly to gwern).

  • Loading branch information...
1 parent 112e8b0 commit 967916cf982dc97ee598e56c90a54faee766dd20 @jgm committed Feb 27, 2010
Showing with 28 additions and 0 deletions.
  1. +1 −0 gitit.cabal
  2. +27 −0 plugins/Subst.hs
View
@@ -77,6 +77,7 @@ data-files: data/static/css/screen.css, data/static/css/print.css,
plugins/WebArchiver.hs,
plugins/ShowUser.hs,
plugins/Signature.hs,
+ plugins/Subst.hs,
CHANGES, README.markdown, YUI-LICENSE, BLUETRIP-LICENSE, TANGOICONS
Flag plugins
View
@@ -0,0 +1,27 @@
+-- Usage: a paragraph containing just [My page](!subst)
+-- will be replaced by the contents of My page.
+--
+-- Limitations: it is assumed that My page is
+-- formatted with markdown, and contains no metadata.
+
+module Subst (plugin) where
+
+import Data.FileStore (retrieve)
+import Text.Pandoc (defaultParserState, readMarkdown)
+import Network.Gitit.ContentTransformer (inlinesToString)
+import Network.Gitit.Interface
+import Network.Gitit.Framework (filestoreFromConfig)
+
+plugin :: Plugin
+plugin = mkPageTransformM substituteIntoBlock
+
+substituteIntoBlock :: [Block] -> PluginM [Block]
+substituteIntoBlock (Para (Link ref ("!subst", _):_ ):xs) =
+ do let target = inlinesToString ref ++ ".page"
+ cfg <- askConfig
+ let fs = filestoreFromConfig cfg
+ article <- liftIO (retrieve fs target Nothing)
+ let (Pandoc _ content) = readMarkdown defaultParserState article
+ (content ++) `fmap` substituteIntoBlock xs
+substituteIntoBlock (x:xs) = (x:) `fmap` substituteIntoBlock xs
+substituteIntoBlock [] = return []

0 comments on commit 967916c

Please sign in to comment.