blaze-html-truncate 0.2.0.1 → 0.2.0.2
raw patch · 2 files changed
+19/−4 lines, 2 filesdep ~blaze-markupPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: blaze-markup
API changes (from Hackage documentation)
Files
- Text/Blaze/Truncate.hs +17/−2
- blaze-html-truncate.cabal +2/−2
Text/Blaze/Truncate.hs view
@@ -52,7 +52,7 @@ (ts',ts'') -> ((TS.TagText str') : ts', (TS.TagText str'') : ts'') dropWhileEndPreEscapedHtml :: SL.StringLike str => (Char -> Bool) -> str -> str-dropWhileEndPreEscapedHtml p txt = (TS.renderTags . reverse . (go 0) . reverse . TS.parseTags) txt+dropWhileEndPreEscapedHtml p txt = (TS.renderTags . reverse . filterEmptyTags . (go 0) . reverse . TS.parseTags) txt where go :: (SL.StringLike str) => Int -> [TS.Tag str] -> [TS.Tag str] go _ [] = []@@ -66,13 +66,16 @@ else case dropWhileEndSL p str of str' -> if not (SL.strNull str') then (TS.TagText str') : ts else go openTgs ts+ filterEmptyTags ((TS.TagClose _) : (TS.TagOpen _ _) : ts) = filterEmptyTags ts+ filterEmptyTags (t : ts) = t : (filterEmptyTags ts)+ filterEmptyTags [] = [] -- | Truncate the given HTML to a certain length, preserving tags. Returns the truncated Html or `Nothing` if no truncation occured. -- Words are preserved, so if the truncated text ends within some word, that whole word is cut. truncateHtml :: Int -- ^ The amount of characters (not counting tags) which the truncated text should have at most -> Markup -- ^ The HTML to truncate -> Maybe Markup -- ^ `Just` the truncated HTML or `Nothing` if no truncation occured-truncateHtml n html = case go n html of Tagged n' html' -> if n' <= 0 then Just html' else Nothing+truncateHtml n html = case go n html of Tagged n' html' -> if n' <= 0 then filterEmptyTags html' else Nothing where go :: Int -> MarkupM b -> Tagged (MarkupM b) go i (Parent t open close content) = fmap (Parent t open close) (go i content)@@ -84,6 +87,18 @@ Tagged j h1' -> fmap (Append h1') (go j h2) go i Empty = Tagged i Empty go i (Content content) = fmap Content (truncateChoiceString i content)+ + -- filter _trailing_ empty tags+ filterEmptyTags :: MarkupM a -> Maybe (MarkupM b)+ filterEmptyTags (Parent t open close content) = fmap (Parent t open close) (filterEmptyTags content)+ filterEmptyTags (Leaf t begin end) = Nothing+ filterEmptyTags (AddAttribute t key value h) = fmap (AddAttribute t key value) (filterEmptyTags h)+ filterEmptyTags (AddCustomAttribute key value h) = fmap (AddCustomAttribute key value) (filterEmptyTags h)+ filterEmptyTags (Append h1 h2) = case filterEmptyTags h2 of+ Nothing -> filterEmptyTags h1+ Just h2' -> Just (Append h1 h2')+ filterEmptyTags Empty = Nothing+ filterEmptyTags (Content content) = if (length' content) == 0 then Nothing else Just (Content content) splitAtPreEscaped' :: Int -> ChoiceString -> (ChoiceString, ChoiceString) splitAtPreEscaped' i str | i <= 0 = (EmptyChoiceString, str)
blaze-html-truncate.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: blaze-html-truncate-version: 0.2.0.1+version: 0.2.0.2 synopsis: A truncator for blaze-html description: This package provides a simple function to truncate HTML, preserving tags and preventing cut-off words. homepage: http://github.com/mruegenberg/blaze-html-truncate@@ -23,7 +23,7 @@ exposed-modules: Text.Blaze.Truncate -- other-modules: build-depends: base >= 4 && < 5- , blaze-markup >= 0.5.0.0+ , blaze-markup >= 0.5.1.0 , bytestring >= 0.9 , text >= 0.10 , tagsoup >= 0.10