From 8f1b6b5c4e34c59d7ceb19ef2fe552a104d7bf62 Mon Sep 17 00:00:00 2001 From: "\"Vincent Ambo ext:(%22)" Date: Sun, 28 Apr 2013 14:26:45 +0200 Subject: * added Markdown support --- TazBlog.cabal | 3 ++- src/Blog.hs | 35 +++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/TazBlog.cabal b/TazBlog.cabal index ed1f886a19ea..63f9ad75e015 100644 --- a/TazBlog.cabal +++ b/TazBlog.cabal @@ -36,4 +36,5 @@ Executable tazblog rss, recaptcha, hamlet, - shakespeare-css + shakespeare-css, + markdown diff --git a/src/Blog.hs b/src/Blog.hs index d3382357fc2b..9c66a20101c8 100644 --- a/src/Blog.hs +++ b/src/Blog.hs @@ -5,14 +5,17 @@ module Blog where import Control.Monad (when, unless) import Data.Data (Data, Typeable) import Data.List (intersperse) +import Data.Maybe (fromJust) import Data.Monoid (mempty) import Data.Text (Text, append, pack, empty) +import Data.Text.Lazy (fromStrict) import Data.Time import Network.Captcha.ReCaptcha import System.Locale (defaultTimeLocale) import Text.Blaze.Html (preEscapedToHtml) import Text.Hamlet -import Text.Lucius +import Text.Lucius +import Text.Markdown import Locales import BlogDB @@ -28,11 +31,16 @@ replace x y = map (\z -> if z == x then y else z) show' :: Show a => a -> Text show' = pack . show +-- |After this time all entries are Markdown +markdownCutoff :: UTCTime +markdownCutoff = fromJust $ parseTime defaultTimeLocale "%s" "1367149834" + data BlogURL = BlogURL -- blog CSS (admin is still static) stylesheetSource = $(luciusFile "res/blogstyle.lucius") blogStyle = renderCssUrl undefined stylesheetSource + -- blog HTML blogTemplate :: BlogLang -> Text -> Html -> Html blogTemplate lang t_append body = [shamlet| @@ -78,6 +86,12 @@ showFooter l v = [shamlet| #{noticeText l} |] +isEntryMarkdown :: Entry -> Bool +isEntryMarkdown e = edate e > markdownCutoff + +renderEntryMarkdown :: Text -> Html +renderEntryMarkdown = markdown def {msXssProtect = False} . fromStrict + renderEntries :: Bool -> [Entry] -> Text -> Maybe Html -> Html renderEntries showAll entries topText footerLinks = [shamlet| #{topText} @@ -85,8 +99,13 @@ renderEntries showAll entries topText footerLinks = [shamlet|