1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-23 12:52:31 +03:00

[GD-10] improve extractFirstParagraph function

This commit is contained in:
Juan Bono 2017-04-25 07:40:13 -03:00
parent 01bd067bdb
commit 49180082c2
2 changed files with 9 additions and 1 deletions

View File

@ -31,6 +31,7 @@ module Guide.Markdown
-- * Misc -- * Misc
renderMD, renderMD,
markdownNull, markdownNull,
extractFirstParagraph,
) )
where where
@ -139,6 +140,12 @@ stringify = T.concat . map go
HTML_BLOCK _ -> "" HTML_BLOCK _ -> ""
HTML_INLINE _ -> "" HTML_INLINE _ -> ""
-- | Extracts the first paragraph.
extractFirstParagraph :: Text -> MarkdownBlock
extractFirstParagraph = toMarkdownBlock . annSource . preface . toMdTree
where
toMdTree = markdownBlockWithTOCMdTree . toMarkdownBlockWithTOC ""
-- | Flatten Markdown by concatenating all block elements. -- | Flatten Markdown by concatenating all block elements.
extractInlines :: [MD.Node] -> [MD.Node] extractInlines :: [MD.Node] -> [MD.Node]
extractInlines = concatMap go extractInlines = concatMap go

View File

@ -46,7 +46,6 @@ import Data.IP
import Data.Time.Format.Human import Data.Time.Format.Human
-- Mustache (templates) -- Mustache (templates)
import qualified Data.Aeson as A import qualified Data.Aeson as A
import Guide.Config import Guide.Config
import Guide.State import Guide.State
import Guide.Types import Guide.Types
@ -701,6 +700,8 @@ renderSearchResult r = do
SRCategory cat -> do SRCategory cat -> 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"] $
toHtml (extractFirstParagraph $ cat^.notes^.mdText)
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)