mirror of
https://github.com/aelve/guide.git
synced 2024-12-23 21:02:13 +03:00
[GD-10] improve extractFirstParagraph function
This commit is contained in:
parent
01bd067bdb
commit
49180082c2
@ -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
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user