1
1
mirror of https://github.com/aelve/guide.git synced 2024-11-24 05:45:11 +03:00

Merge branch 'master'

into sectore/bridge-uid-more-type-safety
This commit is contained in:
Jens Krause 2017-10-08 17:58:58 +02:00
commit 9f4d6469f7
No known key found for this signature in database
GPG Key ID: 3B2FAFBCEFA5906D
11 changed files with 59 additions and 59 deletions

View File

@ -32,7 +32,7 @@ import Guide.Types.Core (Category(..), CategoryStatus(..), Item(..), ItemKind
, Trait, content, uid , Trait, content, uid
) )
import Guide.Utils (Uid(..), Url) import Guide.Utils (Uid(..), Url)
import Guide.Markdown (MarkdownBlock, MarkdownInline, MarkdownTree, mdHtml, mdText) import Guide.Markdown (MarkdownBlock, MarkdownInline, MarkdownTree, mdHtml, mdSource)
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
-- Routes -- Routes
@ -190,19 +190,19 @@ class ToCMardown md where toCMarkdown :: md -> CMarkdown
instance ToCMardown MarkdownInline where instance ToCMardown MarkdownInline where
toCMarkdown md = CMarkdown toCMarkdown md = CMarkdown
{ text = md^.mdText { text = md^.mdSource
, html = T.decodeUtf8 $ md^.mdHtml , html = T.decodeUtf8 $ md^.mdHtml
} }
instance ToCMardown MarkdownBlock where instance ToCMardown MarkdownBlock where
toCMarkdown md = CMarkdown toCMarkdown md = CMarkdown
{ text = md^.mdText { text = md^.mdSource
, html = T.decodeUtf8 $ md^.mdHtml , html = T.decodeUtf8 $ md^.mdHtml
} }
instance ToCMardown MarkdownTree where instance ToCMardown MarkdownTree where
toCMarkdown md = CMarkdown toCMarkdown md = CMarkdown
{ text = md^.mdText { text = md^.mdSource
, html = T.toStrict . renderText $ toHtml md , html = T.toStrict . renderText $ toHtml md
} }

View File

