aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Shared.hs13
-rw-r--r--src/Text/Pandoc/Writers/Docbook.hs2
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs9
-rw-r--r--src/Text/Pandoc/Writers/RST.hs7
4 files changed, 20 insertions, 11 deletions
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.
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
index 8ccf84f30..5f6f1c8b1 100644
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -176,7 +176,7 @@ cdata str = text $ "<![CDATA[" ++ str ++ "]]>"
-- | Take list of inline elements and return wrapped doc.
wrap :: WriterOptions -> [Inline] -> Doc
-wrap options lst = fsep $ map (hcat . (map (inlineToDocbook options))) (splitBySpace lst)
+wrap options lst = fsep $ map (inlinesToDocbook options) (splitBy Space lst)
-- | Escape a string for XML (with "smart" option if specified).
stringToXML :: WriterOptions -> String -> String
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index bfebc71fe..c1d50c2ef 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -58,8 +58,13 @@ escapeLinkTitle = gsub "\"" "\\\\\""
-- | Take list of inline elements and return wrapped doc.
wrappedMarkdown :: [Inline] -> Doc
-wrappedMarkdown lst = fsep $
- map (fcat . (map inlineToMarkdown)) (splitBySpace lst)
+wrappedMarkdown lst =
+ let wrapSection sec = fsep $ map inlineListToMarkdown $ (splitBy Space sec)
+ wrappedSecs = map wrapSection $ splitBy LineBreak lst
+ wrappedSecs' = foldr (\s rest -> if not (null rest)
+ then (s <> text " "):rest
+ else s:rest) [] wrappedSecs in
+ vcat wrappedSecs'
-- | Insert Blank block between key and non-key
formatKeys :: [Block] -> [Block]
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 8b2563eb4..9184e0200 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -59,9 +59,10 @@ escapeString = backslashEscape "`\\|*_"
-- and another containing references.
wrappedRST :: [Inline] -> (Doc, Doc)
wrappedRST lst =
- let words = splitBySpace lst in
- ( fsep $ map (fcat . (map (fst . inlineToRST))) words,
- vcat (map (snd . inlineToRST) lst) )
+ let wrap_section sec = fsep $ map (fst . inlineListToRST) $
+ (splitBy Space sec) in
+ ((vcat $ map wrap_section $ (splitBy LineBreak lst)),
+ vcat $ map (snd . inlineToRST) lst)
-- | Remove reference keys, and make sure there are blanks before each list.
reformatBlocks :: [Block] -> [Block]