Permalink
Browse files

Added splice fro highlighting

  • Loading branch information...
1 parent 8b845c4 commit e99af1e1d423ff1e75866046e078a202ca3b0983 @Palmik committed Mar 22, 2011
Showing with 17 additions and 0 deletions.
  1. +16 −0 src/Controller/Paste.hs
  2. +1 −0 src/Site.hs
View
16 src/Controller/Paste.hs
@@ -2,11 +2,16 @@
module Controller.Paste
( recentPastesSplice
+, highlightAsSplice
) where
import qualified Data.Text as T
import qualified Text.XmlHtml as X
+import Text.XHtml.Strict (renderHtmlFragment)
import Control.Monad.Trans
+import Control.Monad (liftM, liftM2)
+import Data.Maybe
+import Text.Highlighting.Kate
import Text.Templating.Heist
@@ -21,6 +26,17 @@ pasteParts p = map applyAndPack [ ("title", pasteTitle)
, ("language", pasteLanguage) ]
where applyAndPack (x, f) = (T.pack x, T.pack $ f p)
+highlightAsSplice :: Splice Application
+highlightAsSplice = do
+ l <- liftM2 X.getAttribute (return $ T.pack "lang") getParamNode
+ c <- liftM (X.nodeText . head . X.childNodes) getParamNode
+ case l of
+ Nothing -> return [X.TextNode c]
+ _ -> case highlightAs (T.unpack $ fromJust l) (T.unpack c) of
+ Left _ -> return [X.TextNode c]
+ Right h -> return [X.TextNode . T.pack . renderHtmlFragment $ formatAsXHtml [OptNumberLines] (T.unpack $ fromJust l) h]
+
+
recentPastesSplice :: Splice Application
recentPastesSplice = do
ps <- lift getRecentPastesDummy
View
1 src/Site.hs
@@ -56,6 +56,7 @@ pastes = ifTop $ heistLocal (bindSplices pastesSplices) $ render "pastes"
where
pastesSplices =
[ ("recent-pastes", recentPastesSplice)
+ , ("highlight", highlightAsSplice)
]
------------------------------------------------------------------------------

0 comments on commit e99af1e

Please sign in to comment.