git.iko.soy/typeable/pandoc
on master help sign in
Removed normalizeSpaces from Text.Pandoc.Shared.
ba78b75John MacFarlane
src/Text/Pandoc/Readers/RST.hs+6
@@ -141,6 +141,12 @@ metaFromDefList ds meta = adjustAuthors $ foldr f meta ds
141 splitAuthors x = x
141 splitAuthors x = x
142 splitAuthors' = map normalizeSpaces .
142 splitAuthors' = map normalizeSpaces .
143 splitOnSemi . concatMap factorSemi
143 splitOnSemi . concatMap factorSemi
144+ normalizeSpaces = reverse . dropWhile isSp . reverse .
145+ dropWhile isSp
146+ isSp Space = True
147+ isSp SoftBreak = True
148+ isSp LineBreak = True
149+ isSp _ = False
144 splitOnSemi = splitBy (==Str ";")
150 splitOnSemi = splitBy (==Str ";")
145 factorSemi (Str []) = []
151 factorSemi (Str []) = []
146 factorSemi (Str s) = case break (==';') s of
152 factorSemi (Str s) = case break (==';') s of
src/Text/Pandoc/Shared.hs−20
@@ -53,7 +53,6 @@ module Text.Pandoc.Shared (
53 normalizeDate,
53 normalizeDate,
54 -- * Pandoc block and inline list processing
54 -- * Pandoc block and inline list processing
55 orderedListMarkers,
55 orderedListMarkers,
56− normalizeSpaces,
57 extractSpaces,
56 extractSpaces,
58 removeFormatting,
57 removeFormatting,
59 deNote,
58 deNote,
@@ -354,25 +353,6 @@ orderedListMarkers (start, numstyle, numdelim) =
354 TwoParens -> "(" ++ str ++ ")"
353 TwoParens -> "(" ++ str ++ ")"
355 in map inDelim nums
354 in map inDelim nums
356
355
357−-- | Normalize a list of inline elements: remove leading and trailing
358−-- @Space@, @LineBreak@, and @SoftBreak@ elements, collapse double
359−-- @Space@s into singles, and remove empty @Str@ elements.
360−normalizeSpaces :: [Inline] -> [Inline]
361−normalizeSpaces = cleanup . dropWhile isSpaceOrEmpty
362− where cleanup [] = []
363− cleanup (Space:rest) = case dropWhile isSpaceOrEmpty rest of
364− [] -> []
365− (x:xs) -> Space : x : cleanup xs
366− cleanup ((Str ""):rest) = cleanup rest
367− cleanup (x:rest) = x : cleanup rest
368−
369−isSpaceOrEmpty :: Inline -> Bool
370−isSpaceOrEmpty Space = True
371−isSpaceOrEmpty SoftBreak = True
372−isSpaceOrEmpty LineBreak = True
373−isSpaceOrEmpty (Str "") = True
374−isSpaceOrEmpty _ = False
375−
376-- | Extract the leading and trailing spaces from inside an inline element
356-- | Extract the leading and trailing spaces from inside an inline element
377-- and place them outside the element. SoftBreaks count as Spaces for
357-- and place them outside the element. SoftBreaks count as Spaces for
378-- these purposes.
358-- these purposes.
src/Text/Pandoc/Writers/RST.hs+3−3
@@ -36,7 +36,7 @@ import Data.Char (isSpace, toLower)
36import Data.List (intersperse, isPrefixOf, stripPrefix, transpose)
36import Data.List (intersperse, isPrefixOf, stripPrefix, transpose)
37import Data.Maybe (fromMaybe)
37import Data.Maybe (fromMaybe)
38import Network.URI (isURI)
38import Network.URI (isURI)
39−import Text.Pandoc.Builder (deleteMeta)
39+import qualified Text.Pandoc.Builder as B
40import Text.Pandoc.Class (PandocMonad)
40import Text.Pandoc.Class (PandocMonad)
41import Text.Pandoc.Definition
41import Text.Pandoc.Definition
42import Text.Pandoc.ImageSize
42import Text.Pandoc.ImageSize
@@ -81,7 +81,7 @@ pandocToRST (Pandoc meta blocks) = do
81 metadata <- metaToJSON opts
81 metadata <- metaToJSON opts
82 (fmap (render colwidth) . blockListToRST)
82 (fmap (render colwidth) . blockListToRST)
83 (fmap (trimr . render colwidth) . inlineListToRST)
83 (fmap (trimr . render colwidth) . inlineListToRST)
84− $ deleteMeta "title" $ deleteMeta "subtitle" meta
84+ $ B.deleteMeta "title" $ B.deleteMeta "subtitle" meta
85 body <- blockListToRST' True $ case writerTemplate opts of
85 body <- blockListToRST' True $ case writerTemplate opts of
86 Just _ -> normalizeHeadings 1 blocks
86 Just _ -> normalizeHeadings 1 blocks
87 Nothing -> blocks
87 Nothing -> blocks
@@ -504,7 +504,7 @@ inlineToRST (Link _ [Image attr alt (imgsrc,imgtit)] (src, _tit)) = do
504 return $ "|" <> label <> "|"
504 return $ "|" <> label <> "|"
505inlineToRST (Link _ txt (src, tit)) = do
505inlineToRST (Link _ txt (src, tit)) = do
506 useReferenceLinks <- gets $ writerReferenceLinks . stOptions
506 useReferenceLinks <- gets $ writerReferenceLinks . stOptions
507− linktext <- inlineListToRST $ normalizeSpaces txt
507+ linktext <- inlineListToRST $ B.toList . B.trimInlines . B.fromList $ txt
508 if useReferenceLinks
508 if useReferenceLinks
509 then do refs <- gets stLinks
509 then do refs <- gets stLinks
510 case lookup txt refs of
510 case lookup txt refs of