diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2022-07-16 15:48:52 +0200 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-07-16 15:49:45 +0200 |
| commit | 98fb8521a7e827a63779db3a15632787cac96160 (patch) | |
| tree | c8b278cccf44920f5a293369b93aabbc08293b02 /src | |
| parent | c724e9cb7c810e3a36a4bc588822a75cbd1d9788 (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.hs | 15 |
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 |
