git.iko.soy/typeable/pandoc
on master help sign in
Removed normalizeSpaces from Text.Pandoc.Shared.

Rewrote functions in RST reader and writer to avoid the need for it. Closes #1530.

commitba78b75146d9d02de64b400a78402aac884f0644 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 10 Mar 2017, 20:44 (10 years ago) parenta197dc9
3 files changed+9−23
src/Text/Pandoc/Readers/RST.hs+6 src/Text/Pandoc/Shared.hs−20 src/Text/Pandoc/Writers/RST.hs+3−3
src/Text/Pandoc/Readers/RST.hs+6
@@ -141,6 +141,12 @@ metaFromDefList ds meta = adjustAuthors $ foldr f meta ds
141141 splitAuthors x = x
142142 splitAuthors' = map normalizeSpaces .
143143 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
144150 splitOnSemi = splitBy (==Str ";")
145151 factorSemi (Str []) = []
146152 factorSemi (Str s) = case break (==';') s of
src/Text/Pandoc/Shared.hs−20
@@ -53,7 +53,6 @@ module Text.Pandoc.Shared (
5353 normalizeDate,
5454 -- * Pandoc block and inline list processing
5555 orderedListMarkers,
56− normalizeSpaces,
5756 extractSpaces,
5857 removeFormatting,
5958 deNote,
@@ -354,25 +353,6 @@ orderedListMarkers (start, numstyle, numdelim) =
354353 TwoParens -> "(" ++ str ++ ")"
355354 in map inDelim nums
356355
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−
376356-- | Extract the leading and trailing spaces from inside an inline element
377357-- and place them outside the element. SoftBreaks count as Spaces for
378358-- these purposes.
src/Text/Pandoc/Writers/RST.hs+3−3
@@ -36,7 +36,7 @@ import Data.Char (isSpace, toLower)
3636import Data.List (intersperse, isPrefixOf, stripPrefix, transpose)
3737import Data.Maybe (fromMaybe)
3838import Network.URI (isURI)
39−import Text.Pandoc.Builder (deleteMeta)
39+import qualified Text.Pandoc.Builder as B
4040import Text.Pandoc.Class (PandocMonad)
4141import Text.Pandoc.Definition
4242import Text.Pandoc.ImageSize
@@ -81,7 +81,7 @@ pandocToRST (Pandoc meta blocks) = do
8181 metadata <- metaToJSON opts
8282 (fmap (render colwidth) . blockListToRST)
8383 (fmap (trimr . render colwidth) . inlineListToRST)
84− $ deleteMeta "title" $ deleteMeta "subtitle" meta
84+ $ B.deleteMeta "title" $ B.deleteMeta "subtitle" meta
8585 body <- blockListToRST' True $ case writerTemplate opts of
8686 Just _ -> normalizeHeadings 1 blocks
8787 Nothing -> blocks
@@ -504,7 +504,7 @@ inlineToRST (Link _ [Image attr alt (imgsrc,imgtit)] (src, _tit)) = do
504504 return $ "|" <> label <> "|"
505505inlineToRST (Link _ txt (src, tit)) = do
506506 useReferenceLinks <- gets $ writerReferenceLinks . stOptions
507− linktext <- inlineListToRST $ normalizeSpaces txt
507+ linktext <- inlineListToRST $ B.toList . B.trimInlines . B.fromList $ txt
508508 if useReferenceLinks
509509 then do refs <- gets stLinks
510510 case lookup txt refs of