summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-07-16 15:48:52 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2022-07-16 15:49:45 +0200
commit98fb8521a7e827a63779db3a15632787cac96160 (patch)
treec8b278cccf44920f5a293369b93aabbc08293b02 /src
parentc724e9cb7c810e3a36a4bc588822a75cbd1d9788 (diff)
RST writer: Fix missing spaces with nested inlines.
Previously spaces around links inside italics were omitted. Closes #8182.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/RST.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs
index 3d1033d72..021674b34 100644
--- a/src/Text/Pandoc/Writers/RST.hs
+++ b/src/Text/Pandoc/Writers/RST.hs
@@ -32,7 +32,7 @@ import Text.Pandoc.Shared
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Shared
import Text.Pandoc.Walk
-import Safe (lastMay)
+import Safe (lastMay, headMay)
type Refs = [([Inline], Target)]
@@ -478,7 +478,18 @@ transformInlines = insertBS .
insertBS (x:ys) = x : insertBS ys
insertBS [] = []
transformNested :: [Inline] -> [Inline]
- transformNested = map (mapNested stripLeadingTrailingSpace)
+ transformNested = concatMap exportLeadingTrailingSpace
+ exportLeadingTrailingSpace :: Inline -> [Inline]
+ exportLeadingTrailingSpace il
+ | isComplex il =
+ let contents = dropInlineParent il
+ headSpace = headMay contents == Just Space
+ lastSpace = lastMay contents == Just Space
+ in (if headSpace then (Space:) else id) .
+ (if lastSpace then (++ [Space]) else id) $
+ [setInlineChildren il (stripLeadingTrailingSpace contents)]
+ | otherwise = [il]
+
surroundComplex :: Inline -> Inline -> Bool
surroundComplex (Str s) (Str s')
| Just (_, c) <- T.unsnoc s