@ -133,7 +133,7 @@ setMethods = do
Spock.post (setRoute <//> categoryVar <//> "notes") $ \catId -> do Spock.post (setRoute <//> categoryVar <//> "notes") $ \catId -> do
original <- param' "original" original <- param' "original"
content' <- param' "content" content' <- param' "content"
modified <- view (notes.mdText) <$> dbQuery (GetCategory catId) modified <- view (notes.mdSource) <$> dbQuery (GetCategory catId)
if modified == original if modified == original
then do then do
category <- uncache (CacheCategoryNotes catId) $ do category <- uncache (CacheCategoryNotes catId) $ do
@ -196,7 +196,7 @@ setMethods = do
Spock.post (setRoute <//> itemVar <//> "description") $ \itemId -> do Spock.post (setRoute <//> itemVar <//> "description") $ \itemId -> do
original <- param' "original" original <- param' "original"
content' <- param' "content" content' <- param' "content"
modified <- view (description.mdText) <$> dbQuery (GetItem itemId) modified <- view (description.mdSource) <$> dbQuery (GetItem itemId)
if modified == original if modified == original
then do then do
item <- uncache (CacheItemDescription itemId) $ do item <- uncache (CacheItemDescription itemId) $ do
@ -213,7 +213,7 @@ setMethods = do
Spock.post (setRoute <//> itemVar <//> "ecosystem") $ \itemId -> do Spock.post (setRoute <//> itemVar <//> "ecosystem") $ \itemId -> do
original <- param' "original" original <- param' "original"
content' <- param' "content" content' <- param' "content"
modified <- view (ecosystem.mdText) <$> dbQuery (GetItem itemId) modified <- view (ecosystem.mdSource) <$> dbQuery (GetItem itemId)
if modified == original if modified == original
then do then do
item <- uncache (CacheItemEcosystem itemId) $ do item <- uncache (CacheItemEcosystem itemId) $ do
@ -230,7 +230,7 @@ setMethods = do
Spock.post (setRoute <//> itemVar <//> "notes") $ \itemId -> do Spock.post (setRoute <//> itemVar <//> "notes") $ \itemId -> do
original <- param' "original" original <- param' "original"
content' <- param' "content" content' <- param' "content"
modified <- view (notes.mdText) <$> dbQuery (GetItem itemId) modified <- view (notes.mdSource) <$> dbQuery (GetItem itemId)
if modified == original if modified == original
then do then do
item <- uncache (CacheItemNotes itemId) $ do item <- uncache (CacheItemNotes itemId) $ do
@ -248,7 +248,7 @@ setMethods = do
Spock.post (setRoute <//> itemVar <//> traitVar) $ \itemId traitId -> do Spock.post (setRoute <//> itemVar <//> traitVar) $ \itemId traitId -> do
original <- param' "original" original <- param' "original"
content' <- param' "content" content' <- param' "content"
modified <- view (content.mdText) <$> dbQuery (GetTrait itemId traitId) modified <- view (content.mdSource) <$> dbQuery (GetTrait itemId traitId)
if modified == original if modified == original
then do then do
trait <- uncache (CacheItemTraits itemId) $ do trait <- uncache (CacheItemTraits itemId) $ do

View File

@ -19,7 +19,7 @@ module Guide.Markdown
-- * Lenses -- * Lenses
mdHtml, mdHtml,
mdText, mdSource,
mdMarkdown, mdMarkdown,
mdIdPrefix, mdIdPrefix,
mdTree, mdTree,
@ -70,19 +70,19 @@ import Guide.Utils
data MarkdownInline = MarkdownInline { data MarkdownInline = MarkdownInline {
markdownInlineMdText :: Text, markdownInlineMdSource :: Text,
markdownInlineMdHtml :: ByteString, markdownInlineMdHtml :: ByteString,
markdownInlineMdMarkdown :: ![MD.Node] } markdownInlineMdMarkdown :: ![MD.Node] }
deriving (Generic, Data) deriving (Generic, Data)
data MarkdownBlock = MarkdownBlock { data MarkdownBlock = MarkdownBlock {
markdownBlockMdText :: Text, markdownBlockMdSource :: Text,
markdownBlockMdHtml :: ByteString, markdownBlockMdHtml :: ByteString,
markdownBlockMdMarkdown :: ![MD.Node] } markdownBlockMdMarkdown :: ![MD.Node] }
deriving (Generic, Data) deriving (Generic, Data)
data MarkdownTree = MarkdownTree { data MarkdownTree = MarkdownTree {
markdownTreeMdText :: Text, markdownTreeMdSource :: Text,
markdownTreeMdTree :: !(Document Text ByteString), markdownTreeMdTree :: !(Document Text ByteString),
markdownTreeMdIdPrefix :: Text, markdownTreeMdIdPrefix :: Text,
markdownTreeMdTOC :: Forest ([MD.Node], Text) } markdownTreeMdTOC :: Forest ([MD.Node], Text) }
@ -147,14 +147,14 @@ stringify = T.concat . map go
-- | Extract everything before the first heading. -- | Extract everything before the first heading.
-- --
-- Note that if you render 'mdText' of the produced Markdown block, it won't -- Note that if you render 'mdSource' of the produced Markdown block, it won't
-- necessarily parse into 'mdHtml' from the same block. It's because rendered -- necessarily parse into 'mdHtml' from the same block. It's because rendered
-- Markdown might depend on links that are defined further in the tree. -- Markdown might depend on links that are defined further in the tree.
extractPreface :: MarkdownTree -> MarkdownBlock extractPreface :: MarkdownTree -> MarkdownBlock
extractPreface = mkBlock . preface . view mdTree extractPreface = mkBlock . preface . view mdTree
where where
mkBlock x = MarkdownBlock { mkBlock x = MarkdownBlock {
markdownBlockMdText = getSource x, markdownBlockMdSource = getSource x,
markdownBlockMdHtml = renderMD (stripSource x), markdownBlockMdHtml = renderMD (stripSource x),
markdownBlockMdMarkdown = stripSource x } markdownBlockMdMarkdown = stripSource x }
@ -239,7 +239,7 @@ parseLink = either (Left . show) Right . parse p ""
toMarkdownInline :: Text -> MarkdownInline toMarkdownInline :: Text -> MarkdownInline
toMarkdownInline s = MarkdownInline { toMarkdownInline s = MarkdownInline {
markdownInlineMdText = s, markdownInlineMdSource = s,
markdownInlineMdHtml = html, markdownInlineMdHtml = html,
markdownInlineMdMarkdown = inlines } markdownInlineMdMarkdown = inlines }
where where
@ -248,7 +248,7 @@ toMarkdownInline s = MarkdownInline {
toMarkdownBlock :: Text -> MarkdownBlock toMarkdownBlock :: Text -> MarkdownBlock
toMarkdownBlock s = MarkdownBlock { toMarkdownBlock s = MarkdownBlock {
markdownBlockMdText = s, markdownBlockMdSource = s,
markdownBlockMdHtml = html, markdownBlockMdHtml = html,
markdownBlockMdMarkdown = doc } markdownBlockMdMarkdown = doc }
where where
@ -257,7 +257,7 @@ toMarkdownBlock s = MarkdownBlock {
toMarkdownTree :: Text -> Text -> MarkdownTree toMarkdownTree :: Text -> Text -> MarkdownTree
toMarkdownTree idPrefix s = MarkdownTree { toMarkdownTree idPrefix s = MarkdownTree {
markdownTreeMdText = s, markdownTreeMdSource = s,
markdownTreeMdIdPrefix = idPrefix, markdownTreeMdIdPrefix = idPrefix,
markdownTreeMdTree = tree, markdownTreeMdTree = tree,
markdownTreeMdTOC = toc } markdownTreeMdTOC = toc }
@ -297,23 +297,23 @@ slugifyDocument slugify doc = doc {
return sec{headingAnn = slug} return sec{headingAnn = slug}
instance Show MarkdownInline where instance Show MarkdownInline where
show = show . view mdText show = show . view mdSource
instance Show MarkdownBlock where instance Show MarkdownBlock where
show = show . view mdText show = show . view mdSource
instance Show MarkdownTree where instance Show MarkdownTree where
show = show . view mdText show = show . view mdSource
instance A.ToJSON MarkdownInline where instance A.ToJSON MarkdownInline where
toJSON md = A.object [ toJSON md = A.object [
"text" A..= (md^.mdText), "text" A..= (md^.mdSource),
"html" A..= T.toStrict (md^.mdHtml) ] "html" A..= T.toStrict (md^.mdHtml) ]
instance A.ToJSON MarkdownBlock where instance A.ToJSON MarkdownBlock where
toJSON md = A.object [ toJSON md = A.object [
"text" A..= (md^.mdText), "text" A..= (md^.mdSource),
"html" A..= T.toStrict (md^.mdHtml) ] "html" A..= T.toStrict (md^.mdHtml) ]
instance A.ToJSON MarkdownTree where instance A.ToJSON MarkdownTree where
toJSON md = A.object [ toJSON md = A.object [
"text" A..= (md^.mdText) ] "text" A..= (md^.mdSource) ]
instance ToHtml MarkdownInline where instance ToHtml MarkdownInline where
toHtmlRaw = toHtml toHtmlRaw = toHtml
@ -342,22 +342,22 @@ instance ToHtml MarkdownTree where
instance SafeCopy MarkdownInline where instance SafeCopy MarkdownInline where
version = 0 version = 0
kind = base kind = base
putCopy = contain . safePut . view mdText putCopy = contain . safePut . view mdSource
getCopy = contain $ toMarkdownInline <$> safeGet getCopy = contain $ toMarkdownInline <$> safeGet
instance SafeCopy MarkdownBlock where instance SafeCopy MarkdownBlock where
version = 0 version = 0
kind = base kind = base
putCopy = contain . safePut . view mdText putCopy = contain . safePut . view mdSource
getCopy = contain $ toMarkdownBlock <$> safeGet getCopy = contain $ toMarkdownBlock <$> safeGet
instance SafeCopy MarkdownTree where instance SafeCopy MarkdownTree where
version = 0 version = 0
kind = base kind = base
putCopy md = contain $ do putCopy md = contain $ do
safePut (md ^. mdIdPrefix) safePut (md ^. mdIdPrefix)
safePut (md ^. mdText) safePut (md ^. mdSource)
getCopy = contain $ getCopy = contain $
toMarkdownTree <$> safeGet <*> safeGet toMarkdownTree <$> safeGet <*> safeGet
-- | Is a piece of Markdown empty? -- | Is a piece of Markdown empty?
markdownNull :: HasMdText a Text => a -> Bool markdownNull :: HasMdSource a Text => a -> Bool
markdownNull = T.null . view mdText markdownNull = T.null . view mdSource

View File

@ -53,7 +53,7 @@ search query gs =
sortByRank [(SRItemEcosystem cat item, rank) sortByRank [(SRItemEcosystem cat item, rank)
| cat <- gs^.categories | cat <- gs^.categories
, item <- cat^.items , item <- cat^.items
, let rank = match query (item^.ecosystem.mdText) , let rank = match query (item^.ecosystem.mdSource)
, rank > 0 ] , rank > 0 ]
where where
sortByRank :: [(a, Int)] -> [a] sortByRank :: [(a, Int)] -> [a]

View File

@ -182,7 +182,7 @@ undoEdit (Edit'ChangeCategoryEnabledSections catId toEnable toDisable) = do
then return (Left "enabled-sections has been changed further") then return (Left "enabled-sections has been changed further")
else Right () <$ dbUpdate (ChangeCategoryEnabledSections catId toDisable toEnable) else Right () <$ dbUpdate (ChangeCategoryEnabledSections catId toDisable toEnable)
undoEdit (Edit'SetCategoryNotes catId old new) = do undoEdit (Edit'SetCategoryNotes catId old new) = do
now <- view (notes.mdText) <$> dbQuery (GetCategory catId) now <- view (notes.mdSource) <$> dbQuery (GetCategory catId)
if now /= new if now /= new
then return (Left "notes have been changed further") then return (Left "notes have been changed further")
else Right () <$ dbUpdate (SetCategoryNotes catId old) else Right () <$ dbUpdate (SetCategoryNotes catId old)
@ -207,22 +207,22 @@ undoEdit (Edit'SetItemKind itemId old new) = do
then return (Left "kind has been changed further") then return (Left "kind has been changed further")
else Right () <$ dbUpdate (SetItemKind itemId old) else Right () <$ dbUpdate (SetItemKind itemId old)
undoEdit (Edit'SetItemDescription itemId old new) = do undoEdit (Edit'SetItemDescription itemId old new) = do
now <- view (description.mdText) <$> dbQuery (GetItem itemId) now <- view (description.mdSource) <$> dbQuery (GetItem itemId)
if now /= new if now /= new
then return (Left "description has been changed further") then return (Left "description has been changed further")
else Right () <$ dbUpdate (SetItemDescription itemId old) else Right () <$ dbUpdate (SetItemDescription itemId old)
undoEdit (Edit'SetItemNotes itemId old new) = do undoEdit (Edit'SetItemNotes itemId old new) = do
now <- view (notes.mdText) <$> dbQuery (GetItem itemId) now <- view (notes.mdSource) <$> dbQuery (GetItem itemId)
if now /= new if now /= new
then return (Left "notes have been changed further") then return (Left "notes have been changed further")
else Right () <$ dbUpdate (SetItemNotes itemId old) else Right () <$ dbUpdate (SetItemNotes itemId old)
undoEdit (Edit'SetItemEcosystem itemId old new) = do undoEdit (Edit'SetItemEcosystem itemId old new) = do
now <- view (ecosystem.mdText) <$> dbQuery (GetItem itemId) now <- view (ecosystem.mdSource) <$> dbQuery (GetItem itemId)
if now /= new if now /= new
then return (Left "ecosystem has been changed further") then return (Left "ecosystem has been changed further")
else Right () <$ dbUpdate (SetItemEcosystem itemId old) else Right () <$ dbUpdate (SetItemEcosystem itemId old)
undoEdit (Edit'SetTraitContent itemId traitId old new) = do undoEdit (Edit'SetTraitContent itemId traitId old new) = do
now <- view (content.mdText) <$> dbQuery (GetTrait itemId traitId) now <- view (content.mdSource) <$> dbQuery (GetTrait itemId traitId)
if now /= new if now /= new
then return (Left "trait has been changed further") then return (Left "trait has been changed further")
else Right () <$ dbUpdate (SetTraitContent itemId traitId old) else Right () <$ dbUpdate (SetTraitContent itemId traitId old)

View File

@ -440,7 +440,7 @@ setCategoryGroup catId group' = do
setCategoryNotes :: Uid Category -> Text -> Acid.Update GlobalState (Edit, Category) setCategoryNotes :: Uid Category -> Text -> Acid.Update GlobalState (Edit, Category)
setCategoryNotes catId notes' = do setCategoryNotes catId notes' = do
oldNotes <- categoryById catId . notes <<.= toMarkdownBlock notes' oldNotes <- categoryById catId . notes <<.= toMarkdownBlock notes'
let edit = Edit'SetCategoryNotes catId (oldNotes ^. mdText) notes' let edit = Edit'SetCategoryNotes catId (oldNotes ^. mdSource) notes'
(edit,) <$> use (categoryById catId) (edit,) <$> use (categoryById catId)
setCategoryStatus :: Uid Category -> CategoryStatus -> Acid.Update GlobalState (Edit, Category) setCategoryStatus :: Uid Category -> CategoryStatus -> Acid.Update GlobalState (Edit, Category)
@ -516,7 +516,7 @@ setItemDescription itemId description' = do
oldDescr <- itemById itemId . description <<.= oldDescr <- itemById itemId . description <<.=
toMarkdownBlock description' toMarkdownBlock description'
let edit = Edit'SetItemDescription itemId let edit = Edit'SetItemDescription itemId
(oldDescr ^. mdText) description' (oldDescr ^. mdSource) description'
(edit,) <$> use (itemById itemId) (edit,) <$> use (itemById itemId)
setItemNotes :: Uid Item -> Text -> Acid.Update GlobalState (Edit, Item) setItemNotes :: Uid Item -> Text -> Acid.Update GlobalState (Edit, Item)
@ -524,7 +524,7 @@ setItemNotes itemId notes' = do
let pref = "item-notes-" <> uidToText itemId <> "-" let pref = "item-notes-" <> uidToText itemId <> "-"
oldNotes <- itemById itemId . notes <<.= oldNotes <- itemById itemId . notes <<.=
toMarkdownTree pref notes' toMarkdownTree pref notes'
let edit = Edit'SetItemNotes itemId (oldNotes ^. mdText) notes' let edit = Edit'SetItemNotes itemId (oldNotes ^. mdSource) notes'
(edit,) <$> use (itemById itemId) (edit,) <$> use (itemById itemId)
setItemEcosystem :: Uid Item -> Text -> Acid.Update GlobalState (Edit, Item) setItemEcosystem :: Uid Item -> Text -> Acid.Update GlobalState (Edit, Item)
@ -532,7 +532,7 @@ setItemEcosystem itemId ecosystem' = do
oldEcosystem <- itemById itemId . ecosystem <<.= oldEcosystem <- itemById itemId . ecosystem <<.=
toMarkdownBlock ecosystem' toMarkdownBlock ecosystem'
let edit = Edit'SetItemEcosystem itemId let edit = Edit'SetItemEcosystem itemId
(oldEcosystem ^. mdText) ecosystem' (oldEcosystem ^. mdSource) ecosystem'
(edit,) <$> use (itemById itemId) (edit,) <$> use (itemById itemId)
setTraitContent :: Uid Item -> Uid Trait -> Text -> Acid.Update GlobalState (Edit, Trait) setTraitContent :: Uid Item -> Uid Trait -> Text -> Acid.Update GlobalState (Edit, Trait)
@ -540,7 +540,7 @@ setTraitContent itemId traitId content' = do
oldContent <- itemById itemId . traitById traitId . content <<.= oldContent <- itemById itemId . traitById traitId . content <<.=
toMarkdownInline content' toMarkdownInline content'
let edit = Edit'SetTraitContent itemId traitId let edit = Edit'SetTraitContent itemId traitId
(oldContent ^. mdText) content' (oldContent ^. mdSource) content'
(edit,) <$> use (itemById itemId . traitById traitId) (edit,) <$> use (itemById itemId . traitById traitId)
-- delete -- delete

View File

@ -752,7 +752,7 @@ renderSearchResult r = do
a_ [class_ "category-link", href_ (categoryLink cat)] $ a_ [class_ "category-link", href_ (categoryLink cat)] $
toHtml (cat^.title) toHtml (cat^.title)
div_ [class_ "category-description notes-like"] $ div_ [class_ "category-description notes-like"] $
toHtml (extractPreface $ toMarkdownTree "" $ cat^.notes.mdText) toHtml (extractPreface $ toMarkdownTree "" $ cat^.notes.mdSource)
SRItem cat item -> do SRItem cat item -> do
a_ [class_ "category-link in-item-sr", href_ (categoryLink cat)] $ a_ [class_ "category-link in-item-sr", href_ (categoryLink cat)] $
toHtml (cat^.title) toHtml (cat^.title)

View File

@ -182,6 +182,6 @@ renderCategoryNotes category = cached (CacheCategoryNotes (category^.uid)) $ do
[rows_ "10", class_ " editor "] [rows_ "10", class_ " editor "]
contents contents
(\val -> JS.submitCategoryNotes (\val -> JS.submitCategoryNotes
(this, category^.uid, category^.notes.mdText, val)) (this, category^.uid, category^.notes.mdSource, val))
(JS.switchSection (this, "normal" :: Text)) (JS.switchSection (this, "normal" :: Text))
"or press Ctrl+Enter to save" "or press Ctrl+Enter to save"

View File

@ -177,7 +177,7 @@ renderItemEcosystem item = cached (CacheItemEcosystem (item^.uid)) $ do
[rows_ "3", class_ " editor "] [rows_ "3", class_ " editor "]
(item^.ecosystem) (item^.ecosystem)
(\val -> JS.submitItemEcosystem (\val -> JS.submitItemEcosystem
(this, item^.uid, item^.ecosystem.mdText, val)) (this, item^.uid, item^.ecosystem.mdSource, val))
(JS.switchSection (this, "normal" :: Text)) (JS.switchSection (this, "normal" :: Text))
"or press Ctrl+Enter to save" "or press Ctrl+Enter to save"
@ -294,7 +294,7 @@ renderItemNotes category item = cached (CacheItemNotes (item^.uid)) $ do
textareaUid <- randomLongUid textareaUid <- randomLongUid
contents <- if markdownNull (item^.notes) contents <- if markdownNull (item^.notes)
then liftIO $ T.readFile "static/item-notes-template.md" then liftIO $ T.readFile "static/item-notes-template.md"
else return (item^.notes.mdText) else return (item^.notes.mdSource)
let buttons = do let buttons = do
textButton "collapse notes" $ textButton "collapse notes" $
JS.switchSection (this, "collapsed" :: Text) JS.switchSection (this, "collapsed" :: Text)

View File

@ -187,7 +187,7 @@ markdownEditor
-> JS -- ^ “Cancel” handler -> JS -- ^ “Cancel” handler
-> Text -- ^ Instruction (e.g. “press Ctrl+Enter to save”) -> Text -- ^ Instruction (e.g. “press Ctrl+Enter to save”)
-> HtmlT m () -> HtmlT m ()
markdownEditor attr (view mdText -> s) submit cancel instr = do markdownEditor attr (view mdSource -> s) submit cancel instr = do
textareaUid <- randomLongUid textareaUid <- randomLongUid
let val = JS $ "document.getElementById(\""+|textareaUid|+"\").value" let val = JS $ "document.getElementById(\""+|textareaUid|+"\").value"
-- Autocomplete has to be turned off thanks to -- Autocomplete has to be turned off thanks to
@ -219,7 +219,7 @@ smallMarkdownEditor
-> Maybe JS -- ^ “Cancel” handler (if “Cancel” is needed) -> Maybe JS -- ^ “Cancel” handler (if “Cancel” is needed)
-> Text -- ^ Instruction (e.g. “press Enter to add”) -> Text -- ^ Instruction (e.g. “press Enter to add”)
-> HtmlT m () -> HtmlT m ()
smallMarkdownEditor attr (view mdText -> s) submit mbCancel instr = do smallMarkdownEditor attr (view mdSource -> s) submit mbCancel instr = do
textareaId <- randomLongUid textareaId <- randomLongUid
let val = JS $ "document.getElementById(\""+|textareaId|+"\").value" let val = JS $ "document.getElementById(\""+|textareaId|+"\").value"
textarea_ ([class_ "fullwidth", uid_ textareaId, autocomplete_ "off"] ++ textarea_ ([class_ "fullwidth", uid_ textareaId, autocomplete_ "off"] ++

View File

@ -28,7 +28,7 @@ import Guide.Markdown
tests :: Spec tests :: Spec
tests = describe "Markdown" $ do tests = describe "Markdown" $ do
allMarkdowns $ \convert -> do allMarkdowns $ \convert -> do
it "has mdText filled accurately" $ do it "has mdSource filled accurately" $ do
for_ mdBlockExamples $ \s -> for_ mdBlockExamples $ \s ->
s `shouldBe` fst (convert s) s `shouldBe` fst (convert s)
it "only has allowed tags" $ do it "only has allowed tags" $ do
@ -149,15 +149,15 @@ htmlToText = T.toStrict . renderText . toHtml
allMarkdowns :: ((Text -> (Text, Text)) -> Spec) -> Spec allMarkdowns :: ((Text -> (Text, Text)) -> Spec) -> Spec
allMarkdowns f = do allMarkdowns f = do
describe "inline MD" $ describe "inline MD" $
f ((view mdText &&& htmlToText) . toMarkdownInline) f ((view mdSource &&& htmlToText) . toMarkdownInline)
blockMarkdowns f blockMarkdowns f
blockMarkdowns :: ((Text -> (Text, Text)) -> Spec) -> Spec blockMarkdowns :: ((Text -> (Text, Text)) -> Spec) -> Spec
blockMarkdowns f = do blockMarkdowns f = do
describe "block MD" $ describe "block MD" $
f ((view mdText &&& htmlToText) . toMarkdownBlock) f ((view mdSource &&& htmlToText) . toMarkdownBlock)
describe "block+toc MD" $ describe "block+toc MD" $
f ((view mdText &&& htmlToText) . toMarkdownTree "") f ((view mdSource &&& htmlToText) . toMarkdownTree "")
mdInlineExamples :: [Text] mdInlineExamples :: [Text]
mdInlineExamples = [ mdInlineExamples = [