From 99959b68e9ebbe48e952ce915368d6fc88a7d41a Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 4 Jan 2007 01:04:56 +0000 Subject: + Improved text wrapping algorithm in markdown, docbook, and RST writers. LineBreaks no longer cause ugly wrapping in Markdown output. + Replaced splitBySpace with the more general, polymorphic function splitBy (in Text/Pandoc/Shared). git-svn-id: https://pandoc.googlecode.com/svn/trunk@411 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Shared.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/Text/Pandoc/Shared.hs') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index adc2621f3..d4687b10e 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -52,7 +52,7 @@ module Text.Pandoc.Shared ( -- * Pandoc block list processing consolidateList, isNoteBlock, - splitBySpace, + splitBy, normalizeSpaces, compactify, generateReference, @@ -274,10 +274,13 @@ removeTrailingSpace = reverse . removeLeadingSpace . reverse stripFirstAndLast str = drop 1 $ take ((length str) - 1) str --- | Split list of inlines into groups separated by a space. -splitBySpace :: [Inline] -> [[Inline]] -splitBySpace lst = filter (\a -> (/= Space) (head a)) - (groupBy (\a b -> (/= Space) a && (/= Space) b) lst) +-- | Split list into groups separated by sep. +splitBy :: (Eq a) => a -> [a] -> [[a]] +splitBy _ [] = [] +splitBy sep lst = + let (first, rest) = break (== sep) lst + rest' = dropWhile (== sep) rest in + first:(splitBy sep rest') -- | Normalize a list of inline elements: remove leading and trailing -- @Space@ elements, and collapse double @Space@s into singles. -- cgit v1.2.3