Switch to cmark-gfm

This commit is contained in:
Michael Snoyman 2018-06-21 19:19:41 +03:00
parent 77b0b3b396
commit 014114855b
No known key found for this signature in database
GPG Key ID: A048E8C057E86876
3 changed files with 18 additions and 18 deletions

View File

@ -67,7 +67,7 @@ dependencies:
- mono-traversable - mono-traversable
- time - time
- process - process
- markdown - cmark-gfm
- formatting - formatting
- blaze-html - blaze-html
- haddock-library - haddock-library

View File

@ -6,12 +6,13 @@ module Data.WebsiteContent
) where ) where
import ClassyPrelude.Yesod import ClassyPrelude.Yesod
import Text.Markdown (markdown, msXssProtect, msAddHeadingId) import CMarkGFM
import Data.GhcLinks import Data.GhcLinks
import Data.Aeson (withObject) import Data.Aeson (withObject)
import Data.Yaml import Data.Yaml
import System.FilePath (takeFileName) import System.FilePath (takeFileName)
import Types import Types
import Text.Blaze.Html (preEscapedToHtml)
data WebsiteContent = WebsiteContent data WebsiteContent = WebsiteContent
{ wcHomepage :: !Html { wcHomepage :: !Html
@ -49,13 +50,11 @@ loadWebsiteContent dir = do
>>= either throwIO (return . setFromList . map PackageName) >>= either throwIO (return . setFromList . map PackageName)
return WebsiteContent {..} return WebsiteContent {..}
where where
readHtml fp = fmap (preEscapedToMarkup . decodeUtf8 :: ByteString -> Html) readHtml fp = fmap preEscapedToMarkup $ readFileUtf8 $ dir </> fp
$ readFile $ dir </> fp readMarkdown fp = fmap (preEscapedToHtml . commonmarkToHtml
readMarkdown fp = fmap (markdown def [optSmart]
{ msXssProtect = False [extTable, extAutolink])
, msAddHeadingId = True $ readFileUtf8 $ dir </> fp
} . fromStrict . decodeUtf8)
$ readFile $ dir </> fp
loadPosts :: FilePath -> IO (Vector Post) loadPosts :: FilePath -> IO (Vector Post)
loadPosts dir = loadPosts dir =
@ -80,10 +79,10 @@ loadPosts dir =
_ -> error "Does not start with --- frontmatter" _ -> error "Does not start with --- frontmatter"
case Data.Yaml.decodeEither' $ encodeUtf8 frontmatter of case Data.Yaml.decodeEither' $ encodeUtf8 frontmatter of
Left e -> throwIO e Left e -> throwIO e
Right mkPost -> return $ mkPost slug $ markdown def Right mkPost -> return $ mkPost slug $ preEscapedToHtml $ commonmarkToHtml
{ msXssProtect = False [optSmart]
, msAddHeadingId = True [extTable, extAutolink]
} $ fromStrict body body
instance (slug ~ Text, body ~ Html) => FromJSON (slug -> body -> Post) where instance (slug ~ Text, body ~ Html) => FromJSON (slug -> body -> Post) where
parseJSON = withObject "Post" $ \o -> do parseJSON = withObject "Post" $ \o -> do

View File

@ -49,12 +49,12 @@ module Stackage.Database
import Web.PathPieces (toPathPiece) import Web.PathPieces (toPathPiece)
import qualified Codec.Archive.Tar as Tar import qualified Codec.Archive.Tar as Tar
import Database.Esqueleto.Internal.Language (From) import Database.Esqueleto.Internal.Language (From)
import Text.Markdown (markdown, msAddHeadingId, def) import CMarkGFM
import System.Directory (removeFile) import System.Directory (removeFile)
import Stackage.Database.Haddock import Stackage.Database.Haddock
import System.FilePath (takeBaseName, takeExtension) import System.FilePath (takeBaseName, takeExtension)
import ClassyPrelude.Conduit hiding (pi, FilePath, (</>)) import ClassyPrelude.Conduit hiding (pi, FilePath, (</>))
import Text.Blaze.Html (Html, toHtml) import Text.Blaze.Html (Html, toHtml, preEscapedToHtml)
import Yesod.Form.Fields (Textarea (..)) import Yesod.Form.Fields (Textarea (..))
import Stackage.Database.Types import Stackage.Database.Types
import System.Directory (getAppUserDataDirectory) import System.Directory (getAppUserDataDirectory)
@ -351,9 +351,10 @@ addPackage e =
fp = Tar.entryPath e fp = Tar.entryPath e
base = takeBaseName fp base = takeBaseName fp
renderContent txt "markdown" = markdown renderContent txt "markdown" = preEscapedToHtml $ commonmarkToHtml
(def { msAddHeadingId = True }) [optSmart, optSafe]
(fromStrict txt) [extTable, extAutolink]
txt
renderContent txt "haddock" = renderHaddock txt renderContent txt "haddock" = renderHaddock txt
renderContent txt _ = toHtml $ Textarea txt renderContent txt _ = toHtml $ Textarea txt