diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-11-06 22:53:56 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-11-06 22:54:25 -0800 |
commit | 985db7b0a8a090e7654642651c75bffcf53f8d38 (patch) | |
tree | 3f5797108050fbe9a90a2a3cd674b762d9ec758a /src/Text | |
parent | dae3a0e3d2e6fc2677f9f59bd046ef2a4e66ce42 (diff) | |
download | pandoc-985db7b0a8a090e7654642651c75bffcf53f8d38.tar.gz |
ICML writer: consolidate adjacent strings, inc. spaces.
This avoids chunking up the output unnecessarily into
separate elements.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/ICML.hs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Writers/ICML.hs b/src/Text/Pandoc/Writers/ICML.hs index ef1e2af0a..1a7759740 100644 --- a/src/Text/Pandoc/Writers/ICML.hs +++ b/src/Text/Pandoc/Writers/ICML.hs @@ -416,7 +416,7 @@ definitionListItemToICML opts style (term,defs) = do -- | Convert a list of inline elements to ICML. inlinesToICML :: PandocMonad m => WriterOptions -> Style -> [Inline] -> WS m Doc -inlinesToICML opts style lst = vcat `fmap` mapM (inlineToICML opts style) (mergeSpaces lst) +inlinesToICML opts style lst = vcat `fmap` mapM (inlineToICML opts style) (mergeStrings opts lst) -- | Convert an inline element to ICML. inlineToICML :: PandocMonad m => WriterOptions -> Style -> Inline -> WS m Doc @@ -427,8 +427,10 @@ inlineToICML opts style (Strikeout lst) = inlinesToICML opts (strikeoutName:styl inlineToICML opts style (Superscript lst) = inlinesToICML opts (superscriptName:style) lst inlineToICML opts style (Subscript lst) = inlinesToICML opts (subscriptName:style) lst inlineToICML opts style (SmallCaps lst) = inlinesToICML opts (smallCapsName:style) lst -inlineToICML opts style (Quoted SingleQuote lst) = inlinesToICML opts style $ [Str "‘"] ++ lst ++ [Str "’"] -inlineToICML opts style (Quoted DoubleQuote lst) = inlinesToICML opts style $ [Str "“"] ++ lst ++ [Str "”"] +inlineToICML opts style (Quoted SingleQuote lst) = inlinesToICML opts style $ + mergeStrings opts $ [Str "‘"] ++ lst ++ [Str "’"] +inlineToICML opts style (Quoted DoubleQuote lst) = inlinesToICML opts style $ + mergeStrings opts $ [Str "“"] ++ lst ++ [Str "”"] inlineToICML opts style (Cite _ lst) = inlinesToICML opts (citeName:style) lst inlineToICML _ style (Code _ str) = charStyle (codeName:style) $ text $ escapeStringForXML str inlineToICML _ style Space = charStyle style space @@ -474,18 +476,16 @@ footnoteToICML opts style lst = $ inTags True "Footnote" [] $ number $$ intersperseBrs contents -- | Auxiliary function to merge Space elements into the adjacent Strs. -mergeSpaces :: [Inline] -> [Inline] -mergeSpaces (Str s:(x:(Str s':xs))) | isSp x = - mergeSpaces $ Str(s++" "++s') : xs -mergeSpaces (x:(Str s:xs)) | isSp x = mergeSpaces $ Str (" "++s) : xs -mergeSpaces (Str s:(x:xs)) | isSp x = mergeSpaces $ Str (s++" ") : xs -mergeSpaces (x:xs) = x : mergeSpaces xs -mergeSpaces [] = [] - -isSp :: Inline -> Bool -isSp Space = True -isSp SoftBreak = True -isSp _ = False +mergeStrings :: WriterOptions -> [Inline] -> [Inline] +mergeStrings opts = mergeStrings' . map spaceToStr + where spaceToStr Space = Str " " + spaceToStr SoftBreak = case writerWrapText opts of + WrapPreserve -> Str "\n" + _ -> Str " " + spaceToStr x = x +mergeStrings' (Str x : Str y : zs) = mergeStrings' (Str (x ++ y) : zs) +mergeStrings' (x : xs) = x : mergeStrings' xs +mergeStrings' [] = [] -- | Intersperse line breaks intersperseBrs :: [Doc] -> Doc